From 6574e35ffe93c2403edfb920b089e8f0005e8698 Mon Sep 17 00:00:00 2001 From: Dmitry Kruchinin <33020454+dvkruchinin@users.noreply.github.com> Date: Fri, 9 Oct 2020 14:07:02 +0300 Subject: [PATCH] Cypress test. Actions on polygon. (#2266) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Try to draw a polygon shape/track Try to use parameter “number of points”, polygon drawing should automatically stop after this number of points is achieved Try to switch a label and draw one more polygon Check if everything works here Co-authored-by: Kruchinin --- ...ase_10_polygon_shape_track_label_points.js | 173 ++++++++++++++++++ .../issue_1444_filter_property_shape.js | 18 +- .../issue_1882_polygon_interpolation.js | 37 ++-- ...e_1886_point_coordinates_not_duplicated.js | 18 +- tests/cypress/support/commands.js | 22 ++- 5 files changed, 239 insertions(+), 29 deletions(-) create mode 100644 tests/cypress/integration/case_10_polygon_shape_track_label_points.js diff --git a/tests/cypress/integration/case_10_polygon_shape_track_label_points.js b/tests/cypress/integration/case_10_polygon_shape_track_label_points.js new file mode 100644 index 00000000..7e071197 --- /dev/null +++ b/tests/cypress/integration/case_10_polygon_shape_track_label_points.js @@ -0,0 +1,173 @@ +/* + * Copyright (C) 2020 Intel Corporation + * + * SPDX-License-Identifier: MIT + */ + +/// + +context('Actions on polygon', () => { + + const caseId = '10' + const labelName = `Case ${caseId}` + const taskName = `New annotation task for ${labelName}` + const attrName = `Attr for ${labelName}` + const textDefaultValue = 'Some default value for type Text' + const imageFileName = `image_${labelName.replace(' ', '_').toLowerCase()}` + const image = `${imageFileName}.png` + const newLabelName = `New ${labelName}` + const width = 800 + const height = 800 + const posX = 10 + const posY = 10 + const color = 'gray' + const createPolygonShape = { + reDraw: false, + type: 'Shape', + switchLabel: false, + pointsMap: [ + {x: 200, y: 200}, + {x: 250, y: 200}, + {x: 250, y: 250}, + ], + complete: true, + numberOfPoints: null + } + const createPolygonTrack = { + reDraw: false, + type: 'Track', + switchLabel: false, + pointsMap: [ + {x: 300, y: 200}, + {x: 350, y: 200}, + {x: 350, y: 350}, + ], + complete: true, + numberOfPoints: null + } + const createPolygonShapePoints = { + reDraw: false, + type: 'Shape', + switchLabel: false, + pointsMap: [ + {x: 400, y: 200}, + {x: 450, y: 200}, + {x: 450, y: 250}, + {x: 400, y: 350}, + {x: 380, y: 330}, + ], + numberOfPoints: 5 + } + const createPolygonTrackPoints = { + reDraw: false, + type: 'Track', + switchLabel: false, + pointsMap: [ + {x: 500, y: 200}, + {x: 550, y: 200}, + {x: 550, y: 250}, + {x: 500, y: 350}, + {x: 480, y: 330}, + ], + numberOfPoints: 5 + } + const createPolygonShapeSwitchLabel = { + reDraw: false, + type: 'Shape', + switchLabel: true, + labelName: newLabelName, + pointsMap: [ + {x: 600, y: 200}, + {x: 650, y: 200}, + {x: 650, y: 250}, + ], + complete: true, + numberOfPoints: null + } + const createPolygonTrackSwitchLabel = { + reDraw: false, + type: 'Track', + switchLabel: true, + labelName: newLabelName, + pointsMap: [ + {x: 700, y: 200}, + {x: 750, y: 200}, + {x: 750, y: 250}, + ], + complete: true, + numberOfPoints: null + } + + before(() => { + cy.visit('auth/login') + cy.login() + cy.imageGenerator('cypress/fixtures', image, width, height, color, posX, posY, labelName) + cy.createAnnotationTask(taskName, labelName, attrName, textDefaultValue, image) + cy.openTask(taskName) + }) + + describe(`Testing case "${caseId}"`, () => { + it('Add new label', () => { + cy.contains('button', 'Add label').click() + cy.get('[placeholder="Label name"]').type(newLabelName) + cy.contains('button', 'Done').click() + }) + it('Open a job', () => { + cy.openJob() + }) + it('Draw a polygon shape, track', () => { + cy.createPolygon(createPolygonShape) + cy.get('#cvat_canvas_shape_1') + .should('exist').and('be.visible') + cy.get('#cvat-objects-sidebar-state-item-1') + .should('contain', '1').and('contain', 'POLYGON SHAPE').within(() => { + cy.get('.ant-select-selection-selected-value') + .should('contain', labelName) + }) + cy.createPolygon(createPolygonTrack) + cy.get('#cvat_canvas_shape_2') + .should('exist').and('be.visible') + cy.get('#cvat-objects-sidebar-state-item-2') + .should('contain', '2').and('contain', 'POLYGON TRACK').within(() => { + cy.get('.ant-select-selection-selected-value') + .should('contain', labelName) + }) + }) + it('Draw a polygon shape, track with use parameter "number of points"', () => { + cy.createPolygon(createPolygonShapePoints) + cy.get('#cvat_canvas_shape_3') + .should('exist').and('be.visible') + cy.get('#cvat-objects-sidebar-state-item-3') + .should('contain', '3').and('contain', 'POLYGON SHAPE').within(() => { + cy.get('.ant-select-selection-selected-value') + .should('contain', labelName) + }) + cy.createPolygon(createPolygonTrackPoints) + cy.get('#cvat_canvas_shape_4') + .should('exist').and('be.visible') + cy.get('#cvat-objects-sidebar-state-item-4') + .should('contain', '4').and('contain', 'POLYGON TRACK').within(() => { + cy.get('.ant-select-selection-selected-value') + .should('contain', labelName) + }) + }) + it('Draw a polygon shape, track with second label', () => { + cy.createPolygon(createPolygonShapeSwitchLabel) + cy.get('#cvat_canvas_shape_5') + .should('exist').and('be.visible') + cy.get('#cvat-objects-sidebar-state-item-5') + .should('contain', '5').and('contain', 'POLYGON SHAPE').within(() => { + cy.get('.ant-select-selection-selected-value') + .should('contain', newLabelName) + }) + cy.createPolygon(createPolygonTrackSwitchLabel) + cy.get('#cvat_canvas_shape_6') + .should('exist').and('be.visible') + cy.get('#cvat-objects-sidebar-state-item-6') + .should('contain', '6').and('contain', 'POLYGON TRACK').within(() => { + cy.get('.ant-select-selection-selected-value') + .should('contain', labelName) + }) + }) + }) +}) diff --git a/tests/cypress/integration/issue_1444_filter_property_shape.js b/tests/cypress/integration/issue_1444_filter_property_shape.js index 646ca96b..447e06f2 100644 --- a/tests/cypress/integration/issue_1444_filter_property_shape.js +++ b/tests/cypress/integration/issue_1444_filter_property_shape.js @@ -28,6 +28,18 @@ context('Filter property "shape" work correctly', () => { secondX: 350, secondY: 450 } + const createPolygonShape = { + reDraw: false, + type: 'Shape', + switchLabel: false, + pointsMap: [ + {x: 300, y: 100}, + {x: 400, y: 400}, + {x: 400, y: 250}, + ], + complete: true, + numberOfPoints: null + } before(() => { cy.visit('auth/login') @@ -44,11 +56,7 @@ context('Filter property "shape" work correctly', () => { .should('contain', '1').and('contain', 'RECTANGLE SHAPE') }) it('Create a polygon', () => { - cy.createPolygon('Shape', [ - {x: 300, y: 100}, - {x: 400, y: 400}, - {x: 400, y: 250}, - ]) + cy.createPolygon(createPolygonShape) cy.get('#cvat-objects-sidebar-state-item-2') .should('contain', '2').and('contain', 'POLYGON SHAPE') }) diff --git a/tests/cypress/integration/issue_1882_polygon_interpolation.js b/tests/cypress/integration/issue_1882_polygon_interpolation.js index 7519bbbe..f55bbb51 100644 --- a/tests/cypress/integration/issue_1882_polygon_interpolation.js +++ b/tests/cypress/integration/issue_1882_polygon_interpolation.js @@ -19,6 +19,30 @@ context('The points of the previous polygon mustn\'t appear while polygon\'s int const posX = 10 const posY = 10 const color = 'white' + const createPolygonTrack = { + reDraw: false, + type: 'Track', + switchLabel: false, + pointsMap: [ + {x: 309, y: 431}, + {x: 360, y: 500}, + {x: 320, y: 300}, + ], + complete: true, + numberOfPoints: null + } + const reDrawPolygonTrack = { + reDraw: true, + type: 'Track', + switchLabel: false, + pointsMap: [ + {x: 359, y: 431}, + {x: 410, y: 500}, + {x: 370, y: 300}, + ], + complete: true, + numberOfPoints: null + } before(() => { cy.visit('auth/login') @@ -30,11 +54,7 @@ context('The points of the previous polygon mustn\'t appear while polygon\'s int describe(`Testing issue "${issueId}"`, () => { it('Create a polygon', () => { - cy.createPolygon('Track', [ - {x: 309, y: 431}, - {x: 360, y: 500}, - {x: 320, y: 300}, - ]) + cy.createPolygon(createPolygonTrack) cy.get('#cvat-objects-sidebar-state-item-1') .should('contain', '1').and('contain', 'POLYGON TRACK') }) @@ -43,12 +63,7 @@ context('The points of the previous polygon mustn\'t appear while polygon\'s int .trigger('mousemove', {force: true}) .trigger('keydown', {key: 'n', shiftKey: true}) .trigger('keyup', {force: true}, {key: 'n', shiftKey: true}) - cy.createPolygon('Track', [ - {x: 359, y: 431}, - {x: 410, y: 500}, - {x: 370, y: 300}, - ], - false, true) + cy.createPolygon(reDrawPolygonTrack) }) it('Activate auto bordering mode', () => { cy.openSettings() diff --git a/tests/cypress/integration/issue_1886_point_coordinates_not_duplicated.js b/tests/cypress/integration/issue_1886_point_coordinates_not_duplicated.js index af3b6653..caa3af0b 100644 --- a/tests/cypress/integration/issue_1886_point_coordinates_not_duplicated.js +++ b/tests/cypress/integration/issue_1886_point_coordinates_not_duplicated.js @@ -28,6 +28,18 @@ context('Point coordinates are not duplicated while polygon\'s interpolation.', const imagesFolder = `cypress/fixtures/image_issue_${issueId}` const directoryToArchive = imagesFolder let pointsСoordinates = [] + const createPolygonTrack = { + reDraw: false, + type: 'Track', + switchLabel: false, + pointsMap: [ + {x: 300, y: 450}, + {x: 400, y: 450}, + {x: 400, y: 550}, + ], + complete: true, + numberOfPoints: null + } before(() => { cy.visit('auth/login') @@ -42,11 +54,7 @@ context('Point coordinates are not duplicated while polygon\'s interpolation.', describe(`Testing issue "${issueId}"`, () => { it('Create a polygon', () => { - cy.createPolygon('Track', [ - {x: 300, y: 450}, - {x: 400, y: 450}, - {x: 400, y: 550}, - ]) + cy.createPolygon(createPolygonTrack) cy.get('#cvat-objects-sidebar-state-item-1') .should('contain', '1').and('contain', 'POLYGON TRACK') }) diff --git a/tests/cypress/support/commands.js b/tests/cypress/support/commands.js index 50ea068d..75578791 100644 --- a/tests/cypress/support/commands.js +++ b/tests/cypress/support/commands.js @@ -151,25 +151,31 @@ Cypress.Commands.add('shapeGrouping', (firstX, firstY, lastX, lastY) => { .trigger('keyup', {key: 'g'}) }) -Cypress.Commands.add('createPolygon', ( mode, - pointsMap, - complete=true, - reDraw=false) => { - if (!reDraw) { +Cypress.Commands.add('createPolygon', (createPolygonParams) => { + if (!createPolygonParams.reDraw) { cy.get('.cvat-draw-polygon-control').click() + if (createPolygonParams.switchLabel) { + cy.switchLabel(createPolygonParams.labelName) + } cy.contains('Draw new polygon') .parents('.cvat-draw-shape-popover-content') .within(() => { + if (createPolygonParams.numberOfPoints) { + createPolygonParams.complete = false + cy.get('.ant-input-number-input') + .clear() + .type(createPolygonParams.numberOfPoints) + } cy.get('button') - .contains(mode) + .contains(createPolygonParams.type) .click({force: true}) }) } - pointsMap.forEach(element => { + createPolygonParams.pointsMap.forEach(element => { cy.get('.cvat-canvas-container') .click(element.x, element.y) }) - if (complete) { + if (createPolygonParams.complete) { cy.get('.cvat-canvas-container') .trigger('keydown', {key: 'n'}) .trigger('keyup', {key: 'n'})