Skip to content

Commit

Permalink
Corriger les demandes d'intervention
Browse files Browse the repository at this point in the history
Depuis le changement de destinataires sur les DI les destinataires
n'étaient plus enregistrés en base.
De plus j'ai changé la logique de la liste déroulante qui proposait
uniquement les structures de la fiche pour proposer toutes les
structures qui sont joignable (cohérent avec le type message).

Ajout d'un test pour vérifier que tout est ok et que les destinataires
sont bons.
  • Loading branch information
Anto59290 committed Feb 28, 2025
1 parent 0050dbc commit 9ed040e
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 2 deletions.
7 changes: 5 additions & 2 deletions core/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,11 @@ def __init__(self, *args, sender, **kwargs):
self.fields["recipients"].queryset = queryset
self.fields["recipients_copy"].queryset = queryset

queryset_structures = self._get_structures(obj)
queryset_structures = Contact.objects.structures_only().can_be_emailed().select_related("structure")
self.fields["recipients_structures_only"].queryset = queryset_structures
self.fields["recipients_copy_structures_only"].queryset = queryset_structures

if queryset_structures:
if self._get_structures(obj):
self.fields["recipients"].label = self._get_recipients_label(obj)
self.fields["recipients_structures_only"].label = self._get_recipients_label(obj)
self.fields["recipients_copy"].label = self._get_recipients_copy_label(obj)
Expand Down Expand Up @@ -281,6 +281,9 @@ def clean(self):
super().clean()
if self.cleaned_data["message_type"] in Message.TYPES_WITH_LIMITED_RECIPIENTS:
self._convert_checkboxes_to_contacts()
if self.cleaned_data["message_type"] in Message.TYPES_WITH_STRUCTURES_ONLY:
self.cleaned_data["recipients"] = self.cleaned_data["recipients_structures_only"]
self.cleaned_data["recipients_copy"] = self.cleaned_data["recipients_copy_structures_only"]
self.instance.sender = self.sender


Expand Down
56 changes: 56 additions & 0 deletions sv/tests/test_evenement_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,62 @@ def test_can_add_and_see_message_without_document(live_server, page: Page, choic
assert "My content <br> with a line return" in page.get_by_test_id("message-content").inner_html()


def test_can_add_and_see_demande_intervention(live_server, page: Page, choice_js_fill):
active_contact = ContactStructureFactory(with_one_active_agent=True)
other_active_contact = ContactStructureFactory(with_one_active_agent=True)
evenement = EvenementFactory()

page.goto(f"{live_server.url}{evenement.get_absolute_url()}")
page.get_by_test_id("element-actions").click()
page.get_by_role("link", name="Demande d'intervention", exact=True).click()

choice_js_fill(
page,
"#id_recipients_structures_only ~ input",
active_contact.display_with_agent_unit,
active_contact.display_with_agent_unit,
)
page.keyboard.press("Escape")
choice_js_fill(
page,
"#id_recipients_copy_structures_only ~ input",
other_active_contact.display_with_agent_unit,
other_active_contact.display_with_agent_unit,
)
expect(page.locator("#message-type-title")).to_have_text("demande d'intervention")
page.locator("#id_title").fill("Title of the message")
page.locator("#id_content").fill("My content \n with a line return")
page.get_by_test_id("fildesuivi-add-submit").click()

page.wait_for_url(f"**{evenement.get_absolute_url()}#tabpanel-messages-panel")

cell_selector = f"#table-sm-row-key-1 td:nth-child({2}) a"
assert page.text_content(cell_selector) == "Structure Test"

cell_selector = f"#table-sm-row-key-1 td:nth-child({3}) a"
assert page.text_content(cell_selector).strip() == str(active_contact)

cell_selector = f"#table-sm-row-key-1 td:nth-child({4}) a"
assert page.text_content(cell_selector) == "Title of the message"

cell_selector = f"#table-sm-row-key-1 td:nth-child({6}) a"
assert page.text_content(cell_selector) == "Demande d'intervention"

page.locator(cell_selector).click()

expect(page.get_by_role("heading", name="Title of the message")).to_be_visible()
assert "My content <br> with a line return" in page.get_by_test_id("message-content").inner_html()

message = Message.objects.get()
assert list(message.recipients.all()) == [
active_contact,
]
assert list(message.recipients_copy.all()) == [
other_active_contact,
]
assert message.message_type == Message.DEMANDE_INTERVENTION


def test_can_add_and_see_message_multiple_documents(live_server, page: Page, choice_js_fill):
active_contact = ContactAgentFactory(with_active_agent=True).agent
evenement = EvenementFactory()
Expand Down

0 comments on commit 9ed040e

Please sign in to comment.