From bd78107359060910c71a73ca7e7a6b754c180397 Mon Sep 17 00:00:00 2001 From: Thomas Parisot Date: Mon, 19 Feb 2024 16:04:39 +0100 Subject: [PATCH 1/3] feat(exports): trie l'export Certipaq par nom de parcelle MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Assure que la fonction featureName() retourne toujours une chaîne de caractères --- .../ExportStrategies/CertipaqExporter.js | 15 ++++++++++-- .../ExportStrategies/CertipaqExporter.test.js | 20 ++++++++-------- .../ExportStrategies/CertisExporter.test.js | 20 ++++++++-------- .../ExportStrategies/CertisudExporter.test.js | 12 +++++----- .../ControlUnionExporter.test.js | 12 +++++----- .../ExportStrategies/DefaultExporter.test.js | 16 ++++++------- .../ExportStrategies/OcaciaExporter.test.js | 20 ++++++++-------- .../ExportStrategies/QualisudExporter.test.js | 16 ++++++------- .../__fixtures__/record-for-exports.json | 24 +++++++++---------- src/components/Features/index.js | 5 ++-- 10 files changed, 86 insertions(+), 74 deletions(-) diff --git a/src/components/Features/ExportStrategies/CertipaqExporter.js b/src/components/Features/ExportStrategies/CertipaqExporter.js index 9c1a91f8..ccd29344 100644 --- a/src/components/Features/ExportStrategies/CertipaqExporter.js +++ b/src/components/Features/ExportStrategies/CertipaqExporter.js @@ -64,7 +64,18 @@ const getSheet = ({ featureCollection, operator, permissions }) => { ['Commune', 'Ilot', 'Culture', 'Variété / infos', 'C0', 'AB', 'C1', 'C2', 'C3', 'Date conv', 'Observation / date de semis', 'Précédent', 'Anté précédent', 'Produit', 'Date', 'Id. Parcelle', 'Code culture'], ], { origin: 'A4'}) - sheet_add_aoa(sheet, featureCollection.features.map(({ geometry, properties: props, id }) => { + const ilotOptions = { + ilotLabel: '', + parcelleLabel: '', + separator: '_', + placeholder: '' + } + + const sortedFeatures = [...featureCollection.features].sort((a, b) => { + return featureName(a, ilotOptions).localeCompare(b, ilotOptions) + }) + + sheet_add_aoa(sheet, sortedFeatures.map(({ geometry, properties: props, id }) => { const surfaceHa = (surface(geometry) / 10_000).toLocaleString('fr-FR', { maximumFractionDigits: 2 }) const culture = props.cultures?.at(0) ? fromCodeCpf(props.cultures?.at(0).CPF) : { libelle_code_cpf: '[ERREUR] culture absente' } @@ -72,7 +83,7 @@ const getSheet = ({ featureCollection, operator, permissions }) => { // Commune #A props.COMMUNE_LABEL, // Ilot #B - featureName({ properties: props }, { ilotLabel: '', parcelleLabel: '', separator: '_', placeholder: '' }), + featureName({ properties: props }, ilotOptions), // Libellé Culture #C culture?.libelle_code_cpf ?? `[ERREUR] culture inconnue (${props.cultures?.at(0).CPF})`, // Variété / infos #D diff --git a/src/components/Features/ExportStrategies/CertipaqExporter.test.js b/src/components/Features/ExportStrategies/CertipaqExporter.test.js index 164dd5d7..8289abd7 100644 --- a/src/components/Features/ExportStrategies/CertipaqExporter.test.js +++ b/src/components/Features/ExportStrategies/CertipaqExporter.test.js @@ -115,40 +115,40 @@ describe('CertipaqExporter', () => { ], [ '', - '3_1', - '[ERREUR] culture inconnue (01.19.99)', - 'Culture inconnue', + '4_1', + '[ERREUR] culture absente', '', '', '', '', '', '', - '01.19.99 Culture inconnue', '', '', '', '', - '5', + '', + '', + '6', '' ], [ '', - '4_1', - '[ERREUR] culture absente', - '', - '', + '3_1', + '[ERREUR] culture inconnue (01.19.99)', + 'Culture inconnue', '', '', '', '', '', '', + '01.19.99 Culture inconnue', '', '', '', '', - '6', + '5', '' ] ] diff --git a/src/components/Features/ExportStrategies/CertisExporter.test.js b/src/components/Features/ExportStrategies/CertisExporter.test.js index 397bb2e2..fdb307be 100644 --- a/src/components/Features/ExportStrategies/CertisExporter.test.js +++ b/src/components/Features/ExportStrategies/CertisExporter.test.js @@ -155,16 +155,14 @@ describe('CertisExporter', () => { ], [ '', - '3', + '4', '1', 1.0464881572673355, '', '', '', - '[ERREUR] culture inconnue (01.19.99)', - '01.19.99 Culture inconnue', + '[ERREUR] culture absente', '', - '01.19.99 Culture inconnue', '', '', '', @@ -178,20 +176,22 @@ describe('CertisExporter', () => { '', '', '', - '5' + '', + '', + '6' ], [ '', - '4', + '3', '1', 1.0464881572673355, '', '', '', - '[ERREUR] culture absente', - '', - '', + '[ERREUR] culture inconnue (01.19.99)', + '01.19.99 Culture inconnue', '', + '01.19.99 Culture inconnue', '', '', '', @@ -205,7 +205,7 @@ describe('CertisExporter', () => { '', '', '', - '6' + '5' ] ] diff --git a/src/components/Features/ExportStrategies/CertisudExporter.test.js b/src/components/Features/ExportStrategies/CertisudExporter.test.js index 2d5cf5c5..4e1576ec 100644 --- a/src/components/Features/ExportStrategies/CertisudExporter.test.js +++ b/src/components/Features/ExportStrategies/CertisudExporter.test.js @@ -28,20 +28,20 @@ describe('CertisudExporter', () => { 'Id. Parcelles' ], [ - '[ERREUR] culture inconnue (01.19.99)', + '[ERREUR] culture absente', 1.0464881572673355, - '3.1', + '4.1', '', '', - '5' + '6' ], [ - '[ERREUR] culture absente', + '[ERREUR] culture inconnue (01.19.99)', 1.0464881572673355, - '4.1', + '3.1', '', '', - '6' + '5' ], [ 'Luzerne', diff --git a/src/components/Features/ExportStrategies/ControlUnionExporter.test.js b/src/components/Features/ExportStrategies/ControlUnionExporter.test.js index 9d456048..0ffcdd13 100644 --- a/src/components/Features/ExportStrategies/ControlUnionExporter.test.js +++ b/src/components/Features/ExportStrategies/ControlUnionExporter.test.js @@ -71,22 +71,22 @@ describe('ControlUnionExporter', () => { ], [ '', - '[ERREUR] culture inconnue (01.19.99)', + '[ERREUR] culture absente', 1.0464881572673355, '', '', - '3.1, 01.19.99 Culture inconnue', - '5', + '4.1', + '6', '' ], [ '', - '[ERREUR] culture absente', + '[ERREUR] culture inconnue (01.19.99)', 1.0464881572673355, '', '', - '4.1', - '6', + '3.1, 01.19.99 Culture inconnue', + '5', '' ] ] diff --git a/src/components/Features/ExportStrategies/DefaultExporter.test.js b/src/components/Features/ExportStrategies/DefaultExporter.test.js index f45dc29b..ebb6415e 100644 --- a/src/components/Features/ExportStrategies/DefaultExporter.test.js +++ b/src/components/Features/ExportStrategies/DefaultExporter.test.js @@ -92,12 +92,12 @@ describe('DefaultExporter', () => { '' ], [ - '5', - '3', + '6', + '4', '1', 1.0464881572673355, - '01.19.99', - '[ERREUR] culture inconnue (01.19.99)', + '', + '[ERREUR] culture absente', '', '', '', @@ -106,12 +106,12 @@ describe('DefaultExporter', () => { '' ], [ - '6', - '4', + '5', + '3', '1', 1.0464881572673355, - '', - '[ERREUR] culture absente', + '01.19.99', + '[ERREUR] culture inconnue (01.19.99)', '', '', '', diff --git a/src/components/Features/ExportStrategies/OcaciaExporter.test.js b/src/components/Features/ExportStrategies/OcaciaExporter.test.js index e409ec01..5b1832b7 100644 --- a/src/components/Features/ExportStrategies/OcaciaExporter.test.js +++ b/src/components/Features/ExportStrategies/OcaciaExporter.test.js @@ -121,43 +121,43 @@ describe('OcaciaExporter', () => { ], [ '', - '3.1', - '[ERREUR] culture inconnue (01.19.99)', + '4.1', + '[ERREUR] culture absente', '', - '01.19.99 Culture inconnue', '', '', '', '', '', '', - '01.19.99 Culture inconnue', '', '', '', '', '', - '5' - ], - [ '', - '4.1', - '[ERREUR] culture absente', '', + '6' + ], + [ '', + '3.1', + '[ERREUR] culture inconnue (01.19.99)', '', + '01.19.99 Culture inconnue', '', '', '', '', '', '', + '01.19.99 Culture inconnue', '', '', '', '', '', - '6' + '5' ] ] diff --git a/src/components/Features/ExportStrategies/QualisudExporter.test.js b/src/components/Features/ExportStrategies/QualisudExporter.test.js index 20ed4f5f..82f260c7 100644 --- a/src/components/Features/ExportStrategies/QualisudExporter.test.js +++ b/src/components/Features/ExportStrategies/QualisudExporter.test.js @@ -65,22 +65,22 @@ describe('QualisudExporter', () => { '4' ], [ - '[ERREUR] culture inconnue (01.19.99)', - '01.19.99 Culture inconnue', - 'ilot 3, parcelle 1', + '[ERREUR] culture absente', + '', + 'ilot 4, parcelle 1', 1.0464881572673355, '', '', - '5' + '6' ], [ - '[ERREUR] culture absente', - '', - 'ilot 4, parcelle 1', + '[ERREUR] culture inconnue (01.19.99)', + '01.19.99 Culture inconnue', + 'ilot 3, parcelle 1', 1.0464881572673355, '', '', - '6' + '5' ] ] diff --git a/src/components/Features/__fixtures__/record-for-exports.json b/src/components/Features/__fixtures__/record-for-exports.json index 788b3095..6937b032 100644 --- a/src/components/Features/__fixtures__/record-for-exports.json +++ b/src/components/Features/__fixtures__/record-for-exports.json @@ -131,35 +131,35 @@ } }, { - "id": 5, + "id": 6, "type": "Feature", "geometry": { "type": "Polygon", "coordinates": [[ [44.0, 2.0], [44.0, 2.0013], [44.0013, 2.0013], [44.0013, 2.0013], [44.0, 2.0] ]] }, "properties": { - "id": 5, - "NUMERO_I": "3", + "id": 6, + "NUMERO_I": "4", "NUMERO_P": "1", - "cultures": [ - { "id": 1, "CPF": "01.19.99" } - ], - "commentaire": "sans code CPF valide, ni date d'engagement ou autre" + "cultures": [], + "commentaire": "sans culture, suite à un import CVI par exemple" } }, { - "id": 6, + "id": 5, "type": "Feature", "geometry": { "type": "Polygon", "coordinates": [[ [44.0, 2.0], [44.0, 2.0013], [44.0013, 2.0013], [44.0013, 2.0013], [44.0, 2.0] ]] }, "properties": { - "id": 6, - "NUMERO_I": "4", + "id": 5, + "NUMERO_I": "3", "NUMERO_P": "1", - "cultures": [], - "commentaire": "sans culture, suite à un import CVI par exemple" + "cultures": [ + { "id": 1, "CPF": "01.19.99" } + ], + "commentaire": "sans code CPF valide, ni date d'engagement ou autre" } } ] diff --git a/src/components/Features/index.js b/src/components/Features/index.js index 40473425..8b6e1219 100644 --- a/src/components/Features/index.js +++ b/src/components/Features/index.js @@ -346,6 +346,7 @@ export function getFeatureById (features, id) { /** * @param {Feature} feature + * @param {{ ilotLabel?: string, parcelleLabel?: string, separator?: string, placeholder?: string}} options * @returns {String} */ export function featureName (feature, { ilotLabel = 'ilot ', parcelleLabel = 'parcelle ', separator = ', ', placeholder = '-'} = {}) { @@ -361,10 +362,10 @@ export function featureName (feature, { ilotLabel = 'ilot ', parcelleLabel = 'pa .join(separator) if (!name) { - return feature.properties.NOM + return feature.properties.NOM ?? placeholder } - return (ilotLabel && parcelleLabel && feature.properties.NOM ? `${name} (${feature.properties.NOM})` : name) + return (ilotLabel && parcelleLabel && feature.properties.NOM ? `${name} (${feature.properties.NOM})` : (name ?? placeholder)) } if (feature.properties.cadastre) { From 42f58327957da331104bbebd716589f9d5f1fe2b Mon Sep 17 00:00:00 2001 From: Thomas Parisot Date: Mon, 19 Feb 2024 16:05:17 +0100 Subject: [PATCH 2/3] feat(exports): teste l'export BV et prend en compte une possible absence de culture --- .../ExportStrategies/BureauVeritasExporter.js | 2 +- .../BureauVeritasExporter.test.js | 109 ++++++++++++++++++ 2 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 src/components/Features/ExportStrategies/BureauVeritasExporter.test.js diff --git a/src/components/Features/ExportStrategies/BureauVeritasExporter.js b/src/components/Features/ExportStrategies/BureauVeritasExporter.js index e277ffb6..39c9ece8 100644 --- a/src/components/Features/ExportStrategies/BureauVeritasExporter.js +++ b/src/components/Features/ExportStrategies/BureauVeritasExporter.js @@ -76,7 +76,7 @@ const getSheet = ({ featureCollection, operator }) => { sheet_add_aoa(sheet, [ [ culture?.groupe, - culture?.libelle_code_cpf ?? `[ERREUR] culture inconnue (${mainKey})`, + mainKey === '__nogroup__' ? '[ERREUR] culture absente' : (culture?.libelle_code_cpf ?? `[ERREUR] culture inconnue (${mainKey})`), culture?.code_bureau_veritas, // Complément certificat (variété) varietes, diff --git a/src/components/Features/ExportStrategies/BureauVeritasExporter.test.js b/src/components/Features/ExportStrategies/BureauVeritasExporter.test.js new file mode 100644 index 00000000..091f0b11 --- /dev/null +++ b/src/components/Features/ExportStrategies/BureauVeritasExporter.test.js @@ -0,0 +1,109 @@ +import { describe, test, expect, vi } from 'vitest' +import { usePermissions } from '@/stores/index.js' +import { createTestingPinia } from "@pinia/testing" +import Exporter from './BureauVeritasExporter.js' +import record from '@/components/Features/__fixtures__/record-for-exports.json' assert { type: 'json' } + +const pinia = createTestingPinia({ createSpy: vi.fn }) +const permissions = usePermissions(pinia) +permissions.isOc = true + +describe('BureauVeritasExporter', () => { + test('list by features', () => { + const exporter = new Exporter({ + featureCollection: record.parcelles, + operator: record.operator, + record: record, + permissions + }) + + const expectation = [ + [ + "SITE ID de l'opérateur", + "Catégorie", + "Produit", + "Code Produit", + "Complément certificat", + "Autres infos", + "Surface", + "Unité", + "Classement", + "Date conversion" + ], + [ + "27B/6", + "", + "[ERREUR] culture absente", + "", + "", + "Ilots : 4.1", + 1.0464881572673355, + "ha", + "", + "", + ], + [ + "PV", + "", + "[ERREUR] culture inconnue (01.19.99)", + "", + "", + "Ilots : 3.1", + 1.0464881572673355, + "ha", + "", + "", + ], + [ + "", + "Surfaces fourragères", + "Luzerne", + "1125", + "", + "Ilots : 1.1 ; 1.2", + 2.092976314534671, + "ha", + "C1", + "2023-01-01", + ], + [ + "", + "Surfaces fourragères", + "Luzerne", + "1125", + "", + "Ilots : 2.1, 0.70ha", + 1.0464881572673355, + "ha", + "AB", + "2021-01-01", + ], + [ + "", + "Surfaces fourragères", + "Trèfle", + "1124", + "4 feuilles", + "Ilots : 2.1, 4 feuilles, semis le 01/03/2023, 0.30ha", + 1.0464881572673355, + "ha", + "AB", + "2021-01-01", + ], + [ + "", + "Surfaces fourragères", + "Trèfle", + "1124", + "4 feuilles", + "Ilots : 2.2, 4 feuilles, semis le 01/03/2023", + 1.0464881572673355, + "ha", + "AB", + "2015-01-01", + ], + ] + + expect(exporter.toJSON()).toEqual(expectation) + }) +}) From cc6b4a9a4c059d26d5962cd9e50e0af92a986b4f Mon Sep 17 00:00:00 2001 From: Thomas Parisot Date: Mon, 19 Feb 2024 16:05:59 +0100 Subject: [PATCH 3/3] feat(CerticationState): teste et ajoute un aria-label --- src/components/Certification/State.test.js | 22 +++++++++++++++ src/components/Certification/State.vue | 33 ++++------------------ src/referentiels/ab.js | 24 ++++++++++++++++ 3 files changed, 51 insertions(+), 28 deletions(-) create mode 100644 src/components/Certification/State.test.js diff --git a/src/components/Certification/State.test.js b/src/components/Certification/State.test.js new file mode 100644 index 00000000..3c9fe6c5 --- /dev/null +++ b/src/components/Certification/State.test.js @@ -0,0 +1,22 @@ +import { describe, expect, it } from "vitest" +import { mount } from "@vue/test-utils" + +import { CERTIFICATION_STATE } from '@/referentiels/ab.js' +import State from "./State.vue" + +describe("CertificationState", () => { + it("renders N/C for an unknown or empty state", async () => { + let wrapper = mount(State, { props: { 'state': undefined } }) + expect(wrapper.text()).toContain("Non renseigné") + + wrapper = mount(State, { props: { 'state': CERTIFICATION_STATE.UNKNOWN } }) + expect(wrapper.text()).toContain("Non renseigné") + expect(wrapper.attributes()).toHaveProperty('aria-label', "Non renseigné") + }) + + it("renders a date suffix when provided", async () => { + const wrapper = mount(State, { props: { 'state': CERTIFICATION_STATE.CERTIFIED, date: new Date('2023-01-01') } }) + expect(wrapper.text()).toContain("Certifié 2023") + expect(wrapper.attributes()).toHaveProperty('aria-label', "Certifié en 2023") + }) +}) diff --git a/src/components/Certification/State.vue b/src/components/Certification/State.vue index 484bbf30..d47a6edd 100644 --- a/src/components/Certification/State.vue +++ b/src/components/Certification/State.vue @@ -1,45 +1,22 @@