Skip to content

Commit

Permalink
Merge pull request #278 from AgenceBio/fix/fix-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
thom4parisot authored Dec 13, 2023
2 parents afc476d + 9c87752 commit c992063
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 34 deletions.
12 changes: 7 additions & 5 deletions src/components/Features/ExportStrategies/CertipaqExporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }) => {
Expand Down Expand Up @@ -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'
Expand Down
24 changes: 12 additions & 12 deletions src/components/Features/ExportStrategies/CertipaqExporter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ describe('CertipaqExporter', () => {
"Anté précédent",
"Produit",
"Date",
"Code culture",
"Id. Parcelle"
"Id. Parcelle",
"Code culture"
],
[
'',
Expand All @@ -53,8 +53,8 @@ describe('CertipaqExporter', () => {
'',
'',
'',
'01.19.10.8',
'1'
'1',
'01.19.10.8'
],
[
'',
Expand All @@ -72,8 +72,8 @@ describe('CertipaqExporter', () => {
'',
'',
'',
'01.19.10.8',
'2'
'2',
'01.19.10.8'
],
[
'',
Expand All @@ -91,8 +91,8 @@ describe('CertipaqExporter', () => {
'',
'',
'',
'01.19.10.8',
'3'
'3',
'01.19.10.8'
],
[
'',
Expand All @@ -110,8 +110,8 @@ describe('CertipaqExporter', () => {
'',
'',
'',
'01.19.10.7',
'4'
'4',
'01.19.10.7'
],
[
'',
Expand All @@ -129,8 +129,8 @@ describe('CertipaqExporter', () => {
'',
'',
'',
'',
'5'
'5',
''
]
]

Expand Down
33 changes: 23 additions & 10 deletions src/components/Features/FeatureGroup.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe("FeatureGroup", () => {
let featureGroup

beforeEach(() => {
featureGroup = getFeatureGroups(record.parcelles).at(1)
featureGroup = getFeatureGroups(record.parcelles).at(0)
})

afterEach(() => {
Expand Down Expand Up @@ -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 } }
})
Expand All @@ -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 () => {
Expand All @@ -75,16 +88,16 @@ 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([])

// 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)
})

Expand All @@ -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 () => {
Expand All @@ -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)
Expand All @@ -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])
})
})
5 changes: 3 additions & 2 deletions src/components/Features/FeatureGroup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@
</td>
<td @click="toggleEditForm(feature.id)" v-else>
<span class="culture-type" v-if="feature.properties.cultures.length > 1">
Multi-cultures
Multi-cultures<span class="fr-sr-only"> : </span>
<small class="feature-precision" v-for="(culture, i) in feature.properties.cultures" :key="i">
{{ cultureLabel(culture) }}
<span v-if="i" class="fr-sr-only">, </span>{{ cultureLabel(culture) }}
</small>
</span>
<span class="culture-name" v-else>{{ cultureLabel(feature.properties.cultures[0]) }}</span>
<small class="feature-precision">{{ featureName(feature) }}</small>
</td>
<td @click="toggleEditForm(feature.id)">
Expand Down
8 changes: 4 additions & 4 deletions src/components/Features/Table.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', '')
})
Expand All @@ -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)
})

Expand Down Expand Up @@ -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)
})

Expand Down
40 changes: 40 additions & 0 deletions src/components/Features/__fixtures__/record-with-features.json
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
]
}
}
]
}
Expand Down
2 changes: 1 addition & 1 deletion src/stores/record.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit c992063

Please sign in to comment.