Skip to content

Commit

Permalink
feat(test): test frontend for context params url
Browse files Browse the repository at this point in the history
- Synthese test frontend (ok)
- wip : make occhab condition and refact test

Reviewed-by: andriacap
  • Loading branch information
andriacap committed Dec 13, 2024
1 parent af01154 commit 554881c
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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
);
}
}
});
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"
/>
<div
*ngIf="
Expand All @@ -66,6 +67,7 @@
[formControl]="form.get(formDefComp['attribut_name'])"
id="{{ formDefComp['attribut_name'] }}_{{ rand }}"
type="time"
[attr.data-qa]="'field-time' + formDefComp['attribut_name'] + '_' + rand"
/>

<input
Expand All @@ -76,6 +78,7 @@
type="number"
min="{{ formDefComp['min'] }}"
max="{{ formDefComp['max'] }}"
[attr.data-qa]="'field-number' + '-' + formDefComp['attribut_name'] + '_' + rand"
/>

<textarea
Expand All @@ -85,6 +88,7 @@
id="{{ formDefComp['attribut_name'] }}_{{ rand }}"
type="textarea"
rows="{{ formDefComp['rows'] }}"
[attr.data-qa]="'field-textarea' + '-' + formDefComp['attribut_name'] + '_' + rand"
></textarea>

<span *ngSwitchCase="'select'">
Expand All @@ -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"
>
<option
[ngValue]="null"
Expand Down Expand Up @@ -224,6 +229,7 @@
name="{{ formDefComp['attribut_name'] }}_{{ rand }}_{{ item.value }}"
[value]="item.value"
[formControl]="form.get(formDefComp['attribut_name'])"
[attr.data-qa]="'field-radio' + formDefComp['attribut_name'] + '_' + rand"
/>
<label
class="custom-control-label"
Expand Down Expand Up @@ -290,6 +296,7 @@
[regne]="formDefComp['regne']"
[group2Inpn]="formDefComp['group2Inpn']"
[bindAllItem]="formDefComp['bind_all_item']"
[attr.data-qa]="'field-nomenclature' + '-' + formDefComp['attribut_name']"
></pnx-nomenclature>

<pnx-taxonomy
Expand All @@ -299,6 +306,7 @@
[idList]="formDefComp['id_list']"
[charNumber]="3"
[listLength]="20"
[attr.data-qa]="'field-taxonomy' + '-' + formDefComp['attribut_name']"
></pnx-taxonomy>

<pnx-datasets
Expand All @@ -308,6 +316,7 @@
[multiSelect]="formDef.multi_select"
[moduleCode]="formDef.module_code"
[creatableInModule]="formDef.creatable_in_module"
[attr.data-qa]="'field-dataset' + '-' + formDefComp['attribut_name']"
></pnx-datasets>

<pnx-observers
Expand All @@ -318,18 +327,21 @@
[idList]="formDefComp['id_list']"
[codeList]="formDefComp['code_list']"
[multiSelect]="formDefComp['multi_select']"
[attr.data-qa]="'field-observers' + '-' + formDefComp['attribut_name']"
></pnx-observers>

<pnx-observers-text
*ngSwitchCase="'observers-text'"
[label]="formDefComp['attribut_label']"
[parentFormControl]="form.get(formDefComp['attribut_name'])"
[attr.data-qa]="'field-observers-txt' + '-' + formDefComp['attribut_name']"
></pnx-observers-text>

<pnx-date
*ngSwitchCase="'date'"
[label]="formDefComp['attribut_label']"
[parentFormControl]="form.get(formDefComp['attribut_name'])"
[attr.data-qa]="'field-date' + '-' + formDefComp['attribut_name']"
></pnx-date>

<pnx-areas
Expand All @@ -338,13 +350,15 @@
[parentFormControl]="form.get(formDefComp.attribut_name)"
[valueFieldName]="formDefComp.value_field_name"
[typeCodes]="formDefComp.type_codes"
[attr.data-qa]="'field-areas' + '-' + formDefComp['attribut_name']"
></pnx-areas>

<pnx-municipalities
*ngSwitchCase="'municipalities'"
[label]="formDefComp['attribut_label']"
[parentFormControl]="form.get(formDefComp['attribut_name'])"
[valueFieldName]="formDefComp['value_field_name']"
[attr.data-qa]="'field-municipalities' + '-' + formDefComp['attribut_name']"
></pnx-municipalities>

<pnx-multiselect
Expand All @@ -356,6 +370,7 @@
[label]="formDefComp['attribut_label']"
[searchBar]="false"
[disabled]="form.get(formDefComp['attribut_name'])?.disabled"
[attr.data-qa]="'field-multiselect' + '-' + formDefComp['attribut_name']"
></pnx-multiselect>
<pnx-datalist
*ngSwitchCase="'datalist'"
Expand All @@ -377,6 +392,9 @@
[filters]="formDefComp['filters']"
[default]="formDefComp['default']"
[nullDefault]="formDefComp['nullDefault']"
[attr.data-qa]="
'field-datalist' + '-' + formDefComp['attribut_label'] + '-' + formDefComp['attribut_name']
"
></pnx-datalist>

<small class="form-text text-muted">{{ formDefComp['help'] }}</small>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export class DynamicFormComponent implements OnInit, OnChanges, OnDestroy {

ngOnInit() {
this.setFormDefComp(true);
console.log("this.formDefComp", this.formDefComp);
// Disable the form if a value is provided and is not in the select list
// In case list value change and data are still in database
if (this.formDef.type_widget == 'select') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,10 @@ <h5 class="card-title mb-0">{{ 'Import.FieldMapping.Title' | translate }}</h5>
</span>
</ng-template>
<form>
<div class="form-group">
<div
class="form-group"
[attr.data-qa]="'import-fieldmapping-' + '-' + Import.FieldMapping.MappingName"
>
<label
for="mappingName"
*ngIf="this.updateAvailable"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<div
*ngIf="!field.autogenerated"
class="form-group"
[attr.data-qa]="'import-fieldmapping-theme-' + field.name_field"
>
<small>
{{ field.fr_label }} :
Expand Down Expand Up @@ -96,6 +97,7 @@
<div
*ngIf="field.autogenerated"
class="form-group"
[attr.data-qa]="'import-fieldmapping-theme-' + field.name_field"
>
<p
*ngIf="displayAlert(field)"
Expand Down

0 comments on commit 554881c

Please sign in to comment.