Skip to content

Commit

Permalink
fix(test): fix frontend test on field mapping with the modification o…
Browse files Browse the repository at this point in the history
…n the public mapping update
  • Loading branch information
jacquesfize committed Jan 8, 2025
1 parent f289896 commit d48e13c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 16 deletions.
23 changes: 21 additions & 2 deletions frontend/cypress/e2e/import/step3-field-mapping-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,17 @@ function restartTheProcess(user) {
runTheProcess(user);
}

function checkThatMappingCanBeSaved() {
// Trigger the modal
cy.get(SELECTOR_IMPORT_FIELDMAPPING_VALIDATE).should('exist').should('be.enabled').click();

// Validation modal appear
cy.get(SELECTOR_IMPORT_FIELDMAPPING_MODAL_OK, { force: true }).should('exist');

// Close the modal
cy.get(SELECTOR_IMPORT_FIELDMAPPING_MODAL_CLOSE, { force: true }).click();
}

function checkThatMappingCanNotBeSaved() {
// Trigger the modal
cy.get(SELECTOR_IMPORT_FIELDMAPPING_VALIDATE).should('exist').should('be.enabled').click();
Expand Down Expand Up @@ -303,15 +314,23 @@ describe('Import - Field mapping step', () => {
deleteCurrentMapping();
});

it('Should not be able to modifiy the default mapping. A save to alternative should be offered to the user.', () => {
it('Should be able to modifiy the default mapping if user got rights. A save to alternative should be offered to the user.', () => {
// Mapping Synthese
selectMapping(DEFAULT_FIELDMAPPINGS[0]);
selectField(SELECTOR_IMPORT_FIELDMAPPING_DATE_MIN, 'date_fin');
checkThatMappingCanNotBeSaved();
checkThatMappingCanBeSaved();

restartTheProcess(USER_ADMIN);
selectMapping(DEFAULT_FIELDMAPPINGS[1]);
fillTheFormRaw();
checkThatMappingCanBeSaved();
});
it('Should not be able to modifiy the default mapping if user does not got rights', () => {
cy.geonatureLogout();
cy.geonatureLogin(USER_AGENT.login.username, USER_AGENT.login.password);
runTheProcess(USER_AGENT);
selectMapping(DEFAULT_FIELDMAPPINGS[0]);
selectField(SELECTOR_IMPORT_FIELDMAPPING_DATE_MIN, 'date_fin');
checkThatMappingCanNotBeSaved();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,22 +107,28 @@ export class FieldsMappingStepComponent implements OnInit {
//
const currentUser = this._authService.getCurrentUser();

if (this._fieldMappingService.mappingFormGroup.dirty && mappingValue && this.cruved.C) {
const intersectMappingOwnerUser = mappingValue['owners'].filter((x) =>
x.identifiant == currentUser.user_login ? mappingValue['owners'] : false
);
if (
mappingValue.public &&
(hasAdminUpdateMappingRight || (hasOwnMappingUpdateRight && intersectMappingOwnerUser))
) {
this.updateAvailable = true;
this.modalCreateMappingForm.setValue(mappingValue.label);
} else if (!mappingValue.public) {
this.updateAvailable = true;
this.modalCreateMappingForm.setValue(mappingValue.label);
if (this._fieldMappingService.mappingFormGroup.dirty && this.cruved.C) {
if (mappingValue) {
const intersectMappingOwnerUser = mappingValue['owners'].filter((x) =>
x.identifiant == currentUser.user_login ? mappingValue['owners'] : false
);

if (
mappingValue.public &&
(hasAdminUpdateMappingRight ||
(hasOwnMappingUpdateRight && intersectMappingOwnerUser.length > 0))
) {
this.updateAvailable = true;
this.modalCreateMappingForm.setValue(mappingValue.label);
} else if (!mappingValue.public) {
this.updateAvailable = true;
this.modalCreateMappingForm.setValue(mappingValue.label);
} else {
this.updateAvailable = false;
}
} else {
console.log(4);
this.updateAvailable = false;
this.modalCreateMappingForm.setValue('');
}
this._modalService.open(this.saveMappingModal, { size: 'lg' });
} else {
Expand Down

0 comments on commit d48e13c

Please sign in to comment.