Skip to content

Commit

Permalink
Cypress. Rework the command to add a label. (#4195)
Browse files Browse the repository at this point in the history
* Add command for a label delete. Rework command to add a new label

* The tests adaptations

* Some updates

* Fix ESLint issue

* Fix command
  • Loading branch information
Dmitry Kruchinin committed Feb 4, 2022
1 parent 83126c7 commit 5915740
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2021 Intel Corporation
// Copyright (C) 2021-2022 Intel Corporation
//
// SPDX-License-Identifier: MIT

Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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.', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2021 Intel Corporation
// Copyright (C) 2021-2022 Intel Corporation
//
// SPDX-License-Identifier: MIT

Expand Down Expand Up @@ -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.', () => {
Expand Down
46 changes: 32 additions & 14 deletions tests/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -659,24 +659,42 @@ 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.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('@deleteLabel').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) => {
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');
cy.contains('.cvat-constructor-viewer-item', new RegExp(`^${newLabelName}$`)).should('exist');
});

Cypress.Commands.add('addNewLabelViaContinueButton', (additionalLabels) => {
Expand Down

0 comments on commit 5915740

Please sign in to comment.