diff --git a/changelog.d/20240318_195644_mann.compi_labels_constructor_issue_5729.md b/changelog.d/20240318_195644_mann.compi_labels_constructor_issue_5729.md new file mode 100644 index 000000000000..bc854e55442f --- /dev/null +++ b/changelog.d/20240318_195644_mann.compi_labels_constructor_issue_5729.md @@ -0,0 +1,4 @@ +### Fixed + +- Label constructor validation of empty label names + () diff --git a/cvat-ui/src/components/labels-editor/label-form.tsx b/cvat-ui/src/components/labels-editor/label-form.tsx index 600dc11af72b..45e9f66bc92d 100644 --- a/cvat-ui/src/components/labels-editor/label-form.tsx +++ b/cvat-ui/src/components/labels-editor/label-form.tsx @@ -493,7 +493,7 @@ export default class LabelForm extends React.Component { name='name' rules={[ { - required: !!label, + required: true, message: 'Please specify a name', }, { @@ -503,7 +503,7 @@ export default class LabelForm extends React.Component { { validator: (_rule: any, labelName: string) => { if (labelNames.includes(labelName) && label?.name !== labelName) { - return Promise.reject(new Error('Label name must be unique for the task')); + return Promise.reject(new Error('Label name must be unique')); } return Promise.resolve(); }, diff --git a/tests/cypress/e2e/actions_tasks2/case_118_create_label_with_empty_label_name.js b/tests/cypress/e2e/actions_tasks2/case_118_create_label_with_empty_label_name.js new file mode 100644 index 000000000000..9c17b0434605 --- /dev/null +++ b/tests/cypress/e2e/actions_tasks2/case_118_create_label_with_empty_label_name.js @@ -0,0 +1,27 @@ +// Copyright (C) 2024 CVAT.ai Corporation +// +// SPDX-License-Identifier: MIT + +/// + +import { taskName } from '../../support/const'; + +context('Creating a label with an empty name.', () => { + const caseId = '118'; + + before(() => { + cy.openTask(taskName); + }); + + describe(`Testing case "${caseId}"`, () => { + it('Should display an error message if label name is empty', () => { + // Attempt to create a label with an empty name + cy.get('.cvat-constructor-viewer-new-item').click(); + cy.get('button[type="submit"]').click(); + + cy.contains('[role="alert"]', 'Please specify a name') + .should('exist') + .and('be.visible'); + }); + }); +}); diff --git a/tests/cypress/e2e/actions_tasks2/case_42_change_label_name_via_label_constructor.js b/tests/cypress/e2e/actions_tasks2/case_42_change_label_name_via_label_constructor.js index 731cf0fdc59c..88d355af28a8 100644 --- a/tests/cypress/e2e/actions_tasks2/case_42_change_label_name_via_label_constructor.js +++ b/tests/cypress/e2e/actions_tasks2/case_42_change_label_name_via_label_constructor.js @@ -21,8 +21,8 @@ context('Changing a label name via label constructor.', () => { it('Set empty label name. Press "Continue" button. Label name is not created. Label constructor is closed.', () => { cy.get('.cvat-constructor-viewer-new-item').click(); // Open label constructor cy.contains('[type="submit"]', 'Continue').click(); - cy.get('.cvat-label-constructor-creator').should('not.exist'); - cy.get('.cvat-constructor-viewer').should('be.visible'); + cy.contains('[role="alert"]', 'Please specify a name').should('exist').and('be.visible'); + cy.contains('[type="button"]', 'Cancel').click(); // Close label constructor }); it('Change label name to any other correct value. Press "Continue" button. The label created.', () => { diff --git a/tests/cypress/e2e/actions_tasks2/case_43_create_label_with_existing_label_name.js b/tests/cypress/e2e/actions_tasks2/case_43_create_label_with_existing_label_name.js index 2cfb60a7aa0e..7454bcb96cc2 100644 --- a/tests/cypress/e2e/actions_tasks2/case_43_create_label_with_existing_label_name.js +++ b/tests/cypress/e2e/actions_tasks2/case_43_create_label_with_existing_label_name.js @@ -24,7 +24,7 @@ context('Creating a label with existing label name.', () => { // Try to create a label with existing label name cy.get('.cvat-constructor-viewer-new-item').click(); cy.get('[placeholder="Label name"]').type(firstLabelName); - cy.contains('[role="alert"]', 'Label name must be unique for the task') // Checking alert visibility + cy.contains('[role="alert"]', 'Label name must be unique') // Checking alert visibility .should('exist') .and('be.visible'); }); diff --git a/tests/cypress/support/commands.js b/tests/cypress/support/commands.js index 385a23c7012e..b5a2b01d9339 100644 --- a/tests/cypress/support/commands.js +++ b/tests/cypress/support/commands.js @@ -1022,8 +1022,7 @@ Cypress.Commands.add('addNewSkeletonLabel', ({ name, points }) => { cy.contains('Continue').scrollIntoView(); cy.contains('Continue').click(); - cy.contains('Continue').scrollIntoView(); - cy.contains('Continue').click(); + cy.contains('Cancel').click(); }); });