Skip to content

Commit

Permalink
Merge pull request #2526 from DmitriyOparin/upstream/do/cypress_test_…
Browse files Browse the repository at this point in the history
…case_24_delete_unlock_lock_object

Cypress test. Delete unlock and lock object.
  • Loading branch information
Boris Sekachev committed Dec 7, 2020
2 parents b09d4e0 + ac58b36 commit be93804
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cvat-ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cvat-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cvat-ui",
"version": "1.11.5",
"version": "1.11.6",
"description": "CVAT single-page application",
"main": "src/index.tsx",
"scripts": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ function RemoveItem(props: ItemProps): JSX.Element {
onClick={(): void => {
if (locked) {
Modal.confirm({
className: 'cvat-modal-confirm',
title: 'Object is locked',
content: 'Are you sure you want to remove it?',
onOk() {
Expand Down
6 changes: 4 additions & 2 deletions cvat-ui/src/components/cvat-app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,11 @@ class CVATApplication extends React.PureComponent<CVATAppProps & RouteComponentP
}

private showErrors(): void {
function showError(title: string, _error: any): void {
function showError(title: string, _error: any, className?: string): void {
const error = _error.toString();
const dynamicProps = typeof className === 'undefined' ? {} : { className };
notification.error({
...dynamicProps,
message: (
<div
// eslint-disable-next-line
Expand All @@ -214,7 +216,7 @@ class CVATApplication extends React.PureComponent<CVATAppProps & RouteComponentP
const error = (notifications as any).errors[where][what];
shown = shown || !!error;
if (error) {
showError(error.message, error.reason);
showError(error.message, error.reason, error.className);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions cvat-ui/src/reducers/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ export interface ModelsState {
export interface ErrorState {
message: string;
reason: string;
className?: string;
}

export interface NotificationsState {
Expand Down
1 change: 1 addition & 0 deletions cvat-ui/src/reducers/notifications-reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,7 @@ export default function (state = defaultState, action: AnyAction): Notifications
removing: {
message: 'Could not remove the object',
reason: action.payload.error.toString(),
className: 'cvat-notification-notice-remove-object-failed',
},
},
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
// Copyright (C) 2020 Intel Corporation
//
// SPDX-License-Identifier: MIT

/// <reference types="cypress" />

import { taskName, labelName } from '../../support/const';

context('Delete unlock/lock object', () => {
const caseId = '24';

const createRectangleShape2Points = {
points: 'By 2 Points',
type: 'Shape',
labelName: labelName,
firstX: 100,
firstY: 100,
secondX: 300,
secondY: 300,
};

function lockObject() {
cy.get('.cvat-objects-sidebar-state-item').within(() => {
cy.get('.cvat-object-item-button-lock').click();
});
};

function deleteObjectViaShortcut(shortcut, stateLockObject) {
if (stateLockObject == 'unlock') {
cy.get('.cvat-canvas-container').within(() => {
cy.get('.cvat_canvas_shape')
.trigger('mousemove')
.should('have.class', 'cvat_canvas_shape_activated');
});
};
cy.get('body')
.type(shortcut);
};

function clickRemoveOnDropdownMenu() {
cy.get('.cvat-object-item-menu')
.contains(new RegExp('^Remove$', 'g'))
.click({ force: true });
};

function deleteObjectViaGUIFromSidebar() {
cy.get('.cvat-objects-sidebar-states-list').within(() => {
cy.get('.cvat-objects-sidebar-state-item').within(() => {
cy.get('[aria-label="icon: more"]').click();
});
});
clickRemoveOnDropdownMenu();
};

function deleteObjectViaGUIFromObject() {
cy.get('.cvat-canvas-container').within(() => {
cy.get('.cvat_canvas_shape')
.trigger('mousemove')
.rightclick();
});
cy.get('.cvat-canvas-context-menu').within(() => {
cy.get('.cvat-objects-sidebar-state-item').within(() => {
cy.get('[aria-label="icon: more"]').click();
});
});
clickRemoveOnDropdownMenu();
};

function actionOnConfirmWindow(textBuntton) {
cy.get('.cvat-modal-confirm').within(() => {
cy.contains(new RegExp(`^${textBuntton}$`, 'g'))
.click();
});
};

function checkFailDeleteLockObject(shortcut) {
deleteObjectViaShortcut(shortcut, 'lock');
checkExistObject('exist');
cy.get('.cvat-notification-notice-remove-object-failed').should('exist');
};

function checkExistObject(state) {
cy.get('.cvat_canvas_shape').should(state);
cy.get('.cvat-objects-sidebar-state-item').should(state);
};

before(() => {
cy.openTaskJob(taskName);
});

describe(`Testing case "${caseId}"`, () => {
it('Create and delete object via "Delete" shortcut', () => {
cy.createRectangle(createRectangleShape2Points);
deleteObjectViaShortcut('{del}', 'unlock');
checkExistObject('not.exist');
});

it('Create and delete object via GUI from sidebar', () => {
cy.createRectangle(createRectangleShape2Points);
deleteObjectViaGUIFromSidebar();
checkExistObject('not.exist');
});

it('Create, lock and delete object via "Shift+Delete" shortcuts', () => {
cy.createRectangle(createRectangleShape2Points);
lockObject();
checkFailDeleteLockObject('{del}');
deleteObjectViaShortcut('{shift}{del}', 'lock');
checkExistObject('not.exist');
});

it('Create, lock and delete object via GUI from sidebar', () => {
cy.createRectangle(createRectangleShape2Points);
lockObject();
deleteObjectViaGUIFromSidebar();
actionOnConfirmWindow('OK');
checkExistObject('not.exist');
});

it('Create, lock and cancel delete object via GUI from object', () => {
cy.createRectangle(createRectangleShape2Points);
lockObject();
deleteObjectViaGUIFromObject();
actionOnConfirmWindow('Cancel');
checkExistObject('exist');
});
});
});

0 comments on commit be93804

Please sign in to comment.