From 554881cfca645567d0791200c610782bea36db79 Mon Sep 17 00:00:00 2001 From: Andria Capai Date: Fri, 13 Dec 2024 19:03:07 +0100 Subject: [PATCH] feat(test): test frontend for context params url - Synthese test frontend (ok) - wip : make occhab condition and refact test Reviewed-by: andriacap --- ...ldmapping-context-from-destination-spec.js | 106 ++++++++++++++++++ .../dynamic-form/dynamic-form.component.html | 18 +++ .../dynamic-form/dynamic-form.component.ts | 1 + .../fields-mapping-step.component.html | 5 +- .../mapping-theme.component.html | 2 + 5 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 frontend/cypress/e2e/import/fieldmapping-context-from-destination-spec.js diff --git a/frontend/cypress/e2e/import/fieldmapping-context-from-destination-spec.js b/frontend/cypress/e2e/import/fieldmapping-context-from-destination-spec.js new file mode 100644 index 0000000000..75a51a337b --- /dev/null +++ b/frontend/cypress/e2e/import/fieldmapping-context-from-destination-spec.js @@ -0,0 +1,106 @@ +import { USERS } from './constants/users'; +import { TIMEOUT_WAIT, VIEWPORTS } from './constants/common'; +import { FILES } from './constants/files'; + +const USER = USERS[0]; +const VIEWPORT = VIEWPORTS[0]; + +function testQueryParamField(dataQa, paramName, expectedValue, fieldType) { + if (fieldType === 'textarea' || fieldType === 'text' || fieldType === 'number') { + cy.get(dataQa) + .find(`[data-qa^="field-${fieldType}-${paramName}_default_value_"]`) + .should('have.value', expectedValue); + } +} + +const paramsByDestination = [ + { + destination: 'synthese', + queryParams: [ + { + paramsName: 'nom_cite', + paramsValue: 'test_nomcite', + fieldType: 'textarea', + isTypeComp: false, + expectedValue: 'test_nomcite', + }, + { + paramsName: 'altitude_max', + paramsValue: 10, + fieldType: 'number', + isTypeComp: false, + expectedValue: 10, + }, + { + paramsName: 'date_min', + paramsValue: '2024-12-12', + fieldParentType: 'field-date', + fieldType: 'date', + isTypeComp: true, + expectedValue: '12/12/2024', + }, + { + paramsName: 'id_nomenclature_geo_object_nature', + paramsValue: 'Inventoriel', + fieldParentType: 'field-nomenclature', + fieldType: 'nomenclature', + isTypeComp: true, + expectedValue: 'Inventoriel', + }, + ], + }, + // { + // destination: 'occhab', + // queryParams: [ + // { paramsName: 'nom_cite', paramsValue: 'test_nomcite' }, + // { paramsName: 'date_min', paramsValue: '2024-12-12' }, + // ], + // }, +]; + +describe('Import - Upload step', () => { + context(`viewport: ${VIEWPORT.width}x${VIEWPORT.height}`, () => { + beforeEach(() => { + cy.viewport(VIEWPORT.width, VIEWPORT.height); + cy.geonatureLogin(USER.login.username, USER.login.password); + cy.wait(TIMEOUT_WAIT); + }); + + paramsByDestination.forEach(({ destination, queryParams }) => { + it(`Should handle for destination: ${destination}`, () => { + const urlParams = queryParams + .map((param) => `${param.paramsName}=${param.paramsValue}`) + .join('&'); + cy.visit(`/#/import/${destination}/process/upload?${urlParams}`); + + cy.pickDataset(USER.dataset); + cy.loadImportFile(FILES.synthese.valid.fixture); + cy.configureImportFile(); + + queryParams.forEach(({ paramsName, paramsValue, fieldType, isTypeComp, expectedValue }) => { + let dataQa = `[data-qa="import-fieldmapping-theme-${paramsName}"]`; + + // Récupérer et vérifier la valeur en fonction du type de champ + if (!isTypeComp) { + testQueryParamField(dataQa, paramsName, expectedValue, fieldType); + } else if (fieldType === 'date' || fieldType === 'nomenclature') { + // Si c'est un champ de type 'date' ou 'nomenclature' + dataQa = `[data-qa="field-${fieldType}-${paramsName}_default_value"]`; + cy.get(dataQa) + .find(`input`) + .each(($el) => cy.wrap($el).scrollIntoView().should('be.visible')); + + if (fieldType === 'date') { + cy.get(dataQa).find('[data-qa="input-date"]').should('have.value', expectedValue); + } else if (fieldType === 'nomenclature') { + cy.get(`${dataQa} .ng-value-container .ng-value-label`).should( + 'have.text', + expectedValue + ); + } + } + }); + }); + }); + }); +}); diff --git a/frontend/src/app/GN2CommonModule/form/dynamic-form/dynamic-form.component.html b/frontend/src/app/GN2CommonModule/form/dynamic-form/dynamic-form.component.html index f023e1aa0d..6063bbb6f3 100644 --- a/frontend/src/app/GN2CommonModule/form/dynamic-form/dynamic-form.component.html +++ b/frontend/src/app/GN2CommonModule/form/dynamic-form/dynamic-form.component.html @@ -50,6 +50,7 @@ [formControl]="form.get(formDefComp['attribut_name'])" id="{{ formDefComp['attribut_name'] }}_{{ rand }}" type="text" + data-qa="field-text-{{ formDefComp['attribut_name'] }}_{{ rand }}" />
@@ -93,6 +97,7 @@ class="form-control form-control-sm" id="{{ formDefComp['attribut_name'] }}_{{ rand }}" [formControl]="form.get(formDefComp['attribut_name'])" + [attr.data-qa]="'field-select-' + '-' + formDefComp['attribut_name'] + '_' + rand" >
-
+