Skip to content

Commit

Permalink
Cypress tests. Paste labels to another task/project. (#4236)
Browse files Browse the repository at this point in the history
* Start writing the test

* Rename the test

* Update the test. Added a cypress plugin

* Added comment

* Change the comment

* Started writing the test for paste labels from another task

* Added classes

* Update command

* Renamed fine name. Added test for task
  • Loading branch information
Dmitry Kruchinin authored Jan 26, 2022
1 parent e212d57 commit 5e43171
Show file tree
Hide file tree
Showing 7 changed files with 197 additions and 3 deletions.
5 changes: 3 additions & 2 deletions cvat-ui/src/components/labels-editor/raw-viewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,13 @@ export default class RawViewer extends React.PureComponent<Props> {
if (deletedLabels.length || deletedAttributes.length) {
Modal.confirm({
title: 'You are going to remove existing labels/attributes',
className: 'cvat-modal-confirm-remove-existing-labels',
content: (
<>
{deletedLabels.length ? (
<Paragraph>
Following labels are going to be removed:
<div>
<div className='cvat-modal-confirm-content-remove-existing-labels'>
{deletedLabels
.map((_label: Label) => <Tag color={_label.color}>{_label.name}</Tag>)}
</div>
Expand All @@ -121,7 +122,7 @@ export default class RawViewer extends React.PureComponent<Props> {
{deletedAttributes.length ? (
<Paragraph>
Following attributes are going to be removed:
<div>
<div className='cvat-modal-confirm-content-remove-existing-attributes'>
{deletedAttributes.map((_attr: Attribute) => <Tag>{_attr.name}</Tag>)}
</div>
</Paragraph>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// Copyright (C) 2022 Intel Corporation
//
// SPDX-License-Identifier: MIT

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

// The test is disabled for Firefox because the "Cypress Real Events" plugin work only in the chromium-based browser.
context('Creating a project by inserting labels from a task.', { browser: '!firefox' }, () => {
const caseID = '116';
const task = {
name: `Case ${caseID}`,
label: 'Tree',
attrName: 'Kind',
attrValue: 'Oak',
};

const projectName = `Case ${caseID}`;

const imagesCount = 1;
const imageFileName = `image_${task.name.replace(' ', '_').toLowerCase()}`;
const width = 800;
const height = 800;
const posX = 10;
const posY = 10;
const color = 'gray';
const archiveName = `${imageFileName}.zip`;
const archivePath = `cypress/fixtures/${archiveName}`;
const imagesFolder = `cypress/fixtures/${imageFileName}`;
const directoryToArchive = imagesFolder;

before(() => {
cy.visit('/');
cy.login();
cy.imageGenerator(imagesFolder, imageFileName, width, height, color, posX, posY, task.name, imagesCount);
cy.createZipArchive(directoryToArchive, archivePath);
cy.goToTaskList();
cy.createAnnotationTask(task.name, task.label, task.attrName, task.attrValue, archiveName);
});

after(() => {
cy.logout();
cy.getAuthKey().then((authKey) => {
cy.deleteTasks(authKey, [task.name]);
cy.deleteProjects(authKey, [projectName]);
});
});

describe(`Testing "Case ${caseID}"`, () => {
it('Copying a labels from the task from the raw editor.', () => {
cy.openTask(task.name);
cy.contains('[role="tab"]', 'Raw').click();
cy.get('.cvat-raw-labels-viewer')
.focus()
.realPress(['ControlLeft', 'a'])
.realPress(['ControlLeft', 'c']);
});

it('Creating a project with copying labels from the task.', () => {
cy.goToProjectsList();
cy.get('.cvat-create-project-button').click();
cy.get('#name').type(projectName);
cy.contains('[role="tab"]', 'Raw').click();
cy.get('.cvat-raw-labels-viewer')
.focus()
.clear()
.realPress(['ControlLeft', 'v']);
cy.get('.cvat-raw-labels-viewer').then((raw) => {
expect(raw.text()).not.contain('"id":');
});
cy.contains('button', 'Done').click();
cy.contains('[role="tab"]', 'Constructor').click();
cy.contains('.cvat-constructor-viewer-item', task.label).should('exist');
cy.contains('button', 'Submit').click();
cy.get('.cvat-notification-create-project-success').should('exist').find('[data-icon="close"]').click();
cy.goToProjectsList();
cy.openProject(projectName);
cy.contains('[role="tab"]', 'Raw').click();
cy.get('.cvat-raw-labels-viewer').then((raw) => {
expect(raw.text()).contain('"id":');
});
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// Copyright (C) 2022 Intel Corporation
//
// SPDX-License-Identifier: MIT

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

// The test is disabled for Firefox because the "Cypress Real Events" plugin work only in the chromium-based browser.
context('Paste labels from one task to another.', { browser: '!firefox' }, () => {
const caseID = '117';
const task = {
name: `Case ${caseID}`,
label: 'Tree',
attrName: 'Kind',
attrValue: 'Oak',
nameSecond: `Case ${caseID} second`,
labelSecond: 'Car',
attrNameSecond: 'Color',
attrValueSecond: 'Red',
};

const imagesCount = 1;
const imageFileName = `image_${task.name.replace(' ', '_').toLowerCase()}`;
const width = 800;
const height = 800;
const posX = 10;
const posY = 10;
const color = 'gray';
const archiveName = `${imageFileName}.zip`;
const archivePath = `cypress/fixtures/${archiveName}`;
const imagesFolder = `cypress/fixtures/${imageFileName}`;
const directoryToArchive = imagesFolder;

before(() => {
cy.visit('/');
cy.login();
cy.imageGenerator(imagesFolder, imageFileName, width, height, color, posX, posY, task.name, imagesCount);
cy.createZipArchive(directoryToArchive, archivePath);
cy.goToTaskList();
cy.createAnnotationTask(task.name, task.label, task.attrName, task.attrValue, archiveName);
cy.createAnnotationTask(
task.nameSecond, task.labelSecond, task.attrNameSecond, task.attrValueSecond, archiveName,
);
});

after(() => {
cy.logout();
cy.getAuthKey().then((authKey) => {
cy.deleteTasks(authKey, [task.name, task.nameSecond]);
});
});

describe(`Testing "Case ${caseID}"`, () => {
it('Copying a label from a task via the raw editor.', () => {
cy.openTask(task.name);
cy.contains('[role="tab"]', 'Raw').click();
cy.get('.cvat-raw-labels-viewer')
.focus()
.realPress(['ControlLeft', 'a'])
.realPress(['ControlLeft', 'c']);
});

it('Paste the labels to another task instead of existing.', () => {
cy.goToTaskList();
cy.openTask(task.nameSecond);
cy.contains('.cvat-constructor-viewer-item', task.labelSecond).should('exist');
cy.contains('[role="tab"]', 'Raw').click();
cy.get('.cvat-raw-labels-viewer')
.focus()
.clear()
.realPress(['ControlLeft', 'v']);
cy.get('.cvat-raw-labels-viewer').then((raw) => {
expect(raw.text()).not.contain('"id":');
});
cy.contains('button', 'Done').click();
cy.get('.cvat-modal-confirm-remove-existing-labels').should('be.visible').within(() => {
cy.get('.cvat-modal-confirm-content-remove-existing-labels').should('have.text', task.labelSecond);
cy.get('.cvat-modal-confirm-content-remove-existing-attributes')
.should('have.text', task.attrNameSecond);
cy.contains('button', 'Delete existing data').click();
});
cy.get('.cvat-modal-confirm-remove-existing-labels').should('not.exist');
cy.get('.cvat-raw-labels-viewer').then((raw) => {
expect(raw.text()).contain('"id":');
});
cy.contains('[role="tab"]', 'Constructor').click();
cy.get('.cvat-constructor-viewer-item').should('have.length', 1);
cy.contains('.cvat-constructor-viewer-item', task.label).should('exist');
cy.contains('.cvat-constructor-viewer-item', task.labelSecond).should('not.exist');
});
});
});
4 changes: 3 additions & 1 deletion tests/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,9 @@ Cypress.Commands.add(
);

Cypress.Commands.add('openTask', (taskName, projectSubsetFieldValue) => {
cy.contains('strong', taskName).parents('.cvat-tasks-list-item').contains('a', 'Open').click({ force: true });
cy.contains('strong', new RegExp(`^${taskName}$`))
.parents('.cvat-tasks-list-item')
.contains('a', 'Open').click({ force: true });
cy.get('.cvat-task-details').should('exist');
if (projectSubsetFieldValue) {
cy.get('.cvat-project-subset-field').find('input').should('have.attr', 'value', projectSubsetFieldValue);
Expand Down
1 change: 1 addition & 0 deletions tests/cypress/support/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ require('./commands_models');
require('./commands_opencv');
require('./commands_organizations');
require('@cypress/code-coverage/support');
require('cypress-real-events/support');

before(() => {
if (Cypress.browser.family !== 'chromium') {
Expand Down
15 changes: 15 additions & 0 deletions tests/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"cypress": "^8.3.1",
"cypress-file-upload": "^5.0.8",
"cypress-localstorage-commands": "^1.5.0",
"cypress-real-events": "^1.6.0",
"extract-zip": "^2.0.1",
"jimp": "^0.16.1"
}
Expand Down

0 comments on commit 5e43171

Please sign in to comment.