diff --git a/frontend/cypress/e2e/import/search-import-list.js b/frontend/cypress/e2e/import/search-import-list.js new file mode 100644 index 0000000000..98cc837e61 --- /dev/null +++ b/frontend/cypress/e2e/import/search-import-list.js @@ -0,0 +1,152 @@ +const fixturePath = 'import/synthese/liste_import.json'; +const tableSelector = '[data-qa=import-list-table]'; +const timeoutWait = 1000; +const sizes = ['iphone-6', 'ipad-2', [1024, 768]]; +function filterMapList(importSeachTerm) { + cy.get('[data-qa="search-input-import-list"]').clear().type(importSeachTerm); +} + +describe('Test specific route call with specific pattern used in filter input', () => { + beforeEach(() => { + cy.viewport(1024, 768); + cy.geonatureLogin(); + cy.visit('/#/import'); + }); + const importSearchTerm = 'valid_file.csv'; + it('should call the route with the correct pattern', () => { + // Intercept the network request + cy.intercept( + Cypress.env('apiEndpoint') + 'import/imports/?page=1&search=' + importSearchTerm + ).as('getItems'); + cy.get('[data-qa="search-input-import-list"]').clear().type(importSearchTerm); + + // Wait for the request and then verify the details + cy.wait('@getItems').then((interception) => { + const params = new URLSearchParams(interception.request.url.split('?')[1]); + expect(params.get('search')).to.equal(importSearchTerm); + }); + }); +}); + +describe('Tests list import columns and rows content', () => { + sizes.forEach((size) => { + describe(`On ${size} screen size`, () => { + beforeEach(() => { + if (Cypress._.isArray(size)) { + cy.viewport(size[0], size[1]); + } else { + cy.viewport(size); + } + cy.geonatureLogin(); + cy.visit('/#/import'); + cy.intercept(Cypress.env('apiEndpoint') + 'import/imports/?page=1&search=', { + fixture: 'import/synthese/liste_import.json', + }); + }); + + it('Should display the correct number of rows ', () => { + let expectedRowCount; + + cy.fixture(fixturePath).then((config) => { + expectedRowCount = config.count; + cy.get(tableSelector).find('datatable-body-row').should('have.length', expectedRowCount); + }); + }); + + it('Should display the correct columns present in default config ', () => { + // Make an HTTP request to get the list of columns displayed for import + cy.request('GET', Cypress.env('apiEndpoint') + 'gn_commons/config').then((response) => { + // Extract the list of columns from the response + const columnsImport = response.body.IMPORT.LIST_COLUMNS_FRONTEND; + const columnNames = columnsImport.map((column) => column.name); + // Assert that each column name exists in at least one header cell + cy.get('[data-qa=import-list-table] datatable-header-cell').should(($cells) => { + columnNames.forEach((columnName) => { + expect($cells.toArray().some((cell) => cell.innerText.trim() === columnName)).to.be + .true; + }); + }); + }); + }); + }); + }); +}); + +// NOTES : WORKS ONLY IF UPLOAD two valid file (Synthese and Occhab --> from test files backend) +describe('Tests Filter Search List Import', () => { + const filters = [ + { + columnName: 'Voir la fiche du JDD', + searchTerm: ['habitat', 'tous règnes confondus'], + expectedRowsCount: [1, 1], + }, + { + columnName: 'Fichier', + searchTerm: ['valid_file.csv', 'invalid_file.csv'], + expectedRowsCount: [2, 0], + }, + ]; + + sizes.forEach((size) => { + describe(`On ${size} screen size`, () => { + beforeEach(() => { + if (Cypress._.isArray(size)) { + cy.viewport(size[0], size[1]); + } else { + cy.viewport(size); + } + cy.geonatureLogin(); + cy.visit('/#/import'); + // Ensure the import list table is present before proceeding + cy.get('[data-qa=import-list-table]', { timeout: timeoutWait }) + .should('be.visible') + .then(($table) => { + // Calculate column index here, once the table is visible + filters.forEach((filter) => { + filter.columnIndex = $table + .find('datatable-header-cell') + .toArray() + .findIndex((headerCell) => { + return Cypress.$(headerCell).text().trim() === filter.columnName; + }); + expect(filter.columnIndex).to.be.gte(0); // Ensure the column is found + }); + }); + }); + + filters.forEach((filter) => { + filter.searchTerm.forEach((searchTerm, index) => { + const expectedRowsCount = filter.expectedRowsCount[index]; + + it(`Should get ${expectedRowsCount} rows for search term "${searchTerm}" in column "${filter.columnName}"`, () => { + filterMapList(searchTerm); + cy.wait(timeoutWait); // Ensure any UI updates complete + cy.get('[data-qa=import-list-table] datatable-body', { timeout: timeoutWait }).within( + () => { + cy.get('datatable-body-row').should('have.length', expectedRowsCount); + } + ); + }); + + if (expectedRowsCount > 0) { + it(`Should get a row containing "${searchTerm}" in column "${filter.columnName}"`, () => { + filterMapList(searchTerm); + cy.wait(timeoutWait); + + cy.get('[data-qa=import-list-table] datatable-body-row', { timeout: timeoutWait }) + .eq(0) + .as('firstRow'); + cy.get('@firstRow') + .find('datatable-body-cell') + .eq(filter.columnIndex) + .invoke('text') + .then((rowValue) => { + cy.wrap(rowValue.trim()).should('contain', searchTerm); + }); + }); + } + }); + }); + }); + }); +}); diff --git a/frontend/cypress/fixtures/import/synthese/liste_import.json b/frontend/cypress/fixtures/import/synthese/liste_import.json new file mode 100644 index 0000000000..7c663204ab --- /dev/null +++ b/frontend/cypress/fixtures/import/synthese/liste_import.json @@ -0,0 +1,541 @@ +{ + "count": 2, + "imports": [ + { + "altitude_autogenerated": null, + "authors": [ + { + "nom_complet": "User Test - 1" + } + ], + "authors_name": "User Test - 1" , + "available_encodings": [ + "iso-8859-1", + "iso-8859-15", + "utf-8" + ], + "available_formats": [ + "csv", + "geojson" + ], + "available_separators": [ + ",", + ";" + ], + "columns": [ + "error", + "id_synthese", + "id_origine", + "comment_releve", + "comment_occurrence", + "date_debut", + "date_fin", + "heure_debut", + "heure_fin", + "cd_nom", + "cd_ref", + "nom_valide", + "nom_vernaculaire", + "nom_cite", + "regne", + "group1_inpn", + "group2_inpn", + "classe", + "ordre", + "famille", + "rang_taxo", + "nombre_min", + "nombre_max", + "alti_min", + "alti_max", + "prof_min", + "prof_max", + "observateurs", + "determinateur", + "communes", + "geometrie_wkt_4326", + "x_centroid_4326", + "y_centroid_4326", + "nom_lieu", + "validateur", + "niveau_validation", + "date_validation", + "comment_validation", + "preuve_numerique_url", + "preuve_non_numerique", + "jdd_nom", + "jdd_uuid", + "jdd_id", + "ca_nom", + "ca_uuid", + "ca_id", + "cd_habref", + "cd_habitat", + "nom_habitat", + "precision_geographique", + "nature_objet_geo", + "type_regroupement", + "methode_regroupement", + "technique_observation", + "biologique_statut", + "etat_biologique", + "biogeographique_statut", + "naturalite", + "preuve_existante", + "niveau_precision_diffusion", + "stade_vie", + "sexe", + "objet_denombrement", + "type_denombrement", + "niveau_sensibilite", + "statut_observation", + "floutage_dee", + "statut_source", + "type_info_geo", + "methode_determination", + "comportement", + "reference_biblio", + "uuid_perm_sinp", + "uuid_perm_grp_sinp", + "date_creation", + "date_modification" + ], + "contentmapping": { + "DEE_FLOU": { + "Non": "NON" + }, + "ETA_BIO": { + "Non renseign\u00e9": "1" + }, + "METH_DETERMIN": { + "Autre m\u00e9thode de d\u00e9termination": "2" + }, + "METH_OBS": { + "Galerie/terrier": "23" + }, + "NATURALITE": { + "Sauvage": "1" + }, + "NAT_OBJ_GEO": { + "Inventoriel": "In" + }, + "NIV_PRECIS": { + "Pr\u00e9cise": "5" + }, + "OBJ_DENBR": { + "Individu": "IND" + }, + "OCC_COMPORTEMENT": { + "Non renseign\u00e9": "1" + }, + "PREUVE_EXIST": { + "Oui": "1" + }, + "SENSIBILITE": { + "Non sensible - Diffusion pr\u00e9cise": "0" + }, + "SEXE": { + "Femelle": "2" + }, + "STADE_VIE": { + "Adulte": "2", + "Immature": "4", + "Juv\u00e9nile": "3" + }, + "STATUT_BIO": { + "Non renseign\u00e9": "1" + }, + "STATUT_OBS": { + "Pr\u00e9sent": "Pr" + }, + "STATUT_SOURCE": { + "Terrain": "Te" + }, + "STATUT_VALID": { + "En attente de validation": "0" + }, + "STAT_BIOGEO": { + "Non renseign\u00e9": "1" + }, + "TYP_DENBR": { + "Compt\u00e9": "Co" + }, + "TYP_GRP": { + "OBS": "OBS" + } + }, + "cruved": { + "C": true, + "D": true, + "E": false, + "R": true, + "U": true, + "V": false + }, + "dataset": { + "active": true, + "dataset_name": "Contact al\u00e9atoire tous r\u00e8gnes confondus" + }, + "date_create_import": "2024-05-13 23:55:51.167003", + "date_end_import": "2024-05-13 23:56:46.793605", + "date_max_data": null, + "date_min_data": null, + "date_update_import": "2024-05-13 23:56:46.796963", + "destination": { + "code": "synthese", + "label": "Synth\u00e8se", + "statistics_labels": [ + { + "key": "taxa_count", + "value": "Nombre de taxons import\u00e9s" + } + ] + }, + "detected_encoding": "utf-8", + "detected_format": "csv", + "detected_separator": ";", + "encoding": "utf-8", + "errors_count": 3, + "fieldmapping": { + "WKT": "geometrie_wkt_4326", + "altitude_max": "alti_max", + "altitude_min": "alti_min", + "cd_hab": "cd_habref", + "cd_nom": "cd_nom", + "comment_context": "comment_releve", + "comment_description": "comment_occurrence", + "count_max": "nombre_max", + "count_min": "nombre_min", + "date_max": "date_fin", + "date_min": "date_debut", + "depth_max": "prof_max", + "depth_min": "prof_min", + "determiner": "determinateur", + "digital_proof": "preuve_numerique_url", + "entity_source_pk_value": "id_synthese", + "grp_method": "methode_regroupement", + "hour_max": "heure_fin", + "hour_min": "heure_debut", + "id_nomenclature_behaviour": "comportement", + "id_nomenclature_bio_condition": "etat_biologique", + "id_nomenclature_bio_status": "biologique_statut", + "id_nomenclature_biogeo_status": "biogeographique_statut", + "id_nomenclature_blurring": "floutage_dee", + "id_nomenclature_determination_method": "methode_determination", + "id_nomenclature_diffusion_level": "niveau_precision_diffusion", + "id_nomenclature_exist_proof": "preuve_existante", + "id_nomenclature_geo_object_nature": "nature_objet_geo", + "id_nomenclature_grp_typ": "type_regroupement", + "id_nomenclature_life_stage": "stade_vie", + "id_nomenclature_naturalness": "naturalite", + "id_nomenclature_obj_count": "objet_denombrement", + "id_nomenclature_obs_technique": "technique_observation", + "id_nomenclature_observation_status": "statut_observation", + "id_nomenclature_sensitivity": "niveau_sensibilite", + "id_nomenclature_sex": "sexe", + "id_nomenclature_source_status": "statut_source", + "id_nomenclature_type_count": "type_denombrement", + "id_nomenclature_valid_status": "niveau_validation", + "meta_create_date": "date_creation", + "meta_update_date": "date_modification", + "meta_validation_date": "date_validation", + "nom_cite": "nom_cite", + "non_digital_proof": "preuve_non_numerique", + "observers": "observateurs", + "place_name": "nom_lieu", + "precision": "precision_geographique", + "reference_biblio": "reference_biblio", + "unique_id_sinp": "uuid_perm_sinp", + "unique_id_sinp_grp": "uuid_perm_grp_sinp", + "validation_comment": "comment_validation", + "validator": "validateur" + }, + "format_source_file": "csv", + "full_file_name": "fichier_import_1.csv", + "id_dataset": 1, + "id_destination": 1, + "id_import": 1, + "import_count": 3, + "loaded": false, + "processed": true, + "separator": ";", + "source_count": 6, + "srid": 4326, + "statistics": { + "taxa_count": 2 + }, + "task_id": null, + "task_progress": null, + "uuid_autogenerated": null + }, + { + "altitude_autogenerated": null, + "authors": [ + { + "nom_complet": "User Test - 2" + } + ], + "authors_name": "User Test - 2", + "available_encodings": [ + "iso-8859-1", + "iso-8859-15", + "utf-8" + ], + "available_formats": [ + "csv", + "geojson" + ], + "available_separators": [ + ",", + ";" + ], + "columns": [ + "error", + "id_synthese", + "id_origine", + "comment_releve", + "comment_occurrence", + "date_debut", + "date_fin", + "heure_debut", + "heure_fin", + "cd_nom", + "cd_ref", + "nom_valide", + "nom_vernaculaire", + "nom_cite", + "regne", + "group1_inpn", + "group2_inpn", + "classe", + "ordre", + "famille", + "rang_taxo", + "nombre_min", + "nombre_max", + "alti_min", + "alti_max", + "prof_min", + "prof_max", + "observateurs", + "determinateur", + "communes", + "geometrie_wkt_4326", + "x_centroid_4326", + "y_centroid_4326", + "nom_lieu", + "validateur", + "niveau_validation", + "date_validation", + "comment_validation", + "preuve_numerique_url", + "preuve_non_numerique", + "jdd_nom", + "jdd_uuid", + "jdd_id", + "ca_nom", + "ca_uuid", + "ca_id", + "cd_habref", + "cd_habitat", + "nom_habitat", + "precision_geographique", + "nature_objet_geo", + "type_regroupement", + "methode_regroupement", + "technique_observation", + "biologique_statut", + "etat_biologique", + "biogeographique_statut", + "naturalite", + "preuve_existante", + "niveau_precision_diffusion", + "stade_vie", + "sexe", + "objet_denombrement", + "type_denombrement", + "niveau_sensibilite", + "statut_observation", + "floutage_dee", + "statut_source", + "type_info_geo", + "methode_determination", + "comportement", + "reference_biblio", + "uuid_perm_sinp", + "uuid_perm_grp_sinp", + "date_creation", + "date_modification" + ], + "contentmapping": { + "DEE_FLOU": { + "Non": "NON" + }, + "ETA_BIO": { + "Non renseign\u00e9": "1" + }, + "METH_DETERMIN": { + "Autre m\u00e9thode de d\u00e9termination": "2" + }, + "METH_OBS": { + "Galerie/terrier": "23" + }, + "NATURALITE": { + "Sauvage": "1" + }, + "NAT_OBJ_GEO": { + "Inventoriel": "In" + }, + "NIV_PRECIS": { + "Pr\u00e9cise": "5" + }, + "OBJ_DENBR": { + "Individu": "IND" + }, + "OCC_COMPORTEMENT": { + "Non renseign\u00e9": "1" + }, + "PREUVE_EXIST": { + "Oui": "1" + }, + "SENSIBILITE": { + "Non sensible - Diffusion pr\u00e9cise": "0" + }, + "SEXE": { + "Femelle": "2" + }, + "STADE_VIE": { + "Adulte": "2", + "Immature": "4", + "Juv\u00e9nile": "3" + }, + "STATUT_BIO": { + "Non renseign\u00e9": "1" + }, + "STATUT_OBS": { + "Pr\u00e9sent": "Pr" + }, + "STATUT_SOURCE": { + "Terrain": "Te" + }, + "STATUT_VALID": { + "En attente de validation": "0" + }, + "STAT_BIOGEO": { + "Non renseign\u00e9": "1" + }, + "TYP_DENBR": { + "Compt\u00e9": "Co" + }, + "TYP_GRP": { + "OBS": "OBS" + } + }, + "cruved": { + "C": true, + "D": true, + "E": false, + "R": true, + "U": true, + "V": false + }, + "dataset": { + "active": true, + "dataset_name": "JDD - TEST FRONTEND" + }, + "date_create_import": "2024-05-13 23:55:51.167003", + "date_end_import": "2024-05-13 23:56:46.793605", + "date_max_data": null, + "date_min_data": null, + "date_update_import": "2024-05-13 23:56:46.796963", + "destination": { + "code": "destination", + "label": "Destination", + "statistics_labels": [ + { + "key": "taxa_count", + "value": "Nombre de taxons import\u00e9s" + } + ] + }, + "detected_encoding": "utf-8", + "detected_format": "csv", + "detected_separator": ";", + "encoding": "utf-8", + "errors_count": 3, + "fieldmapping": { + "WKT": "geometrie_wkt_4326", + "altitude_max": "alti_max", + "altitude_min": "alti_min", + "cd_hab": "cd_habref", + "cd_nom": "cd_nom", + "comment_context": "comment_releve", + "comment_description": "comment_occurrence", + "count_max": "nombre_max", + "count_min": "nombre_min", + "date_max": "date_fin", + "date_min": "date_debut", + "depth_max": "prof_max", + "depth_min": "prof_min", + "determiner": "determinateur", + "digital_proof": "preuve_numerique_url", + "entity_source_pk_value": "id_synthese", + "grp_method": "methode_regroupement", + "hour_max": "heure_fin", + "hour_min": "heure_debut", + "id_nomenclature_behaviour": "comportement", + "id_nomenclature_bio_condition": "etat_biologique", + "id_nomenclature_bio_status": "biologique_statut", + "id_nomenclature_biogeo_status": "biogeographique_statut", + "id_nomenclature_blurring": "floutage_dee", + "id_nomenclature_determination_method": "methode_determination", + "id_nomenclature_diffusion_level": "niveau_precision_diffusion", + "id_nomenclature_exist_proof": "preuve_existante", + "id_nomenclature_geo_object_nature": "nature_objet_geo", + "id_nomenclature_grp_typ": "type_regroupement", + "id_nomenclature_life_stage": "stade_vie", + "id_nomenclature_naturalness": "naturalite", + "id_nomenclature_obj_count": "objet_denombrement", + "id_nomenclature_obs_technique": "technique_observation", + "id_nomenclature_observation_status": "statut_observation", + "id_nomenclature_sensitivity": "niveau_sensibilite", + "id_nomenclature_sex": "sexe", + "id_nomenclature_source_status": "statut_source", + "id_nomenclature_type_count": "type_denombrement", + "id_nomenclature_valid_status": "niveau_validation", + "meta_create_date": "date_creation", + "meta_update_date": "date_modification", + "meta_validation_date": "date_validation", + "nom_cite": "nom_cite", + "non_digital_proof": "preuve_non_numerique", + "observers": "observateurs", + "place_name": "nom_lieu", + "precision": "precision_geographique", + "reference_biblio": "reference_biblio", + "unique_id_sinp": "uuid_perm_sinp", + "unique_id_sinp_grp": "uuid_perm_grp_sinp", + "validation_comment": "comment_validation", + "validator": "validateur" + }, + "format_source_file": "csv", + "full_file_name": "fichier_import_2.csv", + "id_dataset": 2, + "id_destination": 2, + "id_import": 2, + "import_count": 3, + "loaded": false, + "processed": true, + "separator": ";", + "source_count": 6, + "srid": 4326, + "statistics": { + "taxa_count": 2 + }, + "task_id": null, + "task_progress": null, + "uuid_autogenerated": null + } + ], + "limit": 15, + "offset": 0 + } \ No newline at end of file diff --git a/frontend/src/app/modules/imports/components/import_list/import-list.component.html b/frontend/src/app/modules/imports/components/import_list/import-list.component.html index 2c5dc1ba0b..0878964841 100644 --- a/frontend/src/app/modules/imports/components/import_list/import-list.component.html +++ b/frontend/src/app/modules/imports/components/import_list/import-list.component.html @@ -25,6 +25,7 @@