Skip to content

Commit

Permalink
added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
klakhov committed Jun 25, 2024
1 parent 977a890 commit 28d30ad
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 0 deletions.
114 changes: 114 additions & 0 deletions tests/cypress/e2e/features/annotations_actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,120 @@ context('Testing annotations actions workflow', () => {
});
});

describe('Test action: "Propagate shapes"', () => {
const ACTION_NAME = 'Propagate shapes';
const FORMAT_NAME = 'Segmentation mask 1.1';

function checkFramesContainShapes(from, to, amount) {
frames.forEach((frame) => {
cy.goCheckFrameNumber(frame);

if (frame >= from && frame <= to) {
cy.get('.cvat_canvas_shape').should('have.length', amount);
} else {
cy.get('.cvat_canvas_shape').should('have.length', 0);
}
});
}

before(() => {
const shapes = [{
type: 'rectangle',
occluded: false,
outside: false,
z_order: 0,
points: [250, 350, 350, 450],
rotation: 0,
attributes: [],
elements: [],
frame: 0,
label_id: labels[0].id,
group: 0,
source: 'manual',
}, {
type: 'rectangle',
occluded: false,
outside: false,
z_order: 0,
points: [350, 450, 450, 550],
rotation: 0,
attributes: [],
elements: [],
frame: 0,
label_id: labels[1].id,
group: 0,
source: 'manual',
}];

cy.window().then((window) => {
window.cvat.server.request(`/api/jobs/${jobID}/annotations`, {
method: 'PUT',
data: { shapes },
});
});
});

beforeEach(() => {
cy.visit(`/tasks/${taskID}/jobs/${jobID}`);
cy.get('.cvat-canvas-container').should('not.exist');
cy.get('.cvat-canvas-container').should('exist').and('be.visible');
});

it('Apply action on specific frames', () => {
const middleFrame = Math.round(latestFrameNumber / 2);
cy.openAnnotationsActionsModal();
cy.selectAnnotationsAction(ACTION_NAME);
cy.setAnnotationActionParameter('Target frame', 'input', middleFrame);
cy.runAnnotationsAction();
cy.waitAnnotationsAction();
cy.closeAnnotationsActionsModal();
checkFramesContainShapes(0, middleFrame, 2);
});

it('Apply action on current frame', () => {
cy.openAnnotationsActionsModal();
cy.selectAnnotationsAction(ACTION_NAME);
cy.setAnnotationActionParameter('Target frame', 'input', 0);
cy.runAnnotationsAction();
cy.waitAnnotationsAction();
cy.closeAnnotationsActionsModal();
checkFramesContainShapes(0, 0, 2);
});

it('Apply action on mask with different frame sizes. Mask is cropped. Segmentation mask export is available', () => {
// Default frame size is 800x800, but last frame is 500x500
cy.goCheckFrameNumber(latestFrameNumber - 1);
cy.startMaskDrawing();
cy.drawMask([{
method: 'brush',
coordinates: [[620, 620], [700, 620], [700, 700], [620, 700]],
}]);
cy.finishMaskDrawing();

cy.openAnnotationsActionsModal();
cy.selectAnnotationsAction(ACTION_NAME);
cy.runAnnotationsAction();
cy.waitAnnotationsAction();
cy.closeAnnotationsActionsModal();

cy.get('.cvat_canvas_shape').should('have.length', 1);
cy.goCheckFrameNumber(latestFrameNumber);
cy.get('.cvat_canvas_shape').should('have.length', 1);

cy.saveJob('PUT', 200, 'saveJob');
const exportAnnotation = {
as: 'exportAnnotations',
type: 'annotations',
format: FORMAT_NAME,
};
cy.exportJob(exportAnnotation);
cy.getDownloadFileName().then((file) => {
cy.verifyDownload(file);
});
cy.verifyNotification();
});
});

after(() => {
cy.logout();
cy.getAuthKey().then((response) => {
Expand Down
1 change: 1 addition & 0 deletions tests/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -1236,6 +1236,7 @@ Cypress.Commands.add('exportJob', ({
}) => {
cy.interactMenu('Export job dataset');
cy.get('.cvat-modal-export-job').should('be.visible').find('.cvat-modal-export-select').click();
cy.contains('.cvat-modal-export-option-item', format).scrollIntoView();
cy.contains('.cvat-modal-export-option-item', format).should('be.visible').click();
cy.get('.cvat-modal-export-job').find('.cvat-modal-export-select').should('contain.text', format);
if (type === 'dataset') {
Expand Down
11 changes: 11 additions & 0 deletions tests/cypress/support/commands_annotations_actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,14 @@ Cypress.Commands.add('selectAnnotationsAction', (name) => {
Cypress.Commands.add('waitAnnotationsAction', () => {
cy.get('.cvat-action-runner-progress').should('not.exist'); // wait until action ends
});

Cypress.Commands.add('setAnnotationActionParameter', (parameterName, type, value) => {
if (type === 'input') {
cy.get('.cvat-action-runner-action-parameters').within(() => {
cy.contains('.cvat-action-runner-action-parameter', parameterName)
.get('input').clear();
cy.contains('.cvat-action-runner-action-parameter', parameterName)
.get('input').type(value);
});
}
});

0 comments on commit 28d30ad

Please sign in to comment.