diff --git a/app/locales/incident.en-US.yml b/app/locales/incident.en-US.yml index 4c626e77..c603c70a 100644 --- a/app/locales/incident.en-US.yml +++ b/app/locales/incident.en-US.yml @@ -5,6 +5,7 @@ en-US: close: "Close" modal: title: "SRE - Start an incident" + launching: "Launching incident process..." congratulations: "Congratulations!" something_wrong: "Something has gone wrong. You've got this!" app_help: "This app is going to help you get set up. It will create the following: \n \n • a channel \n • an incident report \n • a Google Meet\n\n" diff --git a/app/locales/incident.fr-FR.yml b/app/locales/incident.fr-FR.yml index 1d9bf8fe..660dc61b 100644 --- a/app/locales/incident.fr-FR.yml +++ b/app/locales/incident.fr-FR.yml @@ -5,6 +5,7 @@ fr-FR: close: "Fermer" modal: title: "IFS - Lancer un incident" + launching: "Lancement du processus d'incident..." congratulations: "Félicitations!" something_wrong: "Il y a eu un problème. Vous pouvez y arriver!" app_help: "Cette application vous aidera à vous préparer. Elle créera les choses suivantes: \n \n • un canal \n • un rapport d'incident \n • une rencontre Google Meet\n\n" diff --git a/app/modules/incident/incident.py b/app/modules/incident/incident.py index c691c4cf..92e87b30 100644 --- a/app/modules/incident/incident.py +++ b/app/modules/incident/incident.py @@ -185,6 +185,28 @@ def generate_incident_modal_view(command, options=[], locale="en-US"): def open_modal(client, ack, command, body): ack() + if "user" in body: + user_id = body["user"]["id"] + else: + user_id = body["user_id"] + locale = slack_users.get_user_locale(client, user_id) + i18n.set("locale", locale) + loading_view = { + "type": "modal", + "callback_id": "incident_view", + "title": {"type": "plain_text", "text": i18n.t("incident.modal.title")}, + "submit": {"type": "plain_text", "text": i18n.t("incident.submit")}, + "blocks": [ + { + "type": "section", + "text": { + "type": "mrkdwn", + "text": f":beach-ball: {i18n.t('incident.modal.launching')}", + }, + }, + ], + } + view = client.views_open(trigger_id=body["trigger_id"], view=loading_view)["view"] folders = google_drive.list_folders() options = [ { @@ -193,14 +215,8 @@ def open_modal(client, ack, command, body): } for i in folders ] - if "user" in body: - user_id = body["user"]["id"] - else: - user_id = body["user_id"] - locale = slack_users.get_user_locale(client, user_id) - i18n.set("locale", locale) - view = generate_incident_modal_view(command, options, locale) - client.views_open(trigger_id=body["trigger_id"], view=view) + loaded_view = generate_incident_modal_view(command, options, locale) + client.views_update(view_id=view["id"], view=loaded_view) def handle_change_locale_button(ack, client, body): diff --git a/app/tests/modules/incident/test_incident.py b/app/tests/modules/incident/test_incident.py index 6c94303d..510b8d34 100644 --- a/app/tests/modules/incident/test_incident.py +++ b/app/tests/modules/incident/test_incident.py @@ -283,8 +283,23 @@ def test_handle_incident_action_buttons_link_preview( ) +@patch("modules.incident.incident.generate_incident_modal_view") +@patch("modules.incident.incident.i18n") +@patch("modules.incident.incident.slack_users.get_user_locale") @patch("modules.incident.incident.google_drive.list_folders") -def test_incident_open_modal_calls_ack(mock_list_folders): +def test_incident_open_modal_calls_ack( + mock_list_folders, + mock_get_user_locale, + mock_i18n, + mock_generate_incident_modal_view, +): + loaded_view = mock_generate_incident_modal_view.return_value = ANY + mock_i18n.t.side_effect = [ + "SRE - Start an incident", + "Submit", + "Launching incident process...", + ] + mock_get_user_locale.return_value = "en-US" mock_list_folders.return_value = [{"id": "id", "name": "name"}] client = MagicMock() ack = MagicMock() @@ -298,14 +313,14 @@ def test_incident_open_modal_calls_ack(mock_list_folders): assert kwargs["trigger_id"] == "trigger_id" assert kwargs["view"]["type"] == "modal" assert kwargs["view"]["callback_id"] == "incident_view" + assert kwargs["view"]["title"]["text"] == "SRE - Start an incident" + assert kwargs["view"]["submit"]["text"] == "Submit" assert ( - kwargs["view"]["blocks"][6]["element"]["initial_value"] - == "incident description" - ) - assert kwargs["view"]["blocks"][7]["element"]["options"][0]["value"] == "id" - assert ( - kwargs["view"]["blocks"][7]["element"]["options"][0]["text"]["text"] == "name" + kwargs["view"]["blocks"][0]["text"]["text"] + == ":beach-ball: Launching incident process..." ) + mock_generate_incident_modal_view.assert_called_once_with(command, ANY, "en-US") + client.views_update.assert_called_once_with(view_id=ANY, view=loaded_view) @patch("modules.incident.incident.generate_incident_modal_view")