Skip to content

Commit

Permalink
test: refact test to use occhab dest fixture
Browse files Browse the repository at this point in the history
Reviewed-by: andriacap
  • Loading branch information
andriacap committed Jan 2, 2025
1 parent 1d5ce19 commit 164e01e
Showing 1 changed file with 47 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ 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') {
function handleFieldValidation(dataQa, paramsName, expectedValue, fieldType) {
if (['textarea', 'text', 'number'].includes(fieldType)) {
cy.get(dataQa)
.find(`[data-qa^="field-${fieldType}-${paramName}_default_value_"]`)
.find(`[data-qa^="field-${fieldType}-${paramsName}_default_value_"]`)
.should('have.value', expectedValue);
} else 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);
}
}

Expand All @@ -21,41 +25,47 @@ const paramsByDestination = [
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' },
// ],
// },
{
destination: 'occhab',
queryParams: [
{
paramsName: 'nom_cite',
paramsValue: 'test_nomcite',
fieldType: 'text',
entityLabel: 'Habitat',
expectedValue: 'test_nomcite',
},
{
paramsName: 'station_name',
paramsValue: 'test_station_name',
fieldType: 'text',
entityLabel: 'Station',
expectedValue: 'test_station_name',
},
],
},
];

describe('Import - Upload step', () => {
Expand All @@ -67,38 +77,30 @@ describe('Import - Upload step', () => {
});

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}"]`;
describe(`Destination: ${destination}`, () => {
beforeEach(() => {
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();
});

// 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'));
it(`Validates fields for destination: ${destination}`, () => {
queryParams.forEach(({ paramsName, expectedValue, fieldType, entityLabel }) => {
let dataQa = `[data-qa="import-fieldmapping-theme-${paramsName}"]`;

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
);
if (destination === 'occhab' && entityLabel) {
const dataQaEntity = `[data-qa="import-entity-tab-${entityLabel}"]`;
cy.get(dataQaEntity, { timeout: 30000 })
.should('be.visible')
.click();
}
}

handleFieldValidation(dataQa, paramsName, expectedValue, fieldType);
});
});
});
});
Expand Down

0 comments on commit 164e01e

Please sign in to comment.