diff --git a/cvat-ui/src/components/labels-editor/raw-viewer.tsx b/cvat-ui/src/components/labels-editor/raw-viewer.tsx index 7c6c0b0ff085..d50adcf66ca2 100644 --- a/cvat-ui/src/components/labels-editor/raw-viewer.tsx +++ b/cvat-ui/src/components/labels-editor/raw-viewer.tsx @@ -106,12 +106,13 @@ export default class RawViewer extends React.PureComponent { 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 ? ( Following labels are going to be removed: -
+
{deletedLabels .map((_label: Label) => {_label.name})}
@@ -121,7 +122,7 @@ export default class RawViewer extends React.PureComponent { {deletedAttributes.length ? ( Following attributes are going to be removed: -
+
{deletedAttributes.map((_attr: Attribute) => {_attr.name})}
diff --git a/tests/cypress/integration/actions_projects_models/case_116_creating_project_by_inserting_labels_from_task.js b/tests/cypress/integration/actions_projects_models/case_116_creating_project_by_inserting_labels_from_task.js new file mode 100644 index 000000000000..17d812f78622 --- /dev/null +++ b/tests/cypress/integration/actions_projects_models/case_116_creating_project_by_inserting_labels_from_task.js @@ -0,0 +1,83 @@ +// Copyright (C) 2022 Intel Corporation +// +// SPDX-License-Identifier: MIT + +/// + +// 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":'); + }); + }); + }); +}); diff --git a/tests/cypress/integration/actions_tasks/case_117_paste_labels_from_another_task.js b/tests/cypress/integration/actions_tasks/case_117_paste_labels_from_another_task.js new file mode 100644 index 000000000000..286bffb7bc06 --- /dev/null +++ b/tests/cypress/integration/actions_tasks/case_117_paste_labels_from_another_task.js @@ -0,0 +1,91 @@ +// Copyright (C) 2022 Intel Corporation +// +// SPDX-License-Identifier: MIT + +/// + +// 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'); + }); + }); +}); diff --git a/tests/cypress/support/commands.js b/tests/cypress/support/commands.js index 82ce94ce2d4f..ac8ec85e2a58 100644 --- a/tests/cypress/support/commands.js +++ b/tests/cypress/support/commands.js @@ -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); diff --git a/tests/cypress/support/index.js b/tests/cypress/support/index.js index 62aaa7681006..921e447254ff 100644 --- a/tests/cypress/support/index.js +++ b/tests/cypress/support/index.js @@ -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') { diff --git a/tests/package-lock.json b/tests/package-lock.json index 0d340a022d56..67a75903af3f 100644 --- a/tests/package-lock.json +++ b/tests/package-lock.json @@ -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" } @@ -3398,6 +3399,14 @@ "cypress": "^2.1.0 || 3.x || 4.x || 5.x || 6.x || 7.x || 8.x" } }, + "node_modules/cypress-real-events": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/cypress-real-events/-/cypress-real-events-1.6.0.tgz", + "integrity": "sha512-QxXm0JsQkCrb2uH+fMXNDQ5kNWTzX3OtndBafdsZmNV19j+6JuTK9n52B1YVxrDrr/qzPAojcHJc5PNoQvwp+w==", + "peerDependencies": { + "cypress": "^4.x || ^5.x || ^6.x || ^7.x || ^8.x || ^9.x" + } + }, "node_modules/cypress/node_modules/ansi-styles": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", @@ -10962,6 +10971,12 @@ "integrity": "sha512-gl1uKeviYdyJG4dLcZ9hfoUjLciwkkfbaQ3gvRtmipsPxC612ZBJhSjbunnJcUGwkryaM+82VrY9ij0tLSg7LA==", "requires": {} }, + "cypress-real-events": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/cypress-real-events/-/cypress-real-events-1.6.0.tgz", + "integrity": "sha512-QxXm0JsQkCrb2uH+fMXNDQ5kNWTzX3OtndBafdsZmNV19j+6JuTK9n52B1YVxrDrr/qzPAojcHJc5PNoQvwp+w==", + "requires": {} + }, "dash-ast": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/dash-ast/-/dash-ast-1.0.0.tgz", diff --git a/tests/package.json b/tests/package.json index 11db8aee1ec9..1f3241bff538 100644 --- a/tests/package.json +++ b/tests/package.json @@ -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" }