From 2e325ae4d45ece1eb31a874bcad5eb3240a64ea4 Mon Sep 17 00:00:00 2001 From: Dmitry Kruchinin <33020454+dvkruchinin@users.noreply.github.com> Date: Mon, 1 Feb 2021 09:53:30 +0300 Subject: [PATCH] Add cypress test. Update cypress command. (#2716) --- ...44_changing_default_value_for_attribute.js | 78 +++++++++++++++++++ tests/cypress/support/commands.js | 6 +- 2 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 tests/cypress/integration/actions_tasks_objects/case_44_changing_default_value_for_attribute.js diff --git a/tests/cypress/integration/actions_tasks_objects/case_44_changing_default_value_for_attribute.js b/tests/cypress/integration/actions_tasks_objects/case_44_changing_default_value_for_attribute.js new file mode 100644 index 00000000..81cf370c --- /dev/null +++ b/tests/cypress/integration/actions_tasks_objects/case_44_changing_default_value_for_attribute.js @@ -0,0 +1,78 @@ +// Copyright (C) 2021 Intel Corporation +// +// SPDX-License-Identifier: MIT + +/// + +import { taskName } from '../../support/const'; + +context('Changing a default value for an attribute.', () => { + const caseId = '44'; + const additionalLabel = `Case ${caseId}`; + const additionalAttrsLabel = [ + { additionalAttrName: 'type', additionalValue: '', typeAttribute: 'Text' }, + { additionalAttrName: 'shape', additionalValue: 'False', typeAttribute: 'Checkbox' }, + ]; + const rectangleShape2Points = { + points: 'By 2 Points', + type: 'Shape', + labelName: additionalLabel, + firstX: 400, + firstY: 100, + secondX: 500, + secondY: 200, + }; + const newTextValue = `${additionalLabel} text`; + const newCheckboxValue = 'True'; + let wrapperId = []; + + before(() => { + cy.openTask(taskName); + }); + + describe(`Testing case "${caseId}"`, () => { + it('Add a label, add text (leave it’s value empty by default) & checkbox attributes.', () => { + cy.server().route('PATCH', '/api/v1/tasks/**').as('patchTask'); + cy.server().route('GET', '/api/v1/tasks**').as('getTask'); + cy.addNewLabel(additionalLabel, additionalAttrsLabel); + cy.wait('@patchTask').its('status').should('equal', 200); + cy.wait('@getTask').its('status').should('equal', 200); + }); + + it('Open label editor. Change default values for text & checkbox attributes, press Done.', () => { + cy.server().route('PATCH', '/api/v1/tasks/**').as('patchTask'); + cy.get('.cvat-constructor-viewer').within(() => { + cy.contains(new RegExp(`^${additionalLabel}$`)) + .parents('.cvat-constructor-viewer-item') + .find('[aria-label="edit"]') + .click({ force: true }); + }); + cy.get('.cvat-label-constructor-updater').within(() => { + cy.get('.cvat-attribute-inputs-wrapper').then((wrapper) => { + for (let i = 0; i < wrapper.length; i++) { + wrapperId.push(wrapper[i].getAttribute('cvat-attribute-id')); + } + const minId = Math.min(...wrapperId); + const maxId = Math.max(...wrapperId); + cy.get(`[cvat-attribute-id="${minId}"]`).find('.cvat-attribute-values-input').type(newTextValue); + cy.task('log', `minId: ${minId}`); + cy.get(`[cvat-attribute-id="${maxId}"]`).find('.cvat-attribute-values-input').click().wait(500); // Wait for the dropdown menu to transition. + cy.task('log', `maxId: ${maxId}`); + }); + }); + cy.get('.ant-select-dropdown').within(() => { + cy.contains(new RegExp(`^${newCheckboxValue}$`)).click(); + }); + cy.contains('[type="submit"]', 'Done').click(); + cy.wait('@patchTask').its('status').should('equal', 200); + }); + + it('Open a job, create an object. Attribute values are correct.', () => { + cy.openJob(); + cy.createRectangle(rectangleShape2Points); + cy.get('#cvat_canvas_shape_1').trigger('mousemove'); + cy.contains(new RegExp(`^type: ${newTextValue}$`)).should('be.visible'); + cy.contains(new RegExp(`^shape: ${newCheckboxValue.toLowerCase()}$`)).should('be.visible'); + }); + }); +}); diff --git a/tests/cypress/support/commands.js b/tests/cypress/support/commands.js index 399f9221..202a8b2b 100644 --- a/tests/cypress/support/commands.js +++ b/tests/cypress/support/commands.js @@ -339,7 +339,11 @@ Cypress.Commands.add('updateAttributes', (multiAttrParams) => { if (multiAttrParams.typeAttribute === 'Text' || multiAttrParams.typeAttribute === 'Number') { cy.get(`[cvat-attribute-id="${minId}"]`).within(() => { - cy.get('.cvat-attribute-values-input').type(multiAttrParams.additionalValue); + if (multiAttrParams.additionalValue !== '') { + cy.get('.cvat-attribute-values-input').type(multiAttrParams.additionalValue); + } else { + cy.get('.cvat-attribute-values-input').clear(); + } }); } else if (multiAttrParams.typeAttribute === 'Radio') { cy.get(`[cvat-attribute-id="${minId}"]`).within(() => {