Skip to content

Commit

Permalink
Merge pull request #388 from AgenceBio/fix/certification_date_debut-edit
Browse files Browse the repository at this point in the history
fix: édition de la date de début de certification
  • Loading branch information
cvagner authored Jul 24, 2024
2 parents 139eda9 + 07fb33b commit e1a8865
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: Build and deploy (test)

on:
workflow_dispatch:
push:
branches:
- "test"
Expand All @@ -12,7 +13,6 @@ on:
- '*.example'
- 'netlify.toml'
- '*.md'
workflow_dispatch:

jobs:
deploy:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# CartoBio

Application de suivi et de certificaton du parcellaire bio à destination des _opérateurs bio_[^1] et aux _organismes de certification_.
Application de suivi et de certificaton du parcellaire bio à destination des _opérateurs bio_[^1] et des _organismes de certification_.

Cette application implémente [la maquette Figma CartoBio][maquette-figma] ainsi que le [Système de Design de l'État](https://www.systeme-de-design.gouv.fr/) avec [Vue 3], [Vue Router], [Vue Pages] et [Pinia].

Expand Down
11 changes: 5 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@agencebio/cartobio-front",
"version": "2.25.6",
"version": "2.26.0",
"private": true,
"type": "module",
"scripts": {
Expand Down Expand Up @@ -47,7 +47,7 @@
"vue-matomo": "^4.1.0",
"vue-router": "^4.0.12",
"vue3-toastify": "^0.1.11",
"xlsx": "git+https://git.sheetjs.com/sheetjs/sheetjs.git#semver:^v0.20.2"
"xlsx": "git+https://git.sheetjs.com/sheetjs/sheetjs.git"
},
"devDependencies": {
"@agencebio/cartobio-types": "^1.6.1",
Expand Down
23 changes: 20 additions & 3 deletions src/components/forms/EditVersionForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,19 @@ useFocus(autofocusedElement, { initialValue: true })
const patch = reactive({
version_name: record.version_name,
audit_date: record.audit_date,
certification_date_debut: record.certification_date_debut,
certification_date_fin: record.certification_date_fin
})
const datesCertificationConflict = computed(() => {
if (!patch.certification_date_debut || !patch.certification_date_fin) {
return false;
}
const debutCertificationDate = new Date(patch.certification_date_debut)
const finCertificationDate = new Date(patch.certification_date_fin)
return debutCertificationDate >= finCertificationDate
})
const dateConflict = computed(() => {
let newDate
try {
Expand All @@ -38,6 +48,7 @@ function save() {
recordStore.updateInfo({
version_name: patch.version_name,
...(patch.audit_date && { audit_date: patch.audit_date }),
...(patch.certification_date_debut && { certification_date_debut: patch.certification_date_debut }),
...(patch.certification_date_fin && { certification_date_fin: patch.certification_date_fin })
})
Expand Down Expand Up @@ -79,19 +90,25 @@ function save() {
<div v-if="record.certification_state === 'CERTIFIED' && permissions.canChangeCertificationDate" class="fr-input-group">
<label for="certification_date_debut" class="fr-input-group__label">Date de début de validité du certificat</label>
<input type="date" id="certification_date_debut" class="fr-input" :value="record.certification_date_debut" />
<input type="date" id="certification_date_debut" class="fr-input" v-model="patch.certification_date_debut" required />
</div>
<div v-if="record.certification_state === 'CERTIFIED' && permissions.canChangeCertificationDate" class="fr-input-group">
<label for="certification_date_fin" class="fr-input-group__label">Date de fin de validité du certificat</label>
<input type="date" id="certification_date_fin" class="fr-input" v-model="patch.certification_date_fin" />
<input type="date" id="certification_date_fin" class="fr-input" v-model="patch.certification_date_fin" required />
</div>
<div v-if="datesCertificationConflict" class="fr-alert fr-alert--error fr-mb-2w">
<p class="fr-text--sm">
La date de début de validé du certificat doit être antérieure à la date de fin de validité de celui-ci.
</p>
</div>
</form>
<template #footer>
<ul class="fr-btns-group fr-btns-group--inline">
<li>
<button type="submit" class="fr-btn" form="version-edit-form" :disabled="dateConflict">Enregistrer</button>
<button type="submit" class="fr-btn" form="version-edit-form" :disabled="dateConflict || datesCertificationConflict">Enregistrer</button>
</li>
<li>
<button class="fr-btn fr-btn--tertiary" @click="$emit('close')">Annuler</button>
Expand Down
45 changes: 44 additions & 1 deletion src/components/records/Header.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { createTestingPinia } from "@pinia/testing"
import { useOperatorStore } from "@/stores/operator.js"
import { useRecordStore } from "@/stores/record.js"
import { useUserStore } from "@/stores/user.js"
import axios from "axios"

import operator from '@/utils/__fixtures__/operator.json' assert { type: 'json' }
import record from '@/utils/__fixtures__/record-with-features.json' assert { type: 'json' }
Expand All @@ -26,6 +27,7 @@ describe("RecordHeader", () => {
beforeEach(() => {
recordStore.update(record)
operatorStore.operator = operator
axios.__createMock.patch.mockResolvedValue({ data: record })
})

afterEach(() => {
Expand Down Expand Up @@ -54,7 +56,7 @@ describe("RecordHeader", () => {
expect(modal.find('#version_name').exists()).toBe(true)
})

it("should only allow Certification Body after", async () => {
it("should allow Certification Body after audit only for OC and without certification dates", async () => {
recordStore.update({ certification_state: 'AUDITED', audit_date: '2024-01-01' })
userStore.isOc = false
userStore.isOcCertif = false
Expand All @@ -69,6 +71,47 @@ describe("RecordHeader", () => {
await flushPromises()
const modal = wrapper.getComponent(EditVersionModal)
expect(modal.find('#audit_date').exists()).toBe(true)
expect(modal.find('#certification_date_debut').exists()).toBe(false)
expect(modal.find('#certification_date_fin').exists()).toBe(false)
})

it("should allow Certification Body after certification only for OC and with certification dates and save it", async () => {
recordStore.update({ certification_state: 'CERTIFIED', audit_date: '2024-01-01',
certification_date_debut: '2024-02-01', certification_date_fin: '2025-02-01' })
userStore.isOc = false
userStore.isOcCertif = false
let wrapper = mount(AsyncComponent)
await flushPromises()
expect(await wrapper.find('.edit-version-info').exists()).toBe(false)

userStore.isOc = true
userStore.isOcCertif = true
wrapper = mount(AsyncComponent)
await wrapper.find('.edit-version-info').trigger('click')
await flushPromises()

const modal = wrapper.getComponent(EditVersionModal)
expect(modal.find('#audit_date').exists()).toBe(true)
expect(modal.find('#certification_date_debut').exists()).toBe(true)
expect(modal.find('#certification_date_fin').exists()).toBe(true)

const newCertificationDateDebut = '2026-02-01'
const newCertificationDateFin = '2027-02-01'
await modal.find('#certification_date_debut').setValue(newCertificationDateDebut)
await modal.find('#certification_date_fin').setValue(newCertificationDateFin)
await modal.find('form').trigger('submit')
await flushPromises()

expect(axios.__createMock.patch).toHaveBeenCalledWith(
'/v2/audits/054f0d70-c3da-448f-823e-81fcf7c2bf6e',
{
audit_date: '2024-01-01',
certification_date_debut: newCertificationDateDebut,
certification_date_fin: newCertificationDateFin,
"version_name": "Version créée le 01/01/2024"
},
expect.anything()
)
})
})

Expand Down

0 comments on commit e1a8865

Please sign in to comment.