2023-10-12 19:43:45 +02:00
|
|
|
from typing_extensions import override
|
|
|
|
|
2022-04-14 23:53:15 +02:00
|
|
|
from zerver.actions.create_user import do_create_user
|
2024-05-10 16:17:04 +02:00
|
|
|
from zerver.actions.onboarding_steps import do_mark_onboarding_step_as_read
|
2024-07-24 13:51:19 +02:00
|
|
|
from zerver.lib.onboarding_steps import ALL_ONBOARDING_STEPS, get_next_onboarding_steps
|
2017-01-24 01:48:35 +01:00
|
|
|
from zerver.lib.test_classes import ZulipTestCase
|
2024-05-10 15:37:43 +02:00
|
|
|
from zerver.models import OnboardingStep
|
2023-12-15 02:14:24 +01:00
|
|
|
from zerver.models.realms import get_realm
|
2017-01-24 01:48:35 +01:00
|
|
|
|
|
|
|
|
|
|
|
# Splitting this out, since I imagine this will eventually have most of the
|
2023-12-01 14:36:24 +01:00
|
|
|
# complicated onboarding steps logic.
|
|
|
|
class TestGetNextOnboardingSteps(ZulipTestCase):
|
2023-10-12 19:43:45 +02:00
|
|
|
@override
|
2017-11-05 10:51:25 +01:00
|
|
|
def setUp(self) -> None:
|
2019-10-19 20:47:00 +02:00
|
|
|
super().setUp()
|
2017-08-31 18:20:03 +02:00
|
|
|
self.user = do_create_user(
|
2021-02-06 14:27:06 +01:00
|
|
|
"user@zulip.com", "password", get_realm("zulip"), "user", acting_user=None
|
2020-07-16 14:10:43 +02:00
|
|
|
)
|
2017-08-31 18:20:03 +02:00
|
|
|
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_some_done_some_not(self) -> None:
|
2024-06-28 13:40:08 +02:00
|
|
|
# "visibility_policy_banner" is already marked as read for a new user.
|
|
|
|
onboarding_step = OnboardingStep.objects.get(user=self.user)
|
|
|
|
self.assertEqual(onboarding_step.onboarding_step, "visibility_policy_banner")
|
|
|
|
|
2024-05-10 15:37:43 +02:00
|
|
|
do_mark_onboarding_step_as_read(self.user, "intro_inbox_view_modal")
|
2023-12-01 14:36:24 +01:00
|
|
|
onboarding_steps = get_next_onboarding_steps(self.user)
|
2024-09-20 16:29:28 +02:00
|
|
|
self.assert_length(onboarding_steps, 7)
|
2024-05-10 15:37:43 +02:00
|
|
|
self.assertEqual(onboarding_steps[0]["name"], "intro_recent_view_modal")
|
|
|
|
self.assertEqual(onboarding_steps[1]["name"], "first_stream_created_banner")
|
2024-04-03 12:01:57 +02:00
|
|
|
self.assertEqual(onboarding_steps[2]["name"], "jump_to_conversation_banner")
|
2024-04-05 13:32:42 +02:00
|
|
|
self.assertEqual(onboarding_steps[3]["name"], "non_interleaved_view_messages_fading")
|
2024-04-23 09:04:05 +02:00
|
|
|
self.assertEqual(onboarding_steps[4]["name"], "interleaved_view_messages_fading")
|
2024-09-20 16:29:28 +02:00
|
|
|
self.assertEqual(onboarding_steps[5]["name"], "intro_resolve_topic")
|
|
|
|
self.assertEqual(onboarding_steps[6]["name"], "narrow_to_dm_with_welcome_bot_new_user")
|
2021-05-08 11:00:12 +02:00
|
|
|
|
2024-05-10 15:37:43 +02:00
|
|
|
with self.settings(TUTORIAL_ENABLED=False):
|
|
|
|
onboarding_steps = get_next_onboarding_steps(self.user)
|
|
|
|
self.assert_length(onboarding_steps, 0)
|
2021-05-08 11:00:12 +02:00
|
|
|
|
2024-05-10 15:37:43 +02:00
|
|
|
def test_all_onboarding_steps_done(self) -> None:
|
|
|
|
self.assertNotEqual(get_next_onboarding_steps(self.user), [])
|
2017-01-24 01:48:35 +01:00
|
|
|
|
2024-07-24 13:51:19 +02:00
|
|
|
for onboarding_step in ALL_ONBOARDING_STEPS: # nocoverage
|
|
|
|
do_mark_onboarding_step_as_read(self.user, onboarding_step.name)
|
2018-03-18 20:59:10 +01:00
|
|
|
|
2024-05-10 15:37:43 +02:00
|
|
|
self.assertEqual(get_next_onboarding_steps(self.user), [])
|
2021-03-11 17:19:49 +01:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2023-12-01 11:52:41 +01:00
|
|
|
class TestOnboardingSteps(ZulipTestCase):
|
2024-07-24 13:51:19 +02:00
|
|
|
@override
|
|
|
|
def setUp(self) -> None:
|
|
|
|
super().setUp()
|
|
|
|
OnboardingStep.objects.filter(user=self.example_user("hamlet")).delete()
|
|
|
|
|
2023-12-01 11:52:41 +01:00
|
|
|
def test_do_mark_onboarding_step_as_read(self) -> None:
|
2021-02-12 08:20:45 +01:00
|
|
|
user = self.example_user("hamlet")
|
2024-05-10 15:37:43 +02:00
|
|
|
do_mark_onboarding_step_as_read(user, "intro_inbox_view_modal")
|
2021-02-12 08:19:30 +01:00
|
|
|
self.assertEqual(
|
2023-12-01 08:20:48 +01:00
|
|
|
list(
|
|
|
|
OnboardingStep.objects.filter(user=user).values_list("onboarding_step", flat=True)
|
|
|
|
),
|
2024-05-10 15:37:43 +02:00
|
|
|
["intro_inbox_view_modal"],
|
2021-02-12 08:19:30 +01:00
|
|
|
)
|
2017-01-24 01:48:35 +01:00
|
|
|
|
2023-12-01 11:52:41 +01:00
|
|
|
def test_onboarding_steps_url_endpoint(self) -> None:
|
2021-02-12 08:20:45 +01:00
|
|
|
user = self.example_user("hamlet")
|
2020-03-06 18:40:46 +01:00
|
|
|
self.login_user(user)
|
2023-12-01 11:52:41 +01:00
|
|
|
result = self.client_post(
|
2024-05-10 15:37:43 +02:00
|
|
|
"/json/users/me/onboarding_steps", {"onboarding_step": "intro_recent_view_modal"}
|
2023-12-01 11:52:41 +01:00
|
|
|
)
|
2017-01-24 01:48:35 +01:00
|
|
|
self.assert_json_success(result)
|
2021-02-12 08:19:30 +01:00
|
|
|
self.assertEqual(
|
2023-12-01 08:20:48 +01:00
|
|
|
list(
|
|
|
|
OnboardingStep.objects.filter(user=user).values_list("onboarding_step", flat=True)
|
|
|
|
),
|
2024-05-10 15:37:43 +02:00
|
|
|
["intro_recent_view_modal"],
|
2021-02-12 08:19:30 +01:00
|
|
|
)
|
2017-03-29 23:04:25 +02:00
|
|
|
|
2023-12-01 11:52:41 +01:00
|
|
|
result = self.client_post("/json/users/me/onboarding_steps", {"onboarding_step": "invalid"})
|
|
|
|
self.assert_json_error(result, "Unknown onboarding_step: invalid")
|
2021-02-12 08:19:30 +01:00
|
|
|
self.assertEqual(
|
2023-12-01 08:20:48 +01:00
|
|
|
list(
|
|
|
|
OnboardingStep.objects.filter(user=user).values_list("onboarding_step", flat=True)
|
|
|
|
),
|
2024-05-10 15:37:43 +02:00
|
|
|
["intro_recent_view_modal"],
|
2021-02-12 08:19:30 +01:00
|
|
|
)
|