From 5e14f61a642539d3af04ffe6af34cf8f962a0380 Mon Sep 17 00:00:00 2001 From: Dima May Date: Tue, 17 Dec 2024 16:46:55 +0000 Subject: [PATCH] #3031: do not repeat validation errors when switching destination subject --- .../subjects/CopySubjectOrSkillsDialog.vue | 2 +- .../copy_skills_to_another_project_spec.js | 43 +++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/dashboard/src/components/subjects/CopySubjectOrSkillsDialog.vue b/dashboard/src/components/subjects/CopySubjectOrSkillsDialog.vue index 321f22536..663c594f8 100644 --- a/dashboard/src/components/subjects/CopySubjectOrSkillsDialog.vue +++ b/dashboard/src/components/subjects/CopySubjectOrSkillsDialog.vue @@ -102,7 +102,6 @@ const endpointsProps = computed(() => { const onProjectChanged = (changedProj) => { if (changedProj != null) { - console.log(`onProjectChanged ${JSON.stringify(changedProj)}`) validationErrors.value = [] if (isSubjectCopy.value) { validatingOtherProj.value = true @@ -139,6 +138,7 @@ const selectedSubjectOrGroup = ref(null) const onSubjectOrGroupChanged = ((changedSubjOrGroup) => { if (changedSubjOrGroup) { validatingOtherProj.value = true + validationErrors.value = [] return SubjectsService.validateCopyItemsToAnotherProject(route.params.projectId, selectedProject.value.projectId, endpointsProps.value) .then((res) => { if (!res.isAllowed) { diff --git a/e2e-tests/cypress/e2e/copy/copy_skills_to_another_project_spec.js b/e2e-tests/cypress/e2e/copy/copy_skills_to_another_project_spec.js index 1c0a7e0ca..c07191c2b 100644 --- a/e2e-tests/cypress/e2e/copy/copy_skills_to_another_project_spec.js +++ b/e2e-tests/cypress/e2e/copy/copy_skills_to_another_project_spec.js @@ -322,6 +322,49 @@ describe('Copy skills from one project to another Tests', () => { cy.get('[data-cy="validationFailedMsg"]').should('not.exist') }); + it('validation errors are cleared and re-checked when the subject is changed', () => { + cy.createSkill(2, 1, 1); + cy.createSubject(2, 2) + cy.createProject(3) + cy.createSubject(3, 1) + + cy.visit('/administrator/projects/proj1/subjects/subj1'); + + cy.initiateSkillsCopyModal([0,1]) + // 1. select project + cy.get('[data-cy="selectAProjectDropdown"]').click(); + cy.get('[data-cy="projectSelector-projectName"]').contains('This is project 2').click(); + cy.get('[data-cy="saveDialogBtn"]').should('be.disabled'); + cy.get('[data-cy="validationPassedMsg"]').should('not.exist'); + // 2. select subject + cy.get('[data-cy="selectASubjectOrGroupDropdown"]').click(); + cy.get('[data-cy="subjOrGroupSelector-name"]').contains('Subject 1').click(); + cy.get('[data-cy="validationFailedMsg"]').contains('The following IDs already exist in the destination project: skill1.') + cy.get('[data-cy="validationFailedMsg"]').contains('The following names already exist in the destination project: Very Great Skill 1.') + // validate that error is not duplicated + cy.get('[data-cy="validationFailedMsg"]').invoke('text').then((text) => { + const occurrences = text.split('Very Great Skill 1').length - 1; + cy.wrap(occurrences).should('eq', 1); + }); + cy.get('[data-cy="saveDialogBtn"]').should('be.disabled'); + cy.get('[data-cy="closeDialogBtn"]').contains('Cancel') + cy.get('[data-cy="selectASubjectOrGroupDropdown"]').should('contain.text', 'Subject 1') + + // select subject a different subject + cy.get('[data-cy="selectASubjectOrGroupDropdown"]').click(); + cy.get('[data-cy="subjOrGroupSelector-name"]').contains('Subject 2').click(); + cy.get('[data-cy="validationFailedMsg"]').contains('The following IDs already exist in the destination project: skill1.') + cy.get('[data-cy="validationFailedMsg"]').contains('The following names already exist in the destination project: Very Great Skill 1.').should('have.length', 1) + // validate that error is not duplicated + cy.get('[data-cy="validationFailedMsg"]').invoke('text').then((text) => { + const occurrences = text.split('Very Great Skill 1').length - 1; + cy.wrap(occurrences).should('eq', 1); + }); + cy.get('[data-cy="saveDialogBtn"]').should('be.disabled'); + cy.get('[data-cy="closeDialogBtn"]').contains('Cancel') + cy.get('[data-cy="selectASubjectOrGroupDropdown"]').should('contain.text', 'Subject 2') + }); + it('cancelling dialog should return focus to the actions button', () => { cy.createSkill(1, 1, 3); cy.createSkill(1, 1, 4);