Skip to content

Commit

Permalink
Réinitialiser le status quand changement d'ON
Browse files Browse the repository at this point in the history
Réinitialise le status réglementaire quand un changement d'organisme
nuisible est fait afin d'éviter de laisser une valeur fausse.
  • Loading branch information
Anto59290 committed Nov 15, 2024
1 parent d28918e commit 88d25a6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 8 deletions.
18 changes: 11 additions & 7 deletions sv/static/sv/fichedetection_form.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,18 @@ document.addEventListener('DOMContentLoaded', function() {
});

choices.passedElement.element.addEventListener("choice", (event)=> {
statusToNuisibleId.forEach((line) =>{
if (line.nuisibleIds.includes(parseInt(event.detail.choice.value)))
{
document.getElementById('statut-reglementaire-input').value=line.statusID
let found = false;
statusToNuisibleId.forEach((status) =>{
if (status.nuisibleIds.includes(parseInt(event.detail.choice.value))) {
document.getElementById('statut-reglementaire-input').value = status.statusID;
document.getElementById('statut-reglementaire-input').dispatchEvent(new Event('change'));
found = true;
}
})

if (found === false){
document.getElementById('statut-reglementaire-input').value="";
document.getElementById('statut-reglementaire-input').dispatchEvent(new Event('change'));
}
})
});

Expand Down Expand Up @@ -309,7 +313,7 @@ document.addEventListener('alpine:init', () => {
})
if (!!this.ficheDetection.freeLinksIds) {
this.ficheDetection.freeLinksIds.forEach(value => {
freeLinksChoices.setChoiceByValue(value);
freeLinksChoices.setChoiceByValue(value);
});
}

Expand Down Expand Up @@ -608,7 +612,7 @@ document.addEventListener('alpine:init', () => {
formData.append('prelevements', JSON.stringify(this.prelevements));
formData.append('action', action);
for (var i = 0; i < this.ficheDetection.freeLinksIds.length; i++) {
formData.append('freeLinksIds', this.ficheDetection.freeLinksIds[i]);
formData.append('freeLinksIds', this.ficheDetection.freeLinksIds[i]);
}

const csrfToken = document.querySelector('input[name="csrfmiddlewaretoken"]').value;
Expand Down
28 changes: 27 additions & 1 deletion sv/tests/test_fichedetection_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ def test_fiche_detection_status_reglementaire_is_pre_selected(

page.goto(f"{live_server.url}{reverse('fiche-detection-creation')}")
choice_js_fill(page, "#organisme-nuisible .choices__list--single", "Mon ON", "Mon ON")
expect(form_elements.statut_reglementaire_input).to_contain_text("----")
expect(form_elements.statut_reglementaire_input).to_have_value("2")
page.get_by_role("button", name="Enregistrer").click()

page.wait_for_timeout(600)
Expand All @@ -383,6 +383,32 @@ def test_fiche_detection_status_reglementaire_is_pre_selected(
assert fiche_detection.statut_reglementaire.code == "OQ"


@pytest.mark.django_db
def test_fiche_detection_status_reglementaire_is_emptied_when_unknown(
live_server, page: Page, form_elements: FicheDetectionFormDomElements, choice_js_fill
):
organisme_nuisible, _ = OrganismeNuisible.objects.get_or_create(code_oepp="OE_XYLEFM")
organisme_nuisible.libelle_court = "Mon ON"
organisme_nuisible.save()

organisme_nuisible_no_status, _ = OrganismeNuisible.objects.get_or_create(code_oepp="FOO")
organisme_nuisible_no_status.libelle_court = "Pas mon ON"
organisme_nuisible_no_status.save()

page.goto(f"{live_server.url}{reverse('fiche-detection-creation')}")
choice_js_fill(page, "#organisme-nuisible .choices__list--single", "Mon ON", "Mon ON")
expect(form_elements.statut_reglementaire_input).to_have_value("2")
choice_js_fill(page, "#organisme-nuisible .choices__list--single", "Pas mon ON", "Pas mon ON")
expect(form_elements.statut_reglementaire_input).to_have_value("")
page.get_by_role("button", name="Enregistrer").click()

page.wait_for_timeout(600)

fiche_detection = FicheDetection.objects.get()
assert fiche_detection.organisme_nuisible == organisme_nuisible_no_status
assert fiche_detection.statut_reglementaire is None


def test_prelevements_are_always_linked_to_lieu(
live_server,
page: Page,
Expand Down

0 comments on commit 88d25a6

Please sign in to comment.