From 03ff9adddbb9b3b0b2e727c2a68b7a9a4e9e6a12 Mon Sep 17 00:00:00 2001 From: Thomas Parisot Date: Wed, 13 Dec 2023 14:09:55 +0100 Subject: [PATCH 1/3] fix: ajoute une feature de plus pour faciliter des tests --- src/components/Features/Table.test.js | 8 ++-- .../__fixtures__/record-with-features.json | 40 +++++++++++++++++++ src/stores/record.test.js | 2 +- 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/src/components/Features/Table.test.js b/src/components/Features/Table.test.js index dd14d72f..4b82b3d3 100644 --- a/src/components/Features/Table.test.js +++ b/src/components/Features/Table.test.js @@ -35,12 +35,12 @@ describe("Features Table", () => { vi.clearAllMocks() }) - test("features are listed as 3 groups of 2 and 1 and 1 features (multi-crops)", () => { + test("features are listed as 3 groups of 2 and 1 and 2 features (one being multi-crops)", () => { const wrapper = mount(TableComponent, { props: { operator, validationRules: { rules: OPERATOR_RULES } } }) - expect(wrapper.find('tr.summary td:nth-child(2)').text()).toBe("3 parcelles") + expect(wrapper.find('tr.summary td:nth-child(2)').text()).toBe("4 parcelles") expect(wrapper.findAll('table tbody')).toHaveLength(3) expect(wrapper.find('#parcelle-1').attributes()).toHaveProperty('hidden', '') }) @@ -53,7 +53,7 @@ describe("Features Table", () => { expect(wrapper.find('#radio-mass-edit').exists()).toEqual(false) await wrapper.find('#radio-select-all').trigger('click') - expect(featuresStore.selectedIds).toEqual([1, 2, 3]) + expect(featuresStore.selectedIds).toEqual([1, 2, 3, 4]) expect(wrapper.find('#radio-mass-edit').exists()).toEqual(true) }) @@ -83,7 +83,7 @@ describe("Features Table", () => { await flushPromises() expect(wrapper.find('tr.summary td:nth-child(2)').text()).toBe("1 parcelles") - expect(featuresStore.all).toHaveLength(3) + expect(featuresStore.all).toHaveLength(4) expect(featuresStore.hits).toHaveLength(1) }) diff --git a/src/components/Features/__fixtures__/record-with-features.json b/src/components/Features/__fixtures__/record-with-features.json index 4f123e6c..cfe567a9 100644 --- a/src/components/Features/__fixtures__/record-with-features.json +++ b/src/components/Features/__fixtures__/record-with-features.json @@ -131,6 +131,46 @@ { "id": 1, "CPF": "01.19.10.8" } ] } + }, + { + "id": 4, + "type": "Feature", + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + 2.825121146516608, + 44.30042614674991 + ], + [ + 2.825121146516608, + 44.260111501833876 + ], + [ + 2.901018077685336, + 44.260111501833876 + ], + [ + 2.901018077685336, + 44.30042614674991 + ], + [ + 2.825121146516608, + 44.30042614674991 + ] + ] + ] + }, + "properties": { + "id": 4, + "NUMERO_I": "2", + "NUMERO_P": "1", + "COMMUNE": "26108", + "cultures": [ + { "id": 1, "CPF": "01.13.42", "variete": "spéciale pour ail noir" } + ] + } } ] } diff --git a/src/stores/record.test.js b/src/stores/record.test.js index 09e1bf3c..5b5448b8 100644 --- a/src/stores/record.test.js +++ b/src/stores/record.test.js @@ -74,7 +74,7 @@ describe('update', () => { it('cascades the feature store updates', () => { store.update(record) - expect(featuresStore.all).toHaveLength(3) + expect(featuresStore.all).toHaveLength(4) }) it('resets the feature store as well', () => { From dfb46fd9e2063143f0369d79277defde2d443a8b Mon Sep 17 00:00:00 2001 From: Thomas Parisot Date: Wed, 13 Dec 2023 14:10:55 +0100 Subject: [PATCH 2/3] fix: teste les contenus des cellules dans FeatureGroup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Détecte notamment l'absence de la culture (hors multi-culture) quand on trie sur une commune par exemple --- src/components/Features/FeatureGroup.test.js | 33 ++++++++++++++------ src/components/Features/FeatureGroup.vue | 5 +-- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/components/Features/FeatureGroup.test.js b/src/components/Features/FeatureGroup.test.js index 07e29575..8adf6b0a 100644 --- a/src/components/Features/FeatureGroup.test.js +++ b/src/components/Features/FeatureGroup.test.js @@ -20,7 +20,7 @@ describe("FeatureGroup", () => { let featureGroup beforeEach(() => { - featureGroup = getFeatureGroups(record.parcelles).at(1) + featureGroup = getFeatureGroups(record.parcelles).at(0) }) afterEach(() => { @@ -48,10 +48,16 @@ describe("FeatureGroup", () => { expect(headers.at(1).text()).toEqual('Nom') expect(headers.at(2).text()).toEqual('Certification') expect(headers.at(3).text()).toEqual('') + + // we should have a multi culture name within the 3rd cell + expect(wrapper.find('#parcelle-2 .feature-precision').text()).toEqual('Multi-culture') + + // we should have a single culture name within the 3rd cell + expect(wrapper.find('#parcelle-4 .culture-name').text()).toEqual('ilot 2, parcelle 1') }) test('non-culture grouping has different column name', async () => { - const featureGroup = getFeatureGroups(record.parcelles, GROUPE_COMMUNE).at(1) + const featureGroup = getFeatureGroups(record.parcelles, GROUPE_COMMUNE).at(0) const wrapper = mount(FeatureGroup, { props: { featureGroup, selectedIds: [], hoveredId: null, validationRules: { rules } } }) @@ -61,6 +67,13 @@ describe("FeatureGroup", () => { // we have default columns const headers = header.findAll('*') expect(headers.at(1).text()).toEqual('Culture') + + // we should have a multi culture name within the 3rd cell + expect(wrapper.find('#parcelle-2 .culture-type').text()).toEqual('Multi-cultures : Ail, Pomelos et pamplemousses') + + // we should have a single culture name within the 3rd cell + expect(wrapper.find('#parcelle-4 .culture-name').text()).toEqual('Ail') + expect(wrapper.find('#parcelle-4 .feature-precision').text()).toEqual('ilot 2, parcelle 1') }) test('toggles on and off all group items', async () => { @@ -75,7 +88,7 @@ describe("FeatureGroup", () => { const selectAllCheckbox = wrapper.find('.group-header .single-checkbox input[type="checkbox"]') await selectAllCheckbox.trigger('click') - expect(featuresStore.selectedIds).toEqual([1, 3]) + expect(featuresStore.selectedIds).toEqual([2, 4]) await selectAllCheckbox.trigger('click') expect(featuresStore.selectedIds).toEqual([]) @@ -83,8 +96,8 @@ describe("FeatureGroup", () => { // we close the header // then we click again on a single checkbox await wrapper.find('.group-header').trigger('click') - await wrapper.find('#parcelle-3 .single-checkbox input[type="checkbox"]').trigger('click') - expect(featuresStore.selectedIds).toEqual([3]) + await wrapper.find('#parcelle-2 .single-checkbox input[type="checkbox"]').trigger('click') + expect(featuresStore.selectedIds).toEqual([2]) expect(wrapper.vm.open).toEqual(true) }) @@ -100,9 +113,9 @@ describe("FeatureGroup", () => { const group = wrapper.getComponent(FeatureGroup) await wrapper.find('.group-header').trigger('click') - await wrapper.find('#parcelle-3 td').trigger('click') + await wrapper.find('#parcelle-2 td').trigger('click') - expect(group.emitted('edit:featureId')).toHaveProperty('0', [3]) + expect(group.emitted('edit:featureId')).toHaveProperty('0', [2]) }) test('we trigger a delete form', async () => { @@ -111,10 +124,10 @@ describe("FeatureGroup", () => { }) await wrapper.find('.group-header').trigger('click') - await wrapper.find('#parcelle-3 .show-actions').trigger('click') + await wrapper.find('#parcelle-2 .show-actions').trigger('click') // menu is open - const menu = wrapper.find('#parcelle-3 .fr-menu') + const menu = wrapper.find('#parcelle-2 .fr-menu') expect(menu.exists()).toEqual(true) // delete item is not active unless we have the permissions (after flushPromises/re-render) @@ -123,6 +136,6 @@ describe("FeatureGroup", () => { await flushPromises() expect(menu.find('.fr-icon-delete-line').attributes()).not.toHaveProperty('disabled') menu.find('.fr-icon-delete-line').trigger('click') - expect(wrapper.emitted('delete:featureId')).toHaveProperty('0', [3]) + expect(wrapper.emitted('delete:featureId')).toHaveProperty('0', [2]) }) }) diff --git a/src/components/Features/FeatureGroup.vue b/src/components/Features/FeatureGroup.vue index a6dab89b..df962f76 100644 --- a/src/components/Features/FeatureGroup.vue +++ b/src/components/Features/FeatureGroup.vue @@ -33,11 +33,12 @@ - Multi-cultures + Multi-cultures : - {{ cultureLabel(culture) }} + , {{ cultureLabel(culture) }} + {{ cultureLabel(feature.properties.cultures[0]) }} {{ featureName(feature) }} From 9c87752615d95ea96fdd34c363a4eec062a441db Mon Sep 17 00:00:00 2001 From: Thomas Parisot Date: Wed, 13 Dec 2023 14:20:55 +0100 Subject: [PATCH 3/3] fix: ajustement de l'export Certipaq Inversion des colonnes P/Q --- .../ExportStrategies/CertipaqExporter.js | 12 ++++++---- .../ExportStrategies/CertipaqExporter.test.js | 24 +++++++++---------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/components/Features/ExportStrategies/CertipaqExporter.js b/src/components/Features/ExportStrategies/CertipaqExporter.js index e5965a48..91fd5159 100644 --- a/src/components/Features/ExportStrategies/CertipaqExporter.js +++ b/src/components/Features/ExportStrategies/CertipaqExporter.js @@ -50,6 +50,8 @@ const getSheet = ({ featureCollection, operator, permissions }) => { { wch: 10 }, { wch: 10 }, // Id. Parcelle { wch: 16 }, + // Code culture + '', // [ blank ] '', // Totaux - AB - C1 - C2 - C3 - C0 - Total @@ -59,7 +61,7 @@ const getSheet = ({ featureCollection, operator, permissions }) => { // First sheet: plots informations (via `featureCollection`) sheet_add_aoa(sheet, [ [ '', '', '', '', 'Surfaces en ha', '', '', '', '', '', '', '', '', 'Dernier intrant non autorisé en AB', '', '', ''], - ['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', 'Code culture', 'Id. Parcelle'], + ['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 }) => { @@ -93,16 +95,16 @@ const getSheet = ({ featureCollection, operator, permissions }) => { '', // Date '', - // Code culture (CPF) #P - culture?.code_cpf, - // Id. Parcelle #Q + // Id. Parcelle #P String(id), + // Code culture (CPF) #Q + culture?.code_cpf, ] }), { origin: 'A6', cellDates: true }) // Formattage des cellules, s'il y a une valeur featureCollection.features.forEach((feature, index) => { - sheet[`Q${6 + index}`].t = 's'; + sheet[`P${6 + index}`].t = 's'; if (sheet[`J${6 + index}`].v) { sheet[`J${6 + index}`].t = 'd' diff --git a/src/components/Features/ExportStrategies/CertipaqExporter.test.js b/src/components/Features/ExportStrategies/CertipaqExporter.test.js index 9debccd7..f2818bd1 100644 --- a/src/components/Features/ExportStrategies/CertipaqExporter.test.js +++ b/src/components/Features/ExportStrategies/CertipaqExporter.test.js @@ -34,8 +34,8 @@ describe('CertipaqExporter', () => { "Anté précédent", "Produit", "Date", - "Code culture", - "Id. Parcelle" + "Id. Parcelle", + "Code culture" ], [ '', @@ -53,8 +53,8 @@ describe('CertipaqExporter', () => { '', '', '', - '01.19.10.8', - '1' + '1', + '01.19.10.8' ], [ '', @@ -72,8 +72,8 @@ describe('CertipaqExporter', () => { '', '', '', - '01.19.10.8', - '2' + '2', + '01.19.10.8' ], [ '', @@ -91,8 +91,8 @@ describe('CertipaqExporter', () => { '', '', '', - '01.19.10.8', - '3' + '3', + '01.19.10.8' ], [ '', @@ -110,8 +110,8 @@ describe('CertipaqExporter', () => { '', '', '', - '01.19.10.7', - '4' + '4', + '01.19.10.7' ], [ '', @@ -129,8 +129,8 @@ describe('CertipaqExporter', () => { '', '', '', - '', - '5' + '5', + '' ] ]