diff --git a/tests/cypress/integration/actions_tasks_objects/case_20_objects_ordering_feature.js b/tests/cypress/integration/actions_tasks_objects/case_20_objects_ordering_feature.js new file mode 100644 index 000000000000..0d0b426b6e73 --- /dev/null +++ b/tests/cypress/integration/actions_tasks_objects/case_20_objects_ordering_feature.js @@ -0,0 +1,77 @@ +// Copyright (C) 2020 Intel Corporation +// +// SPDX-License-Identifier: MIT + +/// + +import { taskName, labelName, attrName } from '../../support/const'; + +context('Objects ordering feature', () => { + const caseId = '20'; + + const createRectangleShape2Points = { + points: 'By 2 Points', + type: 'Shape', + labelName: labelName, + firstX: 250, + firstY: 350, + secondX: 350, + secondY: 450, + }; + + const createRectangleShape2PointsSecond = { + points: 'By 2 Points', + type: 'Shape', + labelName: labelName, + firstX: createRectangleShape2Points.firstX + 300, + firstY: createRectangleShape2Points.firstY, + secondX: createRectangleShape2Points.secondX + 300, + secondY: createRectangleShape2Points.secondY, + }; + + function checkSideBarItemOrdering(ordering) { + let cvatObjectsSidebarStateItemIdList = []; + cy.get('.cvat-objects-sidebar-state-item').then(($cvatObjectsSidebarStateItemId) => { + for (let i = 0; i < $cvatObjectsSidebarStateItemId.length; i++) { + cvatObjectsSidebarStateItemIdList.push(Number($cvatObjectsSidebarStateItemId[i].id.match(/\d+$/))); + } + const idAscent = cvatObjectsSidebarStateItemIdList.reduce((previousValue, currentValue) => { + return previousValue > currentValue ? false : true; + }); + if (ordering === 'ascent') { + expect(idAscent).to.be.true; //expected true to be true (ascent) + } else { + expect(idAscent).to.be.false; //expected false to be false (descent) + } + }); + } + + before(() => { + cy.openTaskJob(taskName); + }); + + describe(`Testing case "${caseId}"`, () => { + it('Create a couple of shapes.', () => { + cy.createRectangle(createRectangleShape2Points); + cy.createRectangle(createRectangleShape2PointsSecond); + checkSideBarItemOrdering('ascent'); + }); + + it('Sort object by "ID - descent".', () => { + cy.sidebarItemSortBy('ID - descent'); + checkSideBarItemOrdering('descent'); + }); + it('Sort objects by "Updated time". Change something in the first object. This object now in the top', () => { + cy.sidebarItemSortBy('Updated time'); + cy.get('#cvat_canvas_shape_1').trigger('mousemove').rightclick(); + cy.get('.cvat-canvas-context-menu').within(() => { + cy.contains('.cvat-objects-sidebar-state-item-collapse', 'Details').click(); + cy.contains('.cvat-object-item-attribute-wrapper', attrName).within(() => { + cy.get('.cvat-object-item-text-attribute').clear(); + }); + }); + cy.get('.cvat-canvas-container').click(); // Hide context menu + checkSideBarItemOrdering('ascent'); + }); + }); +}); diff --git a/tests/cypress/support/commands.js b/tests/cypress/support/commands.js index ffd7ba42c828..9648b3336a2a 100644 --- a/tests/cypress/support/commands.js +++ b/tests/cypress/support/commands.js @@ -447,6 +447,14 @@ Cypress.Commands.add('createTag', (labelName) => { }); }); +Cypress.Commands.add('sidebarItemSortBy', (sortBy) => { + cy.get('.cvat-objects-sidebar-ordering-selector').click(); + cy.get('.ant-select-dropdown') + .not('.ant-select-dropdown-hidden') + .contains(new RegExp(`^${sortBy}$`, 'g')) + .click(); +}); + Cypress.Commands.add('goToRegisterPage', () => { cy.get('a[href="/auth/register"]').click(); cy.url().should('include', '/auth/register');