From cf7c8688654a581e58c117bd03af107965b3d88a Mon Sep 17 00:00:00 2001 From: dvkruchinin Date: Tue, 18 Jan 2022 12:17:25 +0300 Subject: [PATCH 1/5] Add command for a label delete. Rework command to add a new label --- tests/cypress/support/commands.js | 45 ++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/tests/cypress/support/commands.js b/tests/cypress/support/commands.js index da64e1ef8c9..b2f04c0fa7a 100644 --- a/tests/cypress/support/commands.js +++ b/tests/cypress/support/commands.js @@ -1,4 +1,4 @@ -// Copyright (C) 2020-2021 Intel Corporation +// Copyright (C) 2020-2022 Intel Corporation // // SPDX-License-Identifier: MIT @@ -628,24 +628,39 @@ Cypress.Commands.add('collectLabelsName', () => { }); }); +Cypress.Commands.add('deleteLabel', (labelName) => { + cy.contains('.cvat-constructor-viewer-item', new RegExp(`^${labelName}$`)) + .should('exist') + .and('be.visible') + .find('[aria-label="close"]') + .click(); + cy.get('.cvat-modal-delete-label') + .should('be.visible') + .within(() => { + cy.contains('[type="button"]', 'OK').click(); + }); + cy.contains('.cvat-constructor-viewer-item', labelName).should('not.exist'); +}); + Cypress.Commands.add('addNewLabel', (newLabelName, additionalAttrs, labelColor) => { cy.collectLabelsName().then((labelsNames) => { - if (labelsNames.indexOf(newLabelName) === -1) { - cy.contains('button', 'Add label').click(); - cy.get('[placeholder="Label name"]').type(newLabelName); - if (labelColor) { - cy.get('.cvat-change-task-label-color-badge').click(); - cy.changeColorViaBadge(labelColor); - } - if (additionalAttrs) { - for (let i = 0; i < additionalAttrs.length; i++) { - cy.updateAttributes(additionalAttrs[i]); - } - } - cy.contains('button', 'Done').click(); - cy.get('.cvat-constructor-viewer').should('be.visible'); + if (labelsNames.includes(newLabelName)) { + cy.deleteLabel(newLabelName); } }); + cy.contains('button', 'Add label').click(); + cy.get('[placeholder="Label name"]').type(newLabelName); + if (labelColor) { + cy.get('.cvat-change-task-label-color-badge').click(); + cy.changeColorViaBadge(labelColor); + } + if (additionalAttrs) { + for (let i = 0; i < additionalAttrs.length; i++) { + cy.updateAttributes(additionalAttrs[i]); + } + } + cy.contains('button', 'Done').click(); + cy.get('.cvat-constructor-viewer').should('be.visible'); }); Cypress.Commands.add('addNewLabelViaContinueButton', (additionalLabels) => { From 5abb9099f64ba78ea7ec3c07489623bf715095ce Mon Sep 17 00:00:00 2001 From: dvkruchinin Date: Tue, 18 Jan 2022 12:18:18 +0300 Subject: [PATCH 2/5] The tests adaptations --- .../case_57_project_label_deleting_feature.js | 14 ++------------ .../case_58_task_label_deleting_feature.js | 14 ++------------ 2 files changed, 4 insertions(+), 24 deletions(-) diff --git a/tests/cypress/integration/actions_projects_models/case_57_project_label_deleting_feature.js b/tests/cypress/integration/actions_projects_models/case_57_project_label_deleting_feature.js index 8c285a1017b..856f973a581 100644 --- a/tests/cypress/integration/actions_projects_models/case_57_project_label_deleting_feature.js +++ b/tests/cypress/integration/actions_projects_models/case_57_project_label_deleting_feature.js @@ -1,4 +1,4 @@ -// Copyright (C) 2021 Intel Corporation +// Copyright (C) 2021-2022 Intel Corporation // // SPDX-License-Identifier: MIT @@ -67,17 +67,7 @@ context('Delete a label from a project.', () => { it('Delete a label from project.', () => { cy.openProject(projectName); getProjectID(projectName); - cy.contains('.cvat-constructor-viewer-item', labelName) - .should('exist') - .and('be.visible') - .find('[aria-label="close"]') - .click(); - cy.get('.cvat-modal-delete-label') - .should('be.visible') - .within(() => { - cy.contains('[type="button"]', 'OK').click(); - }); - cy.contains('.cvat-constructor-viewer-item', labelName).should('not.exist'); + cy.deleteLabel(labelName); }); it('Try to open job with no labels in the project. Successful.', () => { diff --git a/tests/cypress/integration/actions_tasks/case_58_task_label_deleting_feature.js b/tests/cypress/integration/actions_tasks/case_58_task_label_deleting_feature.js index 9779e402f73..e070b83f0a9 100644 --- a/tests/cypress/integration/actions_tasks/case_58_task_label_deleting_feature.js +++ b/tests/cypress/integration/actions_tasks/case_58_task_label_deleting_feature.js @@ -1,4 +1,4 @@ -// Copyright (C) 2021 Intel Corporation +// Copyright (C) 2021-2022 Intel Corporation // // SPDX-License-Identifier: MIT @@ -38,17 +38,7 @@ context('Delete a label from a task.', () => { describe(`Testing "${labelName}"`, () => { it('Delete a label from the task.', () => { - cy.contains('.cvat-constructor-viewer-item', labelName) - .should('exist') - .and('be.visible') - .find('[aria-label="close"]') - .click(); - cy.get('.cvat-modal-delete-label') - .should('be.visible') - .within(() => { - cy.contains('[type="button"]', 'OK').click(); - }); - cy.contains('.cvat-constructor-viewer-item', labelName).should('not.exist'); + cy.deleteLabel(labelName); }); it('Try to open a job with no labels. Successful.', () => { From 26073965484add785a95456e8e30be1554922701 Mon Sep 17 00:00:00 2001 From: dvkruchinin Date: Tue, 18 Jan 2022 13:52:01 +0300 Subject: [PATCH 3/5] Some updates --- tests/cypress/support/commands.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/cypress/support/commands.js b/tests/cypress/support/commands.js index b2f04c0fa7a..315fae00a0b 100644 --- a/tests/cypress/support/commands.js +++ b/tests/cypress/support/commands.js @@ -634,12 +634,14 @@ Cypress.Commands.add('deleteLabel', (labelName) => { .and('be.visible') .find('[aria-label="close"]') .click(); + cy.intercept('PATCH', '/api/v1/tasks/**').as('tasks'); cy.get('.cvat-modal-delete-label') .should('be.visible') .within(() => { cy.contains('[type="button"]', 'OK').click(); }); - cy.contains('.cvat-constructor-viewer-item', labelName).should('not.exist'); + cy.wait('@tasks').its('response.statusCode').should('equal', 200); + cy.contains('.cvat-constructor-viewer-item', new RegExp(`^${labelName}$`)).should('not.exist'); }); Cypress.Commands.add('addNewLabel', (newLabelName, additionalAttrs, labelColor) => { @@ -661,6 +663,7 @@ Cypress.Commands.add('addNewLabel', (newLabelName, additionalAttrs, labelColor) } cy.contains('button', 'Done').click(); cy.get('.cvat-constructor-viewer').should('be.visible'); + cy.contains('.cvat-constructor-viewer-item', new RegExp(`^${newLabelName}$`)).should('exist'); }); Cypress.Commands.add('addNewLabelViaContinueButton', (additionalLabels) => { From 97e227a8cb9e6191590e12830f57188bc062199d Mon Sep 17 00:00:00 2001 From: dvkruchinin Date: Tue, 18 Jan 2022 13:57:57 +0300 Subject: [PATCH 4/5] Fix ESLint issue --- .../case_57_project_label_deleting_feature.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cypress/integration/actions_projects_models/case_57_project_label_deleting_feature.js b/tests/cypress/integration/actions_projects_models/case_57_project_label_deleting_feature.js index 856f973a581..00a95df1c98 100644 --- a/tests/cypress/integration/actions_projects_models/case_57_project_label_deleting_feature.js +++ b/tests/cypress/integration/actions_projects_models/case_57_project_label_deleting_feature.js @@ -28,7 +28,7 @@ context('Delete a label from a project.', () => { const multiAttrParams = false; let projectID = ''; - function getProjectID(projectName) { + function getProjectID() { cy.contains('.cvat-project-name', projectName) .parents('.cvat-project-details') .should('have.attr', 'cvat-project-id') From 35ecd7f23c11c55ccf9d8d209810997e1a21be11 Mon Sep 17 00:00:00 2001 From: dvkruchinin Date: Tue, 18 Jan 2022 14:42:07 +0300 Subject: [PATCH 5/5] Fix command --- tests/cypress/support/commands.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/cypress/support/commands.js b/tests/cypress/support/commands.js index 315fae00a0b..1653679abf1 100644 --- a/tests/cypress/support/commands.js +++ b/tests/cypress/support/commands.js @@ -634,13 +634,13 @@ Cypress.Commands.add('deleteLabel', (labelName) => { .and('be.visible') .find('[aria-label="close"]') .click(); - cy.intercept('PATCH', '/api/v1/tasks/**').as('tasks'); + cy.intercept('PATCH', /\/api\/v1\/(tasks|projects)\/.*/).as('deleteLabel'); cy.get('.cvat-modal-delete-label') .should('be.visible') .within(() => { cy.contains('[type="button"]', 'OK').click(); }); - cy.wait('@tasks').its('response.statusCode').should('equal', 200); + cy.wait('@deleteLabel').its('response.statusCode').should('equal', 200); cy.contains('.cvat-constructor-viewer-item', new RegExp(`^${labelName}$`)).should('not.exist'); });