Skip to content

Commit

Permalink
Update Cypress test. Object make a copy. (cvat-ai#2739)
Browse files Browse the repository at this point in the history
* Update Cypress test. Make a copy for all object types.

* Some fix.

* Add make a copy for a tag.
  • Loading branch information
dvkruchinin authored and kenu committed Feb 23, 2021
1 parent ebc5fcb commit 28cb45d
Showing 1 changed file with 118 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2020 Intel Corporation
// Copyright (C) 2020-2021 Intel Corporation
//
// SPDX-License-Identifier: MIT

Expand All @@ -12,17 +12,57 @@ context('Object make a copy.', () => {
points: 'By 2 Points',
type: 'Shape',
labelName: labelName,
firstX: 400,
firstX: 100,
firstY: 100,
secondX: 500,
secondY: 200,
secondX: 150,
secondY: 150,
};
const createCuboidShape2Points = {
points: 'From rectangle',
type: 'Shape',
labelName: labelName,
firstX: 200,
firstY: 100,
secondX: 250,
secondY: 150,
};
const createPolygonShape = {
reDraw: false,
type: 'Shape',
labelName: labelName,
pointsMap: [
{ x: 300, y: 100 },
{ x: 350, y: 100 },
{ x: 350, y: 150 },
],
complete: true,
numberOfPoints: null,
};
const createPolylinesShape = {
type: 'Shape',
labelName: labelName,
pointsMap: [
{ x: 400, y: 100 },
{ x: 450, y: 100 },
{ x: 450, y: 150 },
],
complete: true,
numberOfPoints: null,
};
const createPointsShape = {
type: 'Shape',
labelName: labelName,
pointsMap: [{ x: 500, y: 100 }],
complete: true,
numberOfPoints: null,
};
const countObject = 5;

function checkObjectArrSize(expectedValue) {
function checkObjectArrSize(expectedValueShape, expectedValueSidebar) {
cy.get('.cvat_canvas_shape').then(($cvatCanvasShape) => {
cy.get('.cvat-objects-sidebar-state-item').then(($cvatObjectsSidebarStateItem) => {
expect($cvatCanvasShape.length).be.equal(expectedValue);
expect($cvatObjectsSidebarStateItem.length).be.equal(expectedValue);
expect($cvatCanvasShape.length).be.equal(expectedValueShape);
expect($cvatObjectsSidebarStateItem.length).be.equal(expectedValueSidebar);
});
});
}
Expand All @@ -47,42 +87,86 @@ context('Object make a copy.', () => {
before(() => {
cy.openTaskJob(taskName);
cy.createRectangle(rectangleShape2Points);
cy.createCuboid(createCuboidShape2Points);
cy.createPolygon(createPolygonShape);
cy.createPolyline(createPolylinesShape);
cy.createPoint(createPointsShape);
cy.createTag(labelName);
});

describe(`Testing case "${caseId}"`, () => {
it('Make a copy via sidebar.', () => {
cy.get('#cvat-objects-sidebar-state-item-1').within(() => {
cy.get('[aria-label="more"]').trigger('mouseover');
});
cy.get('.cvat-object-item-menu').within(() => {
cy.contains('button', 'Make a copy').click();
});
cy.get('.cvat-canvas-container').click();
let coordX = 100;
let coordY = 300;
for (let id = 1; id < countObject + 2; id++) {
cy.get(`#cvat-objects-sidebar-state-item-${id}`).within(() => {
cy.get('[aria-label="more"]').trigger('mouseover').wait(300); // Wait dropdown menu transition
});
cy.get('.cvat-object-item-menu').last().should('be.visible').contains('button', 'Make a copy').click(); // Get the tast element from cvat-object-item-menu array
cy.get('.cvat-canvas-container').click(coordX, coordY);
cy.get('.cvat-canvas-container').click();
coordX += 100;
}
});

it('Object attributes are the same.', () => {
checkObjectArrSize(2);
compareObjectsAttr('#cvat_canvas_shape_1', '#cvat_canvas_shape_2');
compareObjectsSidebarAttr('#cvat-objects-sidebar-state-item-1', '#cvat-objects-sidebar-state-item-2');
it('After copying via sidebar, the attributes of the objects are the same.', () => {
checkObjectArrSize(10, 12);
for (let id = 1; id < countObject; id++) {
compareObjectsAttr(`#cvat_canvas_shape_${id}`, `#cvat_canvas_shape_${id + countObject + 1}`); // Parameters id 1 equal patameters id 7, 2 to 8, etc.
}
for (let idSidebar = 1; idSidebar < 7; idSidebar++) {
compareObjectsSidebarAttr(
`#cvat-objects-sidebar-state-item-${idSidebar}`,
`#cvat-objects-sidebar-state-item-${idSidebar + countObject + 1}`,
); // Parameters sidebar id 1 equal patameters sidebar id 7, 2 to 8, etc.
}
});

it('Make a copy via object context menu.', () => {
cy.get('#cvat_canvas_shape_1')
.trigger('mousemove')
.should('have.class', 'cvat_canvas_shape_activated')
.rightclick();
cy.get('.cvat-canvas-context-menu').within(() => {
cy.get('[aria-label="more"]').trigger('mouseover');
});
cy.get('.cvat-object-item-menu').contains('button', 'Make a copy').click({ force: true });
cy.get('.cvat-canvas-container').click(500, 500);
cy.get('.cvat-canvas-container').click(300, 500); //deactivate all objects and hide context menu
// Disabled part of the test for the Firefox browser due to possible problems positioning the element and completing the trigger() construct for moving the mouse cursor over the element.
it('Make a copy via object context menu.', { browser: '!firefox' }, () => {
let coordX = 100;
let coordY = 400;
for (let id = 1; id < countObject; id++) {
// Point doesn't have a context menu
if (id === 4) {
cy.get(`#cvat_canvas_shape_${id}`)
.trigger('mousemove', 'right')
.should('have.class', 'cvat_canvas_shape_activated')
.rightclick('right'); // When click in the center of polyline: is being covered by another element: <svg xmlns="http://www.w3.org/2000/svg" ...
} else {
cy.get(`#cvat_canvas_shape_${id}`)
.trigger('mousemove')
.should('have.class', 'cvat_canvas_shape_activated')
.rightclick();
}
cy.get('.cvat-canvas-context-menu')
.last()
.should('be.visible')
.find('[aria-label="more"]')
.trigger('mouseover')
.wait(300); // Wait dropdown menu transition;
cy.get('.cvat-object-item-menu').last().should('be.visible').contains('button', 'Make a copy').click(); // Get the tast element from cvat-object-item-menu array
cy.get('.cvat-canvas-container').click(coordX, coordY);
cy.get('.cvat-canvas-container').click(); // Deactivate all objects and hide context menu
coordX += 100;
}
});

it('Attributes of objects 1 and 3 are the same.', () => {
checkObjectArrSize(3);
compareObjectsAttr('#cvat_canvas_shape_1', '#cvat_canvas_shape_3');
compareObjectsSidebarAttr('#cvat-objects-sidebar-state-item-1', '#cvat-objects-sidebar-state-item-3');
});
it(
'After copying via object context menu, the attributes of the objects are the same.',
{ browser: '!firefox' },
() => {
checkObjectArrSize(14, 16); // The point and tag was not copied via the object's context menu
for (let id = 1; id < countObject; id++) {
compareObjectsAttr(`#cvat_canvas_shape_${id}`, `#cvat_canvas_shape_${id + countObject + 7}`); // Parameters id 1 equal patameters id 13, 2 to 14, etc.
}
for (let idSidebar = 1; idSidebar < 6; idSidebar++) {
compareObjectsSidebarAttr(
`#cvat-objects-sidebar-state-item-${idSidebar}`,
`#cvat-objects-sidebar-state-item-${idSidebar + countObject + 6}`,
); // Parameters sidebar id 1 equal patameters sidebar id 13, 2 to 14, etc.
}
},
);
});
});

0 comments on commit 28cb45d

Please sign in to comment.