Skip to content

Commit

Permalink
test: update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
edelclaux committed Jan 21, 2025
1 parent 962e3a3 commit 3878e07
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 68 deletions.
3 changes: 2 additions & 1 deletion frontend/cypress/e2e/import/constants/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ export const SELECTOR_IMPORT_FIELDMAPPING_OBSERVERS =
export const SELECTOR_IMPORT_FIELDMAPPING_NOM_CITE = '[data-qa=import-fieldmapping-theme-nom_cite]';
export const SELECTOR_IMPORT_FIELDMAPPING_WKT = '[data-qa=import-fieldmapping-theme-WKT]';
export const SELECTOR_IMPORT_FIELDMAPPING_CD_NOM = '[data-qa=import-fieldmapping-theme-cd_nom]';
export const SELECTOR_IMPORT_FIELDMAPPING_DATASET =
'[data-qa=import-fieldmapping-theme-unique_dataset_id]';
export const SELECTOR_IMPORT_FIELDMAPPING_VALIDATE =
'[data-qa=import-new-fieldmapping-model-validate]';
export const SELECTOR_IMPORT_FIELDMAPPING_BUTTON_DELETE =
Expand Down Expand Up @@ -88,7 +90,6 @@ export const SELECTOR_IMPORT_LIST_TOOLBAR_DESTINATIONS =
export const SELECTOR_IMPORT_LIST_TOOLBAR_SEARCH = '[data-qa=import-list-toolbar-search]';
export const SELECTOR_DESTINATIONS = '[data-qa=destinations]';
export const SELECTOR_IMPORT = '[data-qa=gn-sidenav-link-IMPORT]';
export const SELECTOR_IMPORT_UPLOAD_DATASET = '[data-qa=import-new-upload-datasets]';
export const SELECTOR_IMPORT_UPLOAD_FILE = '[data-qa=import-new-upload-file]';
export const SELECTOR_IMPORT_UPLOAD_VALIDATE = '[data-qa=import-new-upload-validate]';
export const SELECTOR_IMPORT_CONTENTMAPPING_STEP_BUTTON =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,9 @@ describe('Tests actions on active/inactive list JDD ', () => {
it('Should be able to modify a finished import, but still active JDD', () => {
cy.startImport();
cy.pickDestination();
cy.pickDataset(user.dataset);
cy.loadImportFile(FILES.synthese.valid.fixture);
cy.configureImportFile();
cy.configureImportFieldMapping();
cy.configureImportFieldMapping(user.dataset);
cy.configureImportContentMapping();
cy.verifyImport();
cy.executeImport();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ describe('Import Process Navigation', () => {
cy.pickDestination(DESTINATION);

// STEP 1 - UPLOAD
cy.pickDataset(FIELDS_CONTENT_STEP_UPLOAD.datasetField.defaultValue);
cy.loadImportFile(FIELDS_CONTENT_STEP_UPLOAD.fileUploadField.defaultValue);
cy.wait(TIMEOUT_WAIT);
cy.url().then((url) => {
Expand Down Expand Up @@ -119,7 +118,6 @@ describe('Import Process Navigation', () => {
expect(defaultValue).to.include(expectedValue);
});
// Change values in upload step
cy.pickDataset(FIELDS_CONTENT_STEP_UPLOAD.datasetField.newValue);
cy.loadImportFile(FIELDS_CONTENT_STEP_UPLOAD.fileUploadField.newValue);
cy.get(SELECTOR_NAVIGATION_STEP_DECODE_FILE.back_btn_selector)
.should('be.visible')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
getSelectorImportListTableRowId,
SELECTOR_IMPORT_CONTENTMAPPING_STEP_BUTTON,
SELECTOR_IMPORT_FIELDMAPPING_CD_NOM,
SELECTOR_IMPORT_FIELDMAPPING_DATASET,
SELECTOR_IMPORT_FIELDMAPPING_DATE_MIN,
SELECTOR_IMPORT_FIELDMAPPING_NOM_CITE,
SELECTOR_IMPORT_FIELDMAPPING_OBSERVERS,
Expand All @@ -22,14 +23,13 @@ function runTheProcessUntilFieldMapping(user) {
cy.visitImport();
cy.startImport();
cy.pickDestination();
cy.pickDataset(user.dataset);
cy.loadImportFile(FILES.synthese.valid.fixture);
cy.configureImportFile();
}

function runTheProcessUntilContentMapping(user) {
runTheProcessUntilFieldMapping(user);
cy.configureImportFieldMapping();
cy.configureImportFieldMapping(user.dataset);
cy.wait(500);
}

Expand Down Expand Up @@ -67,14 +67,14 @@ function selectContentMappingField(dataQa, value) {
cy.get(`[data-qa=import-contentmapping-theme-${dataQa}]`).should('exist').select(value);
}

function fillTheFieldMappingFormRaw() {
function fillTheFieldMappingFormRaw(datasetName) {
selectFieldMappingField(SELECTOR_IMPORT_FIELDMAPPING_DATE_MIN, 'date_debut');
selectFieldMappingField(SELECTOR_IMPORT_FIELDMAPPING_OBSERVERS, 'date_debut');
selectFieldMappingField(SELECTOR_IMPORT_FIELDMAPPING_NOM_CITE, 'date_debut');
selectFieldMappingField(SELECTOR_IMPORT_FIELDMAPPING_WKT, 'date_debut');
selectFieldMappingField(SELECTOR_IMPORT_FIELDMAPPING_CD_NOM, 'date_debut');
selectFieldMappingField(SELECTOR_IMPORT_FIELDMAPPING_DATASET, datasetName);
}

// ////////////////////////////////////////////////////////////////////////////
// Create a mapping with dummy values
// ////////////////////////////////////////////////////////////////////////////
Expand All @@ -97,7 +97,7 @@ describe('Navigation - cancel and save', () => {
const parts = url.split('/');
const importID = parts[parts.length - 2]; // Get the penultimate element

fillTheFieldMappingFormRaw();
fillTheFieldMappingFormRaw(user.dataset);
cy.get(SELECTOR_IMPORT_FOOTER_DELETE).should('be.enabled').click();
cy.wait(TIMEOUT_WAIT);
cy.checkCurrentPageIsImport();
Expand All @@ -112,7 +112,7 @@ describe('Navigation - cancel and save', () => {
const parts = url.split('/');
const importID = parts[parts.length - 2]; // Get the penultimate element

fillTheFieldMappingFormRaw();
fillTheFieldMappingFormRaw(user.dataset);
cy.visitImport();
checkImportIsFirstInList(importID);
clickOnFirstLineEdit();
Expand All @@ -133,7 +133,7 @@ describe('Navigation - cancel and save', () => {
// Extract the ID using string manipulation
const parts = url.split('/');
const importID = parts[parts.length - 2]; // Get the penultimate element
fillTheFieldMappingFormRaw();
fillTheFieldMappingFormRaw(user.dataset);
cy.get(SELECTOR_IMPORT_FOOTER_SAVE).should('be.enabled').click();
checkImportIsFirstInList(importID);
clickOnFirstLineEdit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ describe('Import - create a new import', () => {
it('Should be able to import a valid-file in synthese', () => {
cy.startImport();
cy.pickDestination();
cy.pickDataset(USER.dataset);
cy.loadImportFile(FILES.synthese.valid.fixture);
cy.configureImportFile();
cy.configureImportFieldMapping();
cy.configureImportFieldMapping(USER.dataset);
cy.configureImportContentMapping();
cy.verifyImport();
cy.executeImport();
Expand Down
32 changes: 0 additions & 32 deletions frontend/cypress/e2e/import/step1-upload-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { USERS } from './constants/users';
import { VIEWPORTS } from './constants/common';
import { FILES } from './constants/files';
import {
SELECTOR_IMPORT_UPLOAD_DATASET,
SELECTOR_IMPORT_UPLOAD_FILE,
SELECTOR_IMPORT_UPLOAD_VALIDATE,
} from './constants/selectors';
Expand All @@ -29,38 +28,8 @@ describe('Import - Upload step', () => {
cy.get(SELECTOR_IMPORT_UPLOAD_VALIDATE).should('exist').should('be.disabled');
});

it('Should be able to select a jdd', () => {
cy.pickDataset(USER.dataset);
cy.get(`${SELECTOR_IMPORT_UPLOAD_DATASET} > ng-select`)
.should('have.class', 'ng-valid')
.find('.ng-value-label')
.should('exist')
.should('contains.text', USER.dataset);

cy.get(SELECTOR_IMPORT_UPLOAD_DATASET).find('.ng-clear-wrapper').should('exist').click();

cy.get(`${SELECTOR_IMPORT_UPLOAD_DATASET} > ng-select`).should('have.class', 'ng-invalid');

cy.pickDataset(USER.dataset);

cy.get(`${SELECTOR_IMPORT_UPLOAD_DATASET} > ng-select`)
.should('have.class', 'ng-valid')
.find('.ng-value-label')
.should('exist')
.should('contains.text', USER.dataset);
});

it('Should access jdd only filtered based on permissions ', () => {
cy.get(`${SELECTOR_IMPORT_UPLOAD_DATASET} > ng-select`)
.click()
.get('.ng-option')
.should('have.length', 1)
.should('contain', USER.dataset);
});

it('Should throw error if file is empty', () => {
// required to trigger file validation
cy.pickDataset(USER.dataset);
const file = FILES.synthese.empty;
cy.get(file.formErrorElement).should('not.exist');
cy.loadImportFile(file.fixture);
Expand All @@ -70,7 +39,6 @@ describe('Import - Upload step', () => {

it('Should throw error if csv is not valid', () => {
// required to trigger file validation
cy.pickDataset(USER.dataset);
const file = FILES.synthese.bad;
cy.get(file.formErrorElement).should('not.exist');
cy.fixture(file.fixture, null).as('import_file');
Expand Down
24 changes: 23 additions & 1 deletion frontend/cypress/e2e/import/step3-field-mapping-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
SELECTOR_IMPORT_FIELDMAPPING_BUTTON_DELETE,
SELECTOR_IMPORT_FIELDMAPPING_BUTTON_DELETE_OK,
SELECTOR_IMPORT_FIELDMAPPING_CD_NOM,
SELECTOR_IMPORT_FIELDMAPPING_DATASET,
SELECTOR_IMPORT_FIELDMAPPING_DATE_MIN,
SELECTOR_IMPORT_FIELDMAPPING_MODAL,
SELECTOR_IMPORT_FIELDMAPPING_MODAL_CLOSE,
Expand Down Expand Up @@ -66,6 +67,18 @@ function deleteCurrentMapping() {
cy.wait(TIMEOUT_WAIT);
}

function pickDataset(datasetName) {
cy.get(SELECTOR_IMPORT_FIELDMAPPING_DATASET)
.should('exist')
.click()
.get('ng-dropdown-panel')
.get('.ng-option')
.contains(datasetName)
.then((dataset) => {
cy.wrap(dataset).should('exist').click();
});
}

// ////////////////////////////////////////////////////////////////////////////
// Create a mapping with dummy values
// ////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -96,6 +109,8 @@ function fillTheForm() {

selectField(SELECTOR_IMPORT_FIELDMAPPING_CD_NOM, 'date_debut');

pickDataset(user.dataset);

// Every mandatory field is filled: should be able to validate
cy.get(SELECTOR_IMPORT_FIELDMAPPING_VALIDATE).should('exist').should('be.enabled').click();

Expand All @@ -117,7 +132,6 @@ function runTheProcess(user) {
cy.visitImport();
cy.startImport();
cy.pickDestination();
cy.pickDataset(user.dataset);
cy.loadImportFile(FILES.synthese.valid.fixture);
cy.configureImportFile();
}
Expand Down Expand Up @@ -173,6 +187,14 @@ describe('Import - Field mapping step', () => {
cy.get('[data-qa="import-new-fieldmapping-form"]').should('exist');
});

it('Should access jdd only filtered based on permissions ', () => {
cy.get(`${SELECTOR_IMPORT_UPLOAD_DATASET} > ng-select`)
.click()
.get('.ng-option')
.should('have.length', 1)
.should('contain', USER.dataset);
});

it('Should be able to create a new field mapping, rename it, and delete it', () => {
fillTheForm();
restartTheProcess(USER_ADMIN);
Expand Down
7 changes: 3 additions & 4 deletions frontend/cypress/e2e/import/step4-content-mapping-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,25 +114,24 @@ function runTheProcess(user) {
cy.visitImport();
cy.startImport();
cy.pickDestination();
cy.pickDataset(user.dataset);
cy.loadImportFile(FILES.synthese.valid.fixture);
cy.configureImportFile();
cy.configureImportFieldMapping();
cy.configureImportFieldMapping(user.dataset);
}

function runTheProcessForOcchab(user) {
cy.visitImport();
cy.startImport();
cy.pickDestination('Occhab');
cy.pickDataset(user.dataset);
cy.loadImportFile(FILES.synthese.valid.fixture);
cy.configureImportFile();
// cy.configureImportFieldMapping();
// cy.configureImportFieldMapping(user.dataset);
selectFieldMappingField('import-fieldmapping-theme-date_min', 'error');
selectFieldMappingField('import-fieldmapping-theme-WKT', 'error');
cy.get('#mat-tab-label-0-1').click();
selectFieldMappingField('import-fieldmapping-theme-nom_cite', 'error');
selectFieldMappingField('import-fieldmapping-theme-cd_hab', 'error');
selectFieldMappingField('import-fieldmapping-theme-unique_dataset_id', 'error');

cy.get('[data-qa="import-new-fieldmapping-model-validate"]').click();
cy.get('[data-qa="import-fieldmapping-saving-modal-cancel"]', { force: true }).click();
Expand Down
3 changes: 1 addition & 2 deletions frontend/cypress/e2e/import/step5-recaptiulatif-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ function runTheProcess(user) {
cy.visitImport();
cy.startImport();
cy.pickDestination();
cy.pickDataset(user.dataset);
cy.loadImportFile(FILES.synthese.valid.fixture);
cy.configureImportFile();
cy.configureImportFieldMapping();
cy.configureImportFieldMapping(user.dataset);
cy.configureImportContentMapping();
cy.triggerImportVerification();
}
Expand Down
3 changes: 1 addition & 2 deletions frontend/cypress/e2e/import/step6-report-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ function runTheProcess(user) {
cy.visitImport();
cy.startImport();
cy.pickDestination();
cy.pickDataset(user.dataset);
cy.loadImportFile(FILES.synthese.valid.fixture);
cy.configureImportFile();
cy.configureImportFieldMapping();
cy.configureImportFieldMapping(user.dataset);
cy.configureImportContentMapping();
cy.triggerImportVerification();
cy.executeImport();
Expand Down
13 changes: 12 additions & 1 deletion frontend/cypress/support/import/configureImportFieldMapping.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const DEFAULT_MAPPING = 'Synthese GeoNature';
const DEFAULT_DATASET = '';

Cypress.Commands.add('configureImportFieldMapping', () => {
Cypress.Commands.add('configureImportFieldMapping', (datasetName) => {
cy.get('[data-qa="import-fieldmapping-selection-select"]')
.should('exist')
.click()
Expand All @@ -11,6 +12,16 @@ Cypress.Commands.add('configureImportFieldMapping', () => {
cy.wrap(v).should('exist').click();
});

cy.get('[data-qa="import-fieldmapping-theme-unique_dataset_id"]')
.should('exist')
.click()
.get('ng-dropdown-panel')
.get('.ng-option')
.contains(datasetName)
.then((dataset) => {
cy.wrap(dataset).should('exist').click();
});

// Every mandatory field is filled: should be able to validate
cy.get('[data-qa="import-new-fieldmapping-model-validate"]')
.should('exist')
Expand Down
1 change: 0 additions & 1 deletion frontend/cypress/support/import/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import './getGlobalConfig';
import './getRowIndexByCellValue';
import './hasToastError';
import './loadImportFile';
import './pickDataset';
import './pickDestination';
import './removeFirstImportInList';
import './startImport';
Expand Down
11 changes: 0 additions & 11 deletions frontend/cypress/support/import/pickDataset.js

This file was deleted.

0 comments on commit 3878e07

Please sign in to comment.