Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Réinitialiser le status quand changement d'ON #415

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading