Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check UI does not crash if to activate an object while frame fetching #7873

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
85 changes: 85 additions & 0 deletions tests/cypress/e2e/actions_objects/regression_tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// Copyright (C) 2024 CVAT.ai Corporation
//
// SPDX-License-Identifier: MIT

/// <reference types="cypress" />

context('Regression tests', () => {
let taskID = null;
let jobID = null;

const taskPayload = {
name: 'Test annotations actions',
labels: [{
name: 'label 1',
attributes: [],
type: 'any',
}],
project_id: null,
source_storage: { location: 'local' },
target_storage: { location: 'local' },
};

const dataPayload = {
server_files: ['bigArchive.zip'],
image_quality: 70,
use_zip_chunks: true,
use_cache: true,
sorting_method: 'lexicographical',
};

const rectanglePayload = {
frame: 99,
objectType: 'SHAPE',
shapeType: 'RECTANGLE',
points: [250, 64, 491, 228],
occluded: false,
};

before(() => {
cy.visit('auth/login');
cy.login();

cy.headlessCreateTask(taskPayload, dataPayload).then((response) => {
taskID = response.taskID;
[jobID] = response.jobIDs;

cy.headlessCreateObject([rectanglePayload], jobID);
cy.visit(`/tasks/${taskID}/jobs/${jobID}`);
});
});

describe('Regression tests', () => {
it('UI does not crash if to activate an object while frame fetching', () => {
cy.reload();
cy.get('.cvat-player-last-button').click();

cy.intercept('GET', '/api/jobs/**/data?**', (req) => {
req.continue((res) => {
res.setDelay(1000);
});
}).as('delayedRequest');

cy.get('#cvat_canvas_shape_1').trigger('mousemove');
cy.get('#cvat_canvas_shape_1').should('not.have.class', 'cvat_canvas_shape_activated');

cy.wait('@delayedRequest');
cy.get('#cvat_canvas_shape_1').trigger('mousemove');
cy.get('#cvat_canvas_shape_1').should('have.class', 'cvat_canvas_shape_activated');
});
});

after(() => {
cy.logout();
cy.getAuthKey().then((response) => {
const authKey = response.body.key;
cy.request({
method: 'DELETE',
url: `/api/tasks/${taskID}`,
headers: {
Authorization: `Token ${authKey}`,
},
});
});
});
});
23 changes: 23 additions & 0 deletions tests/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,29 @@ Cypress.Commands.add('headlessLogin', (username = Cypress.env('user'), password
});
});

Cypress.Commands.add('headlessCreateObject', (objects, jobID) => {
cy.window().then(async ($win) => {
const job = (await $win.cvat.jobs.get({ jobID }))[0];
await job.annotations.clear(true);

const objectStates = objects
.map((object) => new $win.cvat.classes
.ObjectState({
frame: object.frame,
objectType: $win.cvat.enums.ObjectType[object.objectType],
shapeType: $win.cvat.enums.ShapeType[object.shapeType],
points: $win.Array.from(object.points),
occluded: object.occluded,
label: job.labels[0],
zOrder: 0,
}));

await job.annotations.put($win.Array.from(objectStates));
await job.annotations.save();
return cy.wrap();
});
});
Comment on lines +268 to +289
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure proper error handling for asynchronous operations.

The function does not handle potential errors that might occur during asynchronous operations such as fetching the job, clearing annotations, and saving annotations. Consider adding error handling to improve robustness.

Cypress.Commands.add('headlessCreateObject', (objects, jobID) => {
    cy.window().then(async ($win) => {
        try {
            const job = (await $win.cvat.jobs.get({ jobID }))[0];
            await job.annotations.clear(true);

            const objectStates = objects
                .map((object) => new $win.cvat.classes
                    .ObjectState({
                        frame: object.frame,
                        objectType: $win.cvat.enums.ObjectType[object.objectType],
                        shapeType: $win.cvat.enums.ShapeType[object.shapeType],
                        points: $win.Array.from(object.points),
                        occluded: object.occluded,
                        label: job.labels[0],
                        zOrder: 0,
                    }));

            await job.annotations.put($win.Array.from(objectStates));
            await job.annotations.save();
        } catch (error) {
            console.error('Error creating objects:', error);
        }
        return cy.wrap();
    });
});

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
Cypress.Commands.add('headlessCreateObject', (objects, jobID) => {
cy.window().then(async ($win) => {
const job = (await $win.cvat.jobs.get({ jobID }))[0];
await job.annotations.clear(true);
const objectStates = objects
.map((object) => new $win.cvat.classes
.ObjectState({
frame: object.frame,
objectType: $win.cvat.enums.ObjectType[object.objectType],
shapeType: $win.cvat.enums.ShapeType[object.shapeType],
points: $win.Array.from(object.points),
occluded: object.occluded,
label: job.labels[0],
zOrder: 0,
}));
await job.annotations.put($win.Array.from(objectStates));
await job.annotations.save();
return cy.wrap();
});
});
Cypress.Commands.add('headlessCreateObject', (objects, jobID) => {
cy.window().then(async ($win) => {
try {
const job = (await $win.cvat.jobs.get({ jobID }))[0];
await job.annotations.clear(true);
const objectStates = objects
.map((object) => new $win.cvat.classes
.ObjectState({
frame: object.frame,
objectType: $win.cvat.enums.ObjectType[object.objectType],
shapeType: $win.cvat.enums.ShapeType[object.shapeType],
points: $win.Array.from(object.points),
occluded: object.occluded,
label: job.labels[0],
zOrder: 0,
}));
await job.annotations.put($win.Array.from(objectStates));
await job.annotations.save();
} catch (error) {
console.error('Error creating objects:', error);
}
return cy.wrap();
});
});


Cypress.Commands.add('headlessCreateTask', (taskSpec, dataSpec) => {
cy.window().then(async ($win) => {
const task = new $win.cvat.classes.Task({
Expand Down
Binary file added tests/mounted_file_share/bigArchive.zip
Binary file not shown.