CVAT.js API Tests (#578)
* Added annotations dummy data * Added test file * Weak maps instead of regular dict * Added 14 API tests * Fixed put tests * Some written tests and some additional checks * Merge tests * Split & group tests * Clear annotations tests * Statistics tests * Added frames meta * Selection tests & bug fixes * Tests for frame * ObjectState tests, many fixed bugs * Object state tests * Renamed method FrameData.frame() => FrameData.data()main
parent
d939b9c34a
commit
d85d777040
@ -0,0 +1,685 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Intel Corporation
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
/* global
|
||||
require:false
|
||||
jest:false
|
||||
describe:false
|
||||
*/
|
||||
|
||||
// Setup mock for a server
|
||||
jest.mock('../../src/server-proxy', () => {
|
||||
const mock = require('../mocks/server-proxy.mock');
|
||||
return mock;
|
||||
});
|
||||
|
||||
// Initialize api
|
||||
require('../../src/api');
|
||||
|
||||
// Test cases
|
||||
describe('Feature: get annotations', () => {
|
||||
test('get annotations from a task', async () => {
|
||||
const task = (await window.cvat.tasks.get({ id: 100 }))[0];
|
||||
const annotations = await task.annotations.get(0);
|
||||
expect(Array.isArray(annotations)).toBeTruthy();
|
||||
expect(annotations).toHaveLength(11);
|
||||
for (const state of annotations) {
|
||||
expect(state).toBeInstanceOf(window.cvat.classes.ObjectState);
|
||||
}
|
||||
});
|
||||
|
||||
test('get annotations from a job', async () => {
|
||||
const job = (await window.cvat.jobs.get({ jobID: 101 }))[0];
|
||||
const annotations0 = await job.annotations.get(0);
|
||||
const annotations10 = await job.annotations.get(10);
|
||||
expect(Array.isArray(annotations0)).toBeTruthy();
|
||||
expect(Array.isArray(annotations10)).toBeTruthy();
|
||||
expect(annotations0).toHaveLength(1);
|
||||
expect(annotations10).toHaveLength(2);
|
||||
for (const state of annotations0.concat(annotations10)) {
|
||||
expect(state).toBeInstanceOf(window.cvat.classes.ObjectState);
|
||||
}
|
||||
});
|
||||
|
||||
test('get annotations for frame out of task', async () => {
|
||||
const task = (await window.cvat.tasks.get({ id: 100 }))[0];
|
||||
|
||||
// Out of task
|
||||
expect(task.annotations.get(500))
|
||||
.rejects.toThrow(window.cvat.exceptions.ArgumentError);
|
||||
|
||||
// Out of task
|
||||
expect(task.annotations.get(-1))
|
||||
.rejects.toThrow(window.cvat.exceptions.ArgumentError);
|
||||
});
|
||||
|
||||
test('get annotations for frame out of job', async () => {
|
||||
const job = (await window.cvat.jobs.get({ jobID: 101 }))[0];
|
||||
|
||||
// Out of segment
|
||||
expect(job.annotations.get(500))
|
||||
.rejects.toThrow(window.cvat.exceptions.ArgumentError);
|
||||
|
||||
// Out of segment
|
||||
expect(job.annotations.get(-1))
|
||||
.rejects.toThrow(window.cvat.exceptions.ArgumentError);
|
||||
});
|
||||
|
||||
// TODO: Test filter (hasn't been implemented yet)
|
||||
});
|
||||
|
||||
|
||||
describe('Feature: put annotations', () => {
|
||||
test('put a shape to a task', async () => {
|
||||
const task = (await window.cvat.tasks.get({ id: 101 }))[0];
|
||||
let annotations = await task.annotations.get(1);
|
||||
const { length } = annotations;
|
||||
|
||||
const state = new window.cvat.classes.ObjectState({
|
||||
frame: 1,
|
||||
objectType: window.cvat.enums.ObjectType.SHAPE,
|
||||
shapeType: window.cvat.enums.ObjectShape.POLYGON,
|
||||
points: [0, 0, 100, 0, 100, 50],
|
||||
occluded: true,
|
||||
label: task.labels[0],
|
||||
});
|
||||
|
||||
await task.annotations.put([state]);
|
||||
annotations = await task.annotations.get(1);
|
||||
expect(annotations).toHaveLength(length + 1);
|
||||
});
|
||||
|
||||
test('put a shape to a job', async () => {
|
||||
const job = (await window.cvat.jobs.get({ jobID: 100 }))[0];
|
||||
let annotations = await job.annotations.get(5);
|
||||
const { length } = annotations;
|
||||
|
||||
const state = new window.cvat.classes.ObjectState({
|
||||
frame: 5,
|
||||
objectType: window.cvat.enums.ObjectType.SHAPE,
|
||||
shapeType: window.cvat.enums.ObjectShape.RECTANGLE,
|
||||
points: [0, 0, 100, 100],
|
||||
occluded: false,
|
||||
label: job.task.labels[0],
|
||||
});
|
||||
|
||||
await job.annotations.put([state]);
|
||||
annotations = await job.annotations.get(5);
|
||||
expect(annotations).toHaveLength(length + 1);
|
||||
});
|
||||
|
||||
test('put a track to a task', async () => {
|
||||
const task = (await window.cvat.tasks.get({ id: 101 }))[0];
|
||||
let annotations = await task.annotations.get(1);
|
||||
const { length } = annotations;
|
||||
|
||||
const state = new window.cvat.classes.ObjectState({
|
||||
frame: 1,
|
||||
objectType: window.cvat.enums.ObjectType.TRACK,
|
||||
shapeType: window.cvat.enums.ObjectShape.POLYGON,
|
||||
points: [0, 0, 100, 0, 100, 50],
|
||||
occluded: true,
|
||||
label: task.labels[0],
|
||||
});
|
||||
|
||||
await task.annotations.put([state]);
|
||||
annotations = await task.annotations.get(1);
|
||||
expect(annotations).toHaveLength(length + 1);
|
||||
});
|
||||
|
||||
test('put a track to a job', async () => {
|
||||
const job = (await window.cvat.jobs.get({ jobID: 100 }))[0];
|
||||
let annotations = await job.annotations.get(5);
|
||||
const { length } = annotations;
|
||||
|
||||
const state = new window.cvat.classes.ObjectState({
|
||||
frame: 5,
|
||||
objectType: window.cvat.enums.ObjectType.TRACK,
|
||||
shapeType: window.cvat.enums.ObjectShape.RECTANGLE,
|
||||
points: [0, 0, 100, 100],
|
||||
occluded: false,
|
||||
label: job.task.labels[0],
|
||||
});
|
||||
|
||||
await job.annotations.put([state]);
|
||||
annotations = await job.annotations.get(5);
|
||||
expect(annotations).toHaveLength(length + 1);
|
||||
});
|
||||
|
||||
test('put object without objectType to a task', async () => {
|
||||
const task = (await window.cvat.tasks.get({ id: 101 }))[0];
|
||||
await task.annotations.clear(true);
|
||||
const state = new window.cvat.classes.ObjectState({
|
||||
frame: 1,
|
||||
shapeType: window.cvat.enums.ObjectShape.POLYGON,
|
||||
points: [0, 0, 100, 0, 100, 50],
|
||||
occluded: true,
|
||||
label: task.labels[0],
|
||||
});
|
||||
|
||||
expect(task.annotations.put([state]))
|
||||
.rejects.toThrow(window.cvat.exceptions.ArgumentError);
|
||||
});
|
||||
|
||||
test('put shape with bad attributes to a task', async () => {
|
||||
const task = (await window.cvat.tasks.get({ id: 101 }))[0];
|
||||
await task.annotations.clear(true);
|
||||
const state = new window.cvat.classes.ObjectState({
|
||||
frame: 1,
|
||||
objectType: window.cvat.enums.ObjectType.SHAPE,
|
||||
shapeType: window.cvat.enums.ObjectShape.POLYGON,
|
||||
points: [0, 0, 100, 0, 100, 50],
|
||||
attributes: { 'bad key': 55 },
|
||||
occluded: true,
|
||||
label: task.labels[0],
|
||||
});
|
||||
|
||||
expect(task.annotations.put([state]))
|
||||
.rejects.toThrow(window.cvat.exceptions.ArgumentError);
|
||||
});
|
||||
|
||||
test('put shape without points and with invalud points to a task', async () => {
|
||||
const task = (await window.cvat.tasks.get({ id: 101 }))[0];
|
||||
await task.annotations.clear(true);
|
||||
const state = new window.cvat.classes.ObjectState({
|
||||
frame: 1,
|
||||
objectType: window.cvat.enums.ObjectType.SHAPE,
|
||||
shapeType: window.cvat.enums.ObjectShape.POLYGON,
|
||||
occluded: true,
|
||||
points: [],
|
||||
label: task.labels[0],
|
||||
});
|
||||
|
||||
await expect(task.annotations.put([state]))
|
||||
.rejects.toThrow(window.cvat.exceptions.DataError);
|
||||
|
||||
delete state.points;
|
||||
await expect(task.annotations.put([state]))
|
||||
.rejects.toThrow(window.cvat.exceptions.DataError);
|
||||
|
||||
state.points = ['150,50 250,30'];
|
||||
expect(task.annotations.put([state]))
|
||||
.rejects.toThrow(window.cvat.exceptions.ArgumentError);
|
||||
});
|
||||
|
||||
test('put shape without type to a task', async () => {
|
||||
const task = (await window.cvat.tasks.get({ id: 101 }))[0];
|
||||
await task.annotations.clear(true);
|
||||
const state = new window.cvat.classes.ObjectState({
|
||||
frame: 1,
|
||||
objectType: window.cvat.enums.ObjectType.SHAPE,
|
||||
points: [0, 0, 100, 0, 100, 50],
|
||||
occluded: true,
|
||||
label: task.labels[0],
|
||||
});
|
||||
|
||||
expect(task.annotations.put([state]))
|
||||
.rejects.toThrow(window.cvat.exceptions.ArgumentError);
|
||||
});
|
||||
|
||||
test('put shape without label and with bad label to a task', async () => {
|
||||
const task = (await window.cvat.tasks.get({ id: 101 }))[0];
|
||||
await task.annotations.clear(true);
|
||||
const state = new window.cvat.classes.ObjectState({
|
||||
frame: 1,
|
||||
objectType: window.cvat.enums.ObjectType.SHAPE,
|
||||
shapeType: window.cvat.enums.ObjectShape.POLYGON,
|
||||
points: [0, 0, 100, 0, 100, 50],
|
||||
occluded: true,
|
||||
});
|
||||
|
||||
await expect(task.annotations.put([state]))
|
||||
.rejects.toThrow(window.cvat.exceptions.ArgumentError);
|
||||
|
||||
state.label = 'bad label';
|
||||
await expect(task.annotations.put([state]))
|
||||
.rejects.toThrow(window.cvat.exceptions.ArgumentError);
|
||||
|
||||
state.label = {};
|
||||
await expect(task.annotations.put([state]))
|
||||
.rejects.toThrow(window.cvat.exceptions.ArgumentError);
|
||||
});
|
||||
|
||||
test('put shape with bad frame to a task', async () => {
|
||||
const task = (await window.cvat.tasks.get({ id: 101 }))[0];
|
||||
await task.annotations.clear(true);
|
||||
const state = new window.cvat.classes.ObjectState({
|
||||
frame: '5',
|
||||
objectType: window.cvat.enums.ObjectType.SHAPE,
|
||||
shapeType: window.cvat.enums.ObjectShape.POLYGON,
|
||||
points: [0, 0, 100, 0, 100, 50],
|
||||
occluded: true,
|
||||
label: task.labels[0],
|
||||
});
|
||||
|
||||
expect(task.annotations.put([state]))
|
||||
.rejects.toThrow(window.cvat.exceptions.ArgumentError);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Feature: check unsaved changes', () => {
|
||||
test('check unsaved changes in a task', async () => {
|
||||
const task = (await window.cvat.tasks.get({ id: 101 }))[0];
|
||||
expect(await task.annotations.hasUnsavedChanges()).toBe(false);
|
||||
const annotations = await task.annotations.get(0);
|
||||
|
||||
annotations[0].keyframe = true;
|
||||
await annotations[0].save();
|
||||
|
||||
expect(await task.annotations.hasUnsavedChanges()).toBe(true);
|
||||
});
|
||||
|
||||
test('check unsaved changes in a job', async () => {
|
||||
const job = (await window.cvat.jobs.get({ jobID: 100 }))[0];
|
||||
expect(await job.annotations.hasUnsavedChanges()).toBe(false);
|
||||
const annotations = await job.annotations.get(0);
|
||||
|
||||
annotations[0].occluded = true;
|
||||
await annotations[0].save();
|
||||
|
||||
expect(await job.annotations.hasUnsavedChanges()).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Feature: save annotations', () => {
|
||||
test('create & save annotations for a task', async () => {
|
||||
const task = (await window.cvat.tasks.get({ id: 101 }))[0];
|
||||
let annotations = await task.annotations.get(0);
|
||||
const { length } = annotations;
|
||||
const state = new window.cvat.classes.ObjectState({
|
||||
frame: 0,
|
||||
objectType: window.cvat.enums.ObjectType.SHAPE,
|
||||
shapeType: window.cvat.enums.ObjectShape.POLYGON,
|
||||
points: [0, 0, 100, 0, 100, 50],
|
||||
occluded: true,
|
||||
label: task.labels[0],
|
||||
});
|
||||
|
||||
expect(await task.annotations.hasUnsavedChanges()).toBe(false);
|
||||
await task.annotations.put([state]);
|
||||
expect(await task.annotations.hasUnsavedChanges()).toBe(true);
|
||||
await task.annotations.save();
|
||||
expect(await task.annotations.hasUnsavedChanges()).toBe(false);
|
||||
annotations = await task.annotations.get(0);
|
||||
expect(annotations).toHaveLength(length + 1);
|
||||
});
|
||||
|
||||
test('update & save annotations for a task', async () => {
|
||||
const task = (await window.cvat.tasks.get({ id: 101 }))[0];
|
||||
const annotations = await task.annotations.get(0);
|
||||
|
||||
expect(await task.annotations.hasUnsavedChanges()).toBe(false);
|
||||
annotations[0].occluded = true;
|
||||
await annotations[0].save();
|
||||
expect(await task.annotations.hasUnsavedChanges()).toBe(true);
|
||||
await task.annotations.save();
|
||||
expect(await task.annotations.hasUnsavedChanges()).toBe(false);
|
||||
});
|
||||
|
||||
test('delete & save annotations for a task', async () => {
|
||||
const task = (await window.cvat.tasks.get({ id: 101 }))[0];
|
||||
const annotations = await task.annotations.get(0);
|
||||
|
||||
expect(await task.annotations.hasUnsavedChanges()).toBe(false);
|
||||
await annotations[0].delete();
|
||||
expect(await task.annotations.hasUnsavedChanges()).toBe(true);
|
||||
await task.annotations.save();
|
||||
expect(await task.annotations.hasUnsavedChanges()).toBe(false);
|
||||
});
|
||||
|
||||
test('create & save annotations for a job', async () => {
|
||||
const job = (await window.cvat.jobs.get({ jobID: 100 }))[0];
|
||||
let annotations = await job.annotations.get(0);
|
||||
const { length } = annotations;
|
||||
const state = new window.cvat.classes.ObjectState({
|
||||
frame: 0,
|
||||
objectType: window.cvat.enums.ObjectType.SHAPE,
|
||||
shapeType: window.cvat.enums.ObjectShape.POLYGON,
|
||||
points: [0, 0, 100, 0, 100, 50],
|
||||
occluded: true,
|
||||
label: job.task.labels[0],
|
||||
});
|
||||
|
||||
expect(await job.annotations.hasUnsavedChanges()).toBe(false);
|
||||
await job.annotations.put([state]);
|
||||
expect(await job.annotations.hasUnsavedChanges()).toBe(true);
|
||||
await job.annotations.save();
|
||||
expect(await job.annotations.hasUnsavedChanges()).toBe(false);
|
||||
annotations = await job.annotations.get(0);
|
||||
expect(annotations).toHaveLength(length + 1);
|
||||
});
|
||||
|
||||
test('update & save annotations for a job', async () => {
|
||||
const job = (await window.cvat.jobs.get({ jobID: 100 }))[0];
|
||||
const annotations = await job.annotations.get(0);
|
||||
|
||||
expect(await job.annotations.hasUnsavedChanges()).toBe(false);
|
||||
annotations[0].points = [0, 100, 200, 300];
|
||||
await annotations[0].save();
|
||||
expect(await job.annotations.hasUnsavedChanges()).toBe(true);
|
||||
await job.annotations.save();
|
||||
expect(await job.annotations.hasUnsavedChanges()).toBe(false);
|
||||
});
|
||||
|
||||
test('delete & save annotations for a job', async () => {
|
||||
const job = (await window.cvat.jobs.get({ jobID: 100 }))[0];
|
||||
const annotations = await job.annotations.get(0);
|
||||
|
||||
expect(await job.annotations.hasUnsavedChanges()).toBe(false);
|
||||
await annotations[0].delete();
|
||||
expect(await job.annotations.hasUnsavedChanges()).toBe(true);
|
||||
await job.annotations.save();
|
||||
expect(await job.annotations.hasUnsavedChanges()).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Feature: merge annotations', () => {
|
||||
test('merge annotations in a task', async () => {
|
||||
const task = (await window.cvat.tasks.get({ id: 100 }))[0];
|
||||
const annotations0 = await task.annotations.get(0);
|
||||
const annotations1 = await task.annotations.get(1);
|
||||
const states = [annotations0[0], annotations1[0]];
|
||||
await task.annotations.merge(states);
|
||||
const merged0 = (await task.annotations.get(0))
|
||||
.filter(state => state.objectType === window.cvat.enums.ObjectType.TRACK);
|
||||
const merged1 = (await task.annotations.get(1))
|
||||
.filter(state => state.objectType === window.cvat.enums.ObjectType.TRACK);
|
||||
expect(merged0).toHaveLength(1);
|
||||
expect(merged1).toHaveLength(1);
|
||||
|
||||
expect(merged0[0].points).toEqual(states[0].points);
|
||||
expect(merged1[0].points).toEqual(states[1].points);
|
||||
});
|
||||
|
||||
test('merge annotations in a job', async () => {
|
||||
const job = (await window.cvat.jobs.get({ jobID: 100 }))[0];
|
||||
const annotations0 = await job.annotations.get(0);
|
||||
const annotations1 = await job.annotations.get(1);
|
||||
const states = [annotations0[0], annotations1[0]];
|
||||
await job.annotations.merge(states);
|
||||
const merged0 = (await job.annotations.get(0))
|
||||
.filter(state => state.objectType === window.cvat.enums.ObjectType.TRACK);
|
||||
const merged1 = (await job.annotations.get(1))
|
||||
.filter(state => state.objectType === window.cvat.enums.ObjectType.TRACK);
|
||||
expect(merged0).toHaveLength(1);
|
||||
expect(merged1).toHaveLength(1);
|
||||
|
||||
expect(merged0[0].points).toEqual(states[0].points);
|
||||
expect(merged1[0].points).toEqual(states[1].points);
|
||||
});
|
||||
|
||||
test('trying to merge not object state', async () => {
|
||||
const task = (await window.cvat.tasks.get({ id: 100 }))[0];
|
||||
const annotations0 = await task.annotations.get(0);
|
||||
const states = [annotations0[0], {}];
|
||||
|
||||
expect(task.annotations.merge(states))
|
||||
.rejects.toThrow(window.cvat.exceptions.ArgumentError);
|
||||
});
|
||||
|
||||
test('trying to merge object state which is not saved in a collection', async () => {
|
||||
const task = (await window.cvat.tasks.get({ id: 100 }))[0];
|
||||
const annotations0 = await task.annotations.get(0);
|
||||
|
||||
const state = new window.cvat.classes.ObjectState({
|
||||
frame: 0,
|
||||
objectType: window.cvat.enums.ObjectType.SHAPE,
|
||||
shapeType: window.cvat.enums.ObjectShape.POLYGON,
|
||||
points: [0, 0, 100, 0, 100, 50],
|
||||
occluded: true,
|
||||
label: task.labels[0],
|
||||
});
|
||||
const states = [annotations0[0], state];
|
||||
|
||||
expect(task.annotations.merge(states))
|
||||
.rejects.toThrow(window.cvat.exceptions.ArgumentError);
|
||||
});
|
||||
|
||||
test('trying to merge with bad label', async () => {
|
||||
const task = (await window.cvat.tasks.get({ id: 100 }))[0];
|
||||
const annotations0 = await task.annotations.get(0);
|
||||
const annotations1 = await task.annotations.get(1);
|
||||
const states = [annotations0[0], annotations1[0]];
|
||||
states[0].label = new window.cvat.classes.Label({
|
||||
id: 500,
|
||||
name: 'new_label',
|
||||
attributes: [],
|
||||
});
|
||||
|
||||
expect(task.annotations.merge(states))
|
||||
.rejects.toThrow(window.cvat.exceptions.ArgumentError);
|
||||
});
|
||||
|
||||
test('trying to merge with different shape types', async () => {
|
||||
const task = (await window.cvat.tasks.get({ id: 100 }))[0];
|
||||
const annotations0 = await task.annotations.get(0);
|
||||
const annotations1 = (await task.annotations.get(1))
|
||||
.filter(state => state.shapeType === window.cvat.enums.ObjectShape.POLYGON);
|
||||
const states = [annotations0[0], annotations1[0]];
|
||||
|
||||
expect(task.annotations.merge(states))
|
||||
.rejects.toThrow(window.cvat.exceptions.ArgumentError);
|
||||
});
|
||||
|
||||
test('trying to merge with different labels', async () => {
|
||||
const task = (await window.cvat.tasks.get({ id: 100 }))[0];
|
||||
const annotations0 = await task.annotations.get(0);
|
||||
const annotations1 = await task.annotations.get(1);
|
||||
const states = [annotations0[0], annotations1[0]];
|
||||
states[1].label = new window.cvat.classes.Label({
|
||||
id: 500,
|
||||
name: 'new_label',
|
||||
attributes: [],
|
||||
});
|
||||
|
||||
expect(task.annotations.merge(states))
|
||||
.rejects.toThrow(window.cvat.exceptions.ArgumentError);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Feature: split annotations', () => {
|
||||
test('split annotations in a task', async () => {
|
||||
const task = (await window.cvat.tasks.get({ id: 101 }))[0];
|
||||
const annotations4 = await task.annotations.get(4);
|
||||
const annotations5 = await task.annotations.get(5);
|
||||
|
||||
expect(annotations4[0].clientID).toBe(annotations5[0].clientID);
|
||||
await task.annotations.split(annotations5[0], 5);
|
||||
const splitted4 = await task.annotations.get(4);
|
||||
const splitted5 = (await task.annotations.get(5)).filter(state => !state.outside);
|
||||
expect(splitted4[0].clientID).not.toBe(splitted5[0].clientID);
|
||||
});
|
||||
|
||||
test('split annotations in a job', async () => {
|
||||
const job = (await window.cvat.jobs.get({ jobID: 101 }))[0];
|
||||
const annotations4 = await job.annotations.get(4);
|
||||
const annotations5 = await job.annotations.get(5);
|
||||
|
||||
expect(annotations4[0].clientID).toBe(annotations5[0].clientID);
|
||||
await job.annotations.split(annotations5[0], 5);
|
||||
const splitted4 = await job.annotations.get(4);
|
||||
const splitted5 = (await job.annotations.get(5)).filter(state => !state.outside);
|
||||
expect(splitted4[0].clientID).not.toBe(splitted5[0].clientID);
|
||||
});
|
||||
|
||||
test('split on a bad frame', async () => {
|
||||
const task = (await window.cvat.tasks.get({ id: 101 }))[0];
|
||||
const annotations4 = await task.annotations.get(4);
|
||||
const annotations5 = await task.annotations.get(5);
|
||||
|
||||
expect(annotations4[0].clientID).toBe(annotations5[0].clientID);
|
||||
expect(task.annotations.split(annotations5[0], 'bad frame'))
|
||||
.rejects.toThrow(window.cvat.exceptions.ArgumentError);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Feature: group annotations', () => {
|
||||
test('group annotations in a task', async () => {
|
||||
const task = (await window.cvat.tasks.get({ id: 100 }))[0];
|
||||
let annotations = await task.annotations.get(0);
|
||||
const groupID = await task.annotations.group(annotations);
|
||||
expect(typeof (groupID)).toBe('number');
|
||||
annotations = await task.annotations.get(0);
|
||||
for (const state of annotations) {
|
||||
expect(state.group).toBe(groupID);
|
||||
}
|
||||
});
|
||||
|
||||
test('group annotations in a job', async () => {
|
||||
const job = (await window.cvat.jobs.get({ jobID: 100 }))[0];
|
||||
let annotations = await job.annotations.get(0);
|
||||
const groupID = await job.annotations.group(annotations);
|
||||
expect(typeof (groupID)).toBe('number');
|
||||
annotations = await job.annotations.get(0);
|
||||
for (const state of annotations) {
|
||||
expect(state.group).toBe(groupID);
|
||||
}
|
||||
});
|
||||
|
||||
test('trying to group object state which has not been saved in a collection', async () => {
|
||||
const task = (await window.cvat.tasks.get({ id: 100 }))[0];
|
||||
await task.annotations.clear(true);
|
||||
|
||||
const state = new window.cvat.classes.ObjectState({
|
||||
frame: 0,
|
||||
objectType: window.cvat.enums.ObjectType.SHAPE,
|
||||
shapeType: window.cvat.enums.ObjectShape.POLYGON,
|
||||
points: [0, 0, 100, 0, 100, 50],
|
||||
occluded: true,
|
||||
label: task.labels[0],
|
||||
});
|
||||
|
||||
expect(task.annotations.group([state]))
|
||||
.rejects.toThrow(window.cvat.exceptions.ArgumentError);
|
||||
});
|
||||
|
||||
test('trying to group not object state', async () => {
|
||||
const task = (await window.cvat.tasks.get({ id: 100 }))[0];
|
||||
const annotations = await task.annotations.get(0);
|
||||
expect(task.annotations.group(annotations.concat({})))
|
||||
.rejects.toThrow(window.cvat.exceptions.ArgumentError);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Feature: clear annotations', () => {
|
||||
test('clear annotations in a task', async () => {
|
||||
const task = (await window.cvat.tasks.get({ id: 100 }))[0];
|
||||
let annotations = await task.annotations.get(0);
|
||||
expect(annotations.length).not.toBe(0);
|
||||
await task.annotations.clear();
|
||||
annotations = await task.annotations.get(0);
|
||||
expect(annotations.length).toBe(0);
|
||||
});
|
||||
|
||||
test('clear annotations in a job', async () => {
|
||||
const job = (await window.cvat.jobs.get({ jobID: 100 }))[0];
|
||||
let annotations = await job.annotations.get(0);
|
||||
expect(annotations.length).not.toBe(0);
|
||||
await job.annotations.clear();
|
||||
annotations = await job.annotations.get(0);
|
||||
expect(annotations.length).toBe(0);
|
||||
});
|
||||
|
||||
test('clear annotations with reload in a task', async () => {
|
||||
const task = (await window.cvat.tasks.get({ id: 100 }))[0];
|
||||
let annotations = await task.annotations.get(0);
|
||||
expect(annotations.length).not.toBe(0);
|
||||
annotations[0].occluded = true;
|
||||
await annotations[0].save();
|
||||
expect(await task.annotations.hasUnsavedChanges()).toBe(true);
|
||||
await task.annotations.clear(true);
|
||||
annotations = await task.annotations.get(0);
|
||||
expect(annotations.length).not.toBe(0);
|
||||
expect(await task.annotations.hasUnsavedChanges()).toBe(false);
|
||||
});
|
||||
|
||||
test('clear annotations with reload in a job', async () => {
|
||||
const job = (await window.cvat.jobs.get({ jobID: 100 }))[0];
|
||||
let annotations = await job.annotations.get(0);
|
||||
expect(annotations.length).not.toBe(0);
|
||||
annotations[0].occluded = true;
|
||||
await annotations[0].save();
|
||||
expect(await job.annotations.hasUnsavedChanges()).toBe(true);
|
||||
await job.annotations.clear(true);
|
||||
annotations = await job.annotations.get(0);
|
||||
expect(annotations.length).not.toBe(0);
|
||||
expect(await job.annotations.hasUnsavedChanges()).toBe(false);
|
||||
});
|
||||
|
||||
test('clear annotations with bad reload parameter', async () => {
|
||||
const task = (await window.cvat.tasks.get({ id: 100 }))[0];
|
||||
await task.annotations.clear(true);
|
||||
expect(task.annotations.clear('reload'))
|
||||
.rejects.toThrow(window.cvat.exceptions.ArgumentError);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Feature: get statistics', () => {
|
||||
test('get statistics from a task', async () => {
|
||||
const task = (await window.cvat.tasks.get({ id: 100 }))[0];
|
||||
await task.annotations.clear(true);
|
||||
const statistics = await task.annotations.statistics();
|
||||
expect(statistics).toBeInstanceOf(window.cvat.classes.Statistics);
|
||||
expect(statistics.total.total).toBe(29);
|
||||
});
|
||||
|
||||
test('get statistics from a job', async () => {
|
||||
const job = (await window.cvat.jobs.get({ jobID: 101 }))[0];
|
||||
await job.annotations.clear(true);
|
||||
const statistics = await job.annotations.statistics();
|
||||
expect(statistics).toBeInstanceOf(window.cvat.classes.Statistics);
|
||||
expect(statistics.total.total).toBe(512);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Feature: select object', () => {
|
||||
test('select object in a task', async () => {
|
||||
const task = (await window.cvat.tasks.get({ id: 100 }))[0];
|
||||
const annotations = await task.annotations.get(0);
|
||||
let result = await task.annotations.select(annotations, 1430, 765);
|
||||
expect(result.state.shapeType).toBe(window.cvat.enums.ObjectShape.RECTANGLE);
|
||||
result = await task.annotations.select(annotations, 1415, 765);
|
||||
expect(result.state.shapeType).toBe(window.cvat.enums.ObjectShape.POLYGON);
|
||||
expect(result.state.points.length).toBe(10);
|
||||
result = await task.annotations.select(annotations, 1083, 543);
|
||||
expect(result.state.shapeType).toBe(window.cvat.enums.ObjectShape.POINTS);
|
||||
expect(result.state.points.length).toBe(16);
|
||||
result = await task.annotations.select(annotations, 613, 811);
|
||||
expect(result.state.shapeType).toBe(window.cvat.enums.ObjectShape.POLYGON);
|
||||
expect(result.state.points.length).toBe(94);
|
||||
});
|
||||
|
||||
test('select object in a job', async () => {
|
||||
const job = (await window.cvat.jobs.get({ jobID: 100 }))[0];
|
||||
const annotations = await job.annotations.get(0);
|
||||
let result = await job.annotations.select(annotations, 490, 540);
|
||||
expect(result.state.shapeType).toBe(window.cvat.enums.ObjectShape.RECTANGLE);
|
||||
result = await job.annotations.select(annotations, 430, 260);
|
||||
expect(result.state.shapeType).toBe(window.cvat.enums.ObjectShape.POLYLINE);
|
||||
result = await job.annotations.select(annotations, 1473, 250);
|
||||
expect(result.state.shapeType).toBe(window.cvat.enums.ObjectShape.RECTANGLE);
|
||||
result = await job.annotations.select(annotations, 1490, 237);
|
||||
expect(result.state.shapeType).toBe(window.cvat.enums.ObjectShape.POLYGON);
|
||||
expect(result.state.points.length).toBe(94);
|
||||
});
|
||||
|
||||
test('trying to select from not object states', async () => {
|
||||
const task = (await window.cvat.tasks.get({ id: 100 }))[0];
|
||||
const annotations = await task.annotations.get(0);
|
||||
expect(task.annotations.select(annotations.concat({}), 500, 500))
|
||||
.rejects.toThrow(window.cvat.exceptions.ArgumentError);
|
||||
});
|
||||
|
||||
test('trying to select with invalid coordinates', async () => {
|
||||
const task = (await window.cvat.tasks.get({ id: 100 }))[0];
|
||||
const annotations = await task.annotations.get(0);
|
||||
expect(task.annotations.select(annotations, null, null))
|
||||
.rejects.toThrow(window.cvat.exceptions.ArgumentError);
|
||||
expect(task.annotations.select(annotations, null, null))
|
||||
.rejects.toThrow(window.cvat.exceptions.ArgumentError);
|
||||
expect(task.annotations.select(annotations, '5', '10'))
|
||||
.rejects.toThrow(window.cvat.exceptions.ArgumentError);
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Intel Corporation
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
/* global
|
||||
require:false
|
||||
jest:false
|
||||
describe:false
|
||||
*/
|
||||
|
||||
// Setup mock for a server
|
||||
jest.mock('../../src/server-proxy', () => {
|
||||
const mock = require('../mocks/server-proxy.mock');
|
||||
return mock;
|
||||
});
|
||||
|
||||
// Initialize api
|
||||
require('../../src/api');
|
||||
|
||||
const { FrameData } = require('../../src/frames');
|
||||
|
||||
describe('Feature: get frame meta', () => {
|
||||
test('get meta for a task', async () => {
|
||||
const task = (await window.cvat.tasks.get({ id: 100 }))[0];
|
||||
const frame = await task.frames.get(0);
|
||||
expect(frame).toBeInstanceOf(FrameData);
|
||||
});
|
||||
|
||||
test('get meta for a job', async () => {
|
||||
const job = (await window.cvat.jobs.get({ jobID: 100 }))[0];
|
||||
const frame = await job.frames.get(0);
|
||||
expect(frame).toBeInstanceOf(FrameData);
|
||||
});
|
||||
|
||||
test('pass frame number out of a task', async () => {
|
||||
const task = (await window.cvat.tasks.get({ id: 100 }))[0];
|
||||
expect(task.frames.get(100))
|
||||
.rejects.toThrow(window.cvat.exceptions.ArgumentError);
|
||||
expect(task.frames.get(-1))
|
||||
.rejects.toThrow(window.cvat.exceptions.ArgumentError);
|
||||
});
|
||||
|
||||
test('pass bad frame number', async () => {
|
||||
const task = (await window.cvat.tasks.get({ id: 100 }))[0];
|
||||
expect(task.frames.get('5'))
|
||||
.rejects.toThrow(window.cvat.exceptions.ArgumentError);
|
||||
});
|
||||
|
||||
test('do not pass any frame number', async () => {
|
||||
const task = (await window.cvat.tasks.get({ id: 100 }))[0];
|
||||
expect(task.frames.get())
|
||||
.rejects.toThrow(window.cvat.exceptions.ArgumentError);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Feature: get frame data', () => {
|
||||
test('get frame data for a task', async () => {
|
||||
const task = (await window.cvat.tasks.get({ id: 100 }))[0];
|
||||
const frame = await task.frames.get(0);
|
||||
const frameData = await frame.data();
|
||||
expect(typeof (frameData)).toBe('string');
|
||||
});
|
||||
|
||||
test('get frame data for a job', async () => {
|
||||
const job = (await window.cvat.jobs.get({ jobID: 100 }))[0];
|
||||
const frame = await job.frames.get(0);
|
||||
const frameData = await frame.data();
|
||||
expect(typeof (frameData)).toBe('string');
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,347 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Intel Corporation
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
/* global
|
||||
require:false
|
||||
jest:false
|
||||
describe:false
|
||||
*/
|
||||
|
||||
// Setup mock for a server
|
||||
jest.mock('../../src/server-proxy', () => {
|
||||
const mock = require('../mocks/server-proxy.mock');
|
||||
return mock;
|
||||
});
|
||||
|
||||
// Initialize api
|
||||
require('../../src/api');
|
||||
|
||||
describe('Feature: set attributes for an object state', () => {
|
||||
test('set a valid value', () => {
|
||||
const state = new window.cvat.classes.ObjectState({
|
||||
objectType: window.cvat.enums.ObjectType.SHAPE,
|
||||
shapeType: window.cvat.enums.ObjectShape.RECTANGLE,
|
||||
frame: 5,
|
||||
});
|
||||
|
||||
const attributes = {
|
||||
5: 'man',
|
||||
6: 'glasses',
|
||||
};
|
||||
|
||||
state.attributes = attributes;
|
||||
expect(state.attributes).toEqual(attributes);
|
||||
});
|
||||
|
||||
test('trying to set a bad value', () => {
|
||||
const state = new window.cvat.classes.ObjectState({
|
||||
objectType: window.cvat.enums.ObjectType.SHAPE,
|
||||
shapeType: window.cvat.enums.ObjectShape.RECTANGLE,
|
||||
frame: 5,
|
||||
});
|
||||
|
||||
let attributes = 'bad attribute';
|
||||
expect(() => {
|
||||
state.attributes = attributes;
|
||||
}).toThrow(window.cvat.exceptions.ArgumentError);
|
||||
|
||||
attributes = 5;
|
||||
expect(() => {
|
||||
state.attributes = attributes;
|
||||
}).toThrow(window.cvat.exceptions.ArgumentError);
|
||||
|
||||
attributes = false;
|
||||
expect(() => {
|
||||
state.attributes = attributes;
|
||||
}).toThrow(window.cvat.exceptions.ArgumentError);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Feature: set points for an object state', () => {
|
||||
test('set a valid value', () => {
|
||||
const state = new window.cvat.classes.ObjectState({
|
||||
objectType: window.cvat.enums.ObjectType.SHAPE,
|
||||
shapeType: window.cvat.enums.ObjectShape.RECTANGLE,
|
||||
frame: 5,
|
||||
});
|
||||
|
||||
const points = [1, 2, 3, 4];
|
||||
state.points = points;
|
||||
expect(state.points).toEqual(points);
|
||||
});
|
||||
|
||||
test('trying to set a bad value', () => {
|
||||
const state = new window.cvat.classes.ObjectState({
|
||||
objectType: window.cvat.enums.ObjectType.SHAPE,
|
||||
shapeType: window.cvat.enums.ObjectShape.RECTANGLE,
|
||||
frame: 5,
|
||||
});
|
||||
|
||||
let points = 'bad points';
|
||||
expect(() => {
|
||||
state.points = points;
|
||||
}).toThrow(window.cvat.exceptions.ArgumentError);
|
||||
|
||||
points = 5;
|
||||
expect(() => {
|
||||
state.points = points;
|
||||
}).toThrow(window.cvat.exceptions.ArgumentError);
|
||||
|
||||
points = false;
|
||||
expect(() => {
|
||||
state.points = points;
|
||||
}).toThrow(window.cvat.exceptions.ArgumentError);
|
||||
|
||||
points = {};
|
||||
expect(() => {
|
||||
state.points = points;
|
||||
}).toThrow(window.cvat.exceptions.ArgumentError);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Feature: save object from its state', () => {
|
||||
test('save valid values for a shape', async () => {
|
||||
const task = (await window.cvat.tasks.get({ id: 100 }))[0];
|
||||
const annotations = await task.annotations.get(0);
|
||||
let state = annotations[0];
|
||||
expect(state.objectType).toBe(window.cvat.enums.ObjectType.SHAPE);
|
||||
expect(state.shapeType).toBe(window.cvat.enums.ObjectShape.RECTANGLE);
|
||||
state.points = [0, 0, 100, 100];
|
||||
state.occluded = true;
|
||||
[, state.label] = task.labels;
|
||||
state.lock = true;
|
||||
state = await state.save();
|
||||
expect(state).toBeInstanceOf(window.cvat.classes.ObjectState);
|
||||
expect(state.label.id).toBe(task.labels[1].id);
|
||||
expect(state.lock).toBe(true);
|
||||
expect(state.occluded).toBe(true);
|
||||
expect(state.points).toEqual([0, 0, 100, 100]);
|
||||
});
|
||||
|
||||
test('save valid values for a track', async () => {
|
||||
const task = (await window.cvat.tasks.get({ id: 101 }))[0];
|
||||
const annotations = await task.annotations.get(10);
|
||||
let state = annotations[1];
|
||||
expect(state.objectType).toBe(window.cvat.enums.ObjectType.TRACK);
|
||||
expect(state.shapeType).toBe(window.cvat.enums.ObjectShape.RECTANGLE);
|
||||
|
||||
state.occluded = true;
|
||||
state.lock = true;
|
||||
state.points = [100, 200, 200, 400];
|
||||
state.attributes = {
|
||||
1: 'sitting',
|
||||
3: 'female',
|
||||
2: '10',
|
||||
4: 'true',
|
||||
};
|
||||
|
||||
state = await state.save();
|
||||
expect(state).toBeInstanceOf(window.cvat.classes.ObjectState);
|
||||
expect(state.lock).toBe(true);
|
||||
expect(state.occluded).toBe(true);
|
||||
expect(state.points).toEqual([100, 200, 200, 400]);
|
||||
expect(state.attributes[1]).toBe('sitting');
|
||||
expect(state.attributes[2]).toBe('10');
|
||||
expect(state.attributes[3]).toBe('female');
|
||||
expect(state.attributes[4]).toBe('true');
|
||||
|
||||
state.lock = false;
|
||||
[state.label] = task.labels;
|
||||
state = await state.save();
|
||||
expect(state.label.id).toBe(task.labels[0].id);
|
||||
|
||||
state.outside = true;
|
||||
state = await state.save();
|
||||
expect(state.lock).toBe(false);
|
||||
expect(state.outside).toBe(true);
|
||||
|
||||
state.keyframe = false;
|
||||
state = await state.save();
|
||||
expect(state.keyframe).toBe(false);
|
||||
});
|
||||
|
||||
test('save bad values for a shape', async () => {
|
||||
const task = (await window.cvat.tasks.get({ id: 100 }))[0];
|
||||
const annotations = await task.annotations.get(0);
|
||||
const state = annotations[0];
|
||||
|
||||
state.occluded = 'false';
|
||||
await expect(state.save())
|
||||
.rejects.toThrow(window.cvat.exceptions.ArgumentError);
|
||||
|
||||
const oldPoints = state.points;
|
||||
state.occluded = false;
|
||||
state.points = ['100', '50', '100', {}];
|
||||
await expect(state.save())
|
||||
.rejects.toThrow(window.cvat.exceptions.ArgumentError);
|
||||
|
||||
state.points = oldPoints;
|
||||
state.lock = 'true';
|
||||
await expect(state.save())
|
||||
.rejects.toThrow(window.cvat.exceptions.ArgumentError);
|
||||
|
||||
const oldLabel = state.label;
|
||||
state.lock = false;
|
||||
state.label = 1;
|
||||
await expect(state.save())
|
||||
.rejects.toThrow(window.cvat.exceptions.ArgumentError);
|
||||
|
||||
state.label = oldLabel;
|
||||
state.attributes = { 1: {}, 2: false, 3: () => {} };
|
||||
await expect(state.save())
|
||||
.rejects.toThrow(window.cvat.exceptions.ArgumentError);
|
||||
});
|
||||
|
||||
test('save bad values for a track', async () => {
|
||||
const task = (await window.cvat.tasks.get({ id: 101 }))[0];
|
||||
const annotations = await task.annotations.get(0);
|
||||
const state = annotations[0];
|
||||
|
||||
state.occluded = 'false';
|
||||
await expect(state.save())
|
||||
.rejects.toThrow(window.cvat.exceptions.ArgumentError);
|
||||
|
||||
const oldPoints = state.points;
|
||||
state.occluded = false;
|
||||
state.points = ['100', '50', '100', {}];
|
||||
await expect(state.save())
|
||||
.rejects.toThrow(window.cvat.exceptions.ArgumentError);
|
||||
|
||||
state.points = oldPoints;
|
||||
state.lock = 'true';
|
||||
await expect(state.save())
|
||||
.rejects.toThrow(window.cvat.exceptions.ArgumentError);
|
||||
|
||||
const oldLabel = state.label;
|
||||
state.lock = false;
|
||||
state.label = 1;
|
||||
await expect(state.save())
|
||||
.rejects.toThrow(window.cvat.exceptions.ArgumentError);
|
||||
|
||||
state.label = oldLabel;
|
||||
state.outside = 5;
|
||||
await expect(state.save())
|
||||
.rejects.toThrow(window.cvat.exceptions.ArgumentError);
|
||||
|
||||
state.outside = false;
|
||||
state.keyframe = '10';
|
||||
await expect(state.save())
|
||||
.rejects.toThrow(window.cvat.exceptions.ArgumentError);
|
||||
|
||||
state.keyframe = true;
|
||||
state.attributes = { 1: {}, 2: false, 3: () => {} };
|
||||
await expect(state.save())
|
||||
.rejects.toThrow(window.cvat.exceptions.ArgumentError);
|
||||
});
|
||||
|
||||
test('trying to change locked shape', async () => {
|
||||
const task = (await window.cvat.tasks.get({ id: 101 }))[0];
|
||||
const annotations = await task.annotations.get(0);
|
||||
let state = annotations[0];
|
||||
|
||||
state.lock = true;
|
||||
state = await state.save();
|
||||
|
||||
const { points } = state;
|
||||
state.points = [0, 0, 500, 500];
|
||||
state = await state.save();
|
||||
expect(state.points).toEqual(points);
|
||||
});
|
||||
|
||||
test('trying to set too small area of a shape', async () => {
|
||||
const task = (await window.cvat.tasks.get({ id: 101 }))[0];
|
||||
const annotations = await task.annotations.get(0);
|
||||
let state = annotations[0];
|
||||
|
||||
const { points } = state;
|
||||
state.points = [0, 0, 2, 2]; // area is 4
|
||||
state = await state.save();
|
||||
expect(state.points).toEqual(points);
|
||||
});
|
||||
|
||||
test('trying to set too small area of a track', async () => {
|
||||
const task = (await window.cvat.tasks.get({ id: 101 }))[0];
|
||||
const annotations = await task.annotations.get(0);
|
||||
let state = annotations[0];
|
||||
|
||||
const { points } = state;
|
||||
state.points = [0, 0, 2, 2]; // area is 4
|
||||
state = await state.save();
|
||||
expect(state.points).toEqual(points);
|
||||
});
|
||||
|
||||
test('trying to set too small length of a shape', async () => {
|
||||
const task = (await window.cvat.tasks.get({ id: 100 }))[0];
|
||||
const annotations = await task.annotations.get(0);
|
||||
let state = annotations[8];
|
||||
|
||||
const { points } = state;
|
||||
state.points = [0, 0, 2, 2]; // length is 2
|
||||
state = await state.save();
|
||||
expect(state.points).toEqual(points);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Feature: delete object', () => {
|
||||
test('delete a shape', async () => {
|
||||
const task = (await window.cvat.tasks.get({ id: 100 }))[0];
|
||||
const annotationsBefore = await task.annotations.get(0);
|
||||
const { length } = annotationsBefore;
|
||||
await annotationsBefore[0].delete();
|
||||
const annotationsAfter = await task.annotations.get(0);
|
||||
expect(annotationsAfter).toHaveLength(length - 1);
|
||||
});
|
||||
|
||||
test('delete a track', async () => {
|
||||
const task = (await window.cvat.tasks.get({ id: 101 }))[0];
|
||||
const annotationsBefore = await task.annotations.get(0);
|
||||
const { length } = annotationsBefore;
|
||||
await annotationsBefore[0].delete();
|
||||
const annotationsAfter = await task.annotations.get(0);
|
||||
expect(annotationsAfter).toHaveLength(length - 1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Feature: change z order of an object', () => {
|
||||
test('up z order for a shape', async () => {
|
||||
const task = (await window.cvat.tasks.get({ id: 100 }))[0];
|
||||
const annotations = await task.annotations.get(0);
|
||||
const state = annotations[0];
|
||||
|
||||
const { zOrder } = state;
|
||||
await state.up();
|
||||
expect(state.zOrder).toBeGreaterThan(zOrder);
|
||||
});
|
||||
|
||||
test('up z order for a track', async () => {
|
||||
const task = (await window.cvat.tasks.get({ id: 101 }))[0];
|
||||
const annotations = await task.annotations.get(0);
|
||||
const state = annotations[0];
|
||||
|
||||
const { zOrder } = state;
|
||||
await state.up();
|
||||
expect(state.zOrder).toBeGreaterThan(zOrder);
|
||||
});
|
||||
|
||||
test('down z order for a shape', async () => {
|
||||
const task = (await window.cvat.tasks.get({ id: 100 }))[0];
|
||||
const annotations = await task.annotations.get(0);
|
||||
const state = annotations[0];
|
||||
|
||||
const { zOrder } = state;
|
||||
await state.down();
|
||||
expect(state.zOrder).toBeLessThan(zOrder);
|
||||
});
|
||||
|
||||
test('down z order for a track', async () => {
|
||||
const task = (await window.cvat.tasks.get({ id: 101 }))[0];
|
||||
const annotations = await task.annotations.get(0);
|
||||
const state = annotations[0];
|
||||
|
||||
const { zOrder } = state;
|
||||
await state.down();
|
||||
expect(state.zOrder).toBeLessThan(zOrder);
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Intel Corporation
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
/* global
|
||||
require:false
|
||||
jest:false
|
||||
describe:false
|
||||
*/
|
||||
|
||||
// Setup mock for a server
|
||||
jest.mock('../../src/server-proxy', () => {
|
||||
const mock = require('../mocks/server-proxy.mock');
|
||||
return mock;
|
||||
});
|
||||
|
||||
// Initialize api
|
||||
require('../../src/api');
|
||||
|
||||
describe('Feature: dummy feature', () => {
|
||||
test('dummy test', async () => {
|
||||
// TODO: Write test after design of plugin system
|
||||
});
|
||||
});
|
||||
|
||||
/*
|
||||
const plugin = {
|
||||
name: 'Example Plugin',
|
||||
description: 'This example plugin demonstrates how plugin system in CVAT works',
|
||||
cvat: {
|
||||
server: {
|
||||
about: {
|
||||
async leave(self, result) {
|
||||
result.plugins = await self.internal.getPlugins();
|
||||
return result;
|
||||
},
|
||||
},
|
||||
},
|
||||
classes: {
|
||||
Job: {
|
||||
prototype: {
|
||||
annotations: {
|
||||
put: {
|
||||
enter(self, objects) {
|
||||
for (const obj of objects) {
|
||||
if (obj.type !== 'tag') {
|
||||
const points = obj.position.map((point) => {
|
||||
const roundPoint = {
|
||||
x: Math.round(point.x),
|
||||
y: Math.round(point.y),
|
||||
};
|
||||
return roundPoint;
|
||||
});
|
||||
obj.points = points;
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
internal: {
|
||||
async getPlugins() {
|
||||
const plugins = await window.cvat.plugins.list();
|
||||
return plugins.map((el) => {
|
||||
const obj = {
|
||||
name: el.name,
|
||||
description: el.description,
|
||||
};
|
||||
return obj;
|
||||
});
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
async function test() {
|
||||
await window.cvat.plugins.register(plugin);
|
||||
await window.cvat.server.login('admin', 'nimda760');
|
||||
|
||||
try {
|
||||
console.log(JSON.stringify(await window.cvat.server.about()));
|
||||
console.log(await window.cvat.users.get({ self: false }));
|
||||
console.log(await window.cvat.users.get({ self: true }));
|
||||
console.log(JSON.stringify(await window.cvat.jobs.get({ taskID: 8 })));
|
||||
console.log(JSON.stringify(await window.cvat.jobs.get({ jobID: 10 })));
|
||||
console.log(await window.cvat.tasks.get());
|
||||
console.log(await window.cvat.tasks.get({ id: 8 }));
|
||||
console.log('Done.');
|
||||
} catch (exception) {
|
||||
console.log(exception.constructor.name);
|
||||
console.log(exception.message);
|
||||
}
|
||||
}
|
||||
*/
|
||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue