Skip to content

Commit

Permalink
Merge pull request #319 from AgenceBio/feature/sort-exports
Browse files Browse the repository at this point in the history
  • Loading branch information
thom4parisot authored Feb 19, 2024
2 parents 597aee9 + cc6b4a9 commit 679c514
Show file tree
Hide file tree
Showing 15 changed files with 247 additions and 103 deletions.
22 changes: 22 additions & 0 deletions src/components/Certification/State.test.js
Original file line number Diff line number Diff line change
@@ -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")
})
})
33 changes: 5 additions & 28 deletions src/components/Certification/State.vue
Original file line number Diff line number Diff line change
@@ -1,45 +1,22 @@
<template>
<span :class="['fr-badge', stateInfo.color]">
<span :class="['fr-badge', stateInfo.color]" :aria-label="date ? `${stateInfo.label} en ${dateLabel}` : stateInfo.label">
{{ stateInfo.label }}
<span v-if="date" class="year">{{ dateLabel }}</span>
</span>
</template>

<script setup>
import { readonly, computed } from 'vue'
import { computed } from 'vue'
import { CERTIFICATION_STATE } from '@/referentiels/ab.js'
import { CERTIFICATION_STATE, certificationStates } from '@/referentiels/ab.js'
const props = defineProps({
state: String,
date: String
})
const STATE_MAP = readonly({
UNKNOWN: {
label: 'Non renseigné',
color: 'fr-badge--warning'
},
[CERTIFICATION_STATE.OPERATOR_DRAFT]: {
label: 'Parcellaire importé',
color: 'fr-badge--info'
},
[CERTIFICATION_STATE.AUDITED]: {
label: 'Audit terminé',
color: 'fr-badge--new'
},
[CERTIFICATION_STATE.PENDING_CERTIFICATION]: {
label: 'Certification en cours',
color: 'fr-badge--new'
},
[CERTIFICATION_STATE.CERTIFIED]: {
label: 'Certifié',
color: 'fr-badge--success'
},
})
const stateId = computed(() => props.state in STATE_MAP ? props.state : 'UNKNOWN')
const stateInfo = computed(() => STATE_MAP[stateId.value])
const stateId = computed(() => props.state in certificationStates ? props.state : CERTIFICATION_STATE.UNKNOWN)
const stateInfo = computed(() => certificationStates[stateId.value])
const dateLabel = computed(() => {
return props.date
? new Date(props.date).toLocaleDateString('fr-FR', { year: 'numeric'})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
109 changes: 109 additions & 0 deletions src/components/Features/ExportStrategies/BureauVeritasExporter.test.js
Original file line number Diff line number Diff line change
@@ -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)
})
})
15 changes: 13 additions & 2 deletions src/components/Features/ExportStrategies/CertipaqExporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,26 @@ 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' }

return [
// 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
Expand Down
20 changes: 10 additions & 10 deletions src/components/Features/ExportStrategies/CertipaqExporter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
''
]
]
Expand Down
20 changes: 10 additions & 10 deletions src/components/Features/ExportStrategies/CertisExporter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
'',
'',
'',
Expand All @@ -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',
'',
'',
'',
Expand All @@ -205,7 +205,7 @@ describe('CertisExporter', () => {
'',
'',
'',
'6'
'5'
]
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
''
]
]
Expand Down
Loading

0 comments on commit 679c514

Please sign in to comment.