Skip to content

Commit

Permalink
Merge pull request #3047 from NationalSecurityAgency/t#3031/validatio…
Browse files Browse the repository at this point in the history
…n_fix

#3031: do not repeat validation errors when switching destination sub…
  • Loading branch information
rmmayo authored Dec 17, 2024
2 parents 32292f1 + 5e14f61 commit 3468922
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
43 changes: 43 additions & 0 deletions e2e-tests/cypress/e2e/copy/copy_skills_to_another_project_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 3468922

Please sign in to comment.