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
|
2023-12-01 11:52:41 +01:00
|
|
|
from zerver.actions.hotspots import do_mark_onboarding_step_as_read
|
2023-12-01 14:36:24 +01:00
|
|
|
from zerver.lib.hotspots import (
|
|
|
|
ALL_HOTSPOTS,
|
|
|
|
INTRO_HOTSPOTS,
|
|
|
|
NON_INTRO_HOTSPOTS,
|
|
|
|
ONE_TIME_NOTICES,
|
|
|
|
get_next_onboarding_steps,
|
|
|
|
)
|
2017-01-24 01:48:35 +01:00
|
|
|
from zerver.lib.test_classes import ZulipTestCase
|
2023-12-15 02:14:24 +01:00
|
|
|
from zerver.models import OnboardingStep, UserProfile
|
|
|
|
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_first_hotspot(self) -> None:
|
2023-12-01 14:36:24 +01:00
|
|
|
for hotspot in NON_INTRO_HOTSPOTS: # nocoverage
|
|
|
|
do_mark_onboarding_step_as_read(self.user, hotspot.name)
|
|
|
|
|
|
|
|
for one_time_notice in ONE_TIME_NOTICES: # nocoverage
|
|
|
|
do_mark_onboarding_step_as_read(self.user, one_time_notice.name)
|
|
|
|
|
|
|
|
hotspots = get_next_onboarding_steps(self.user)
|
2021-05-17 05:41:32 +02:00
|
|
|
self.assert_length(hotspots, 1)
|
2021-12-07 15:43:26 +01:00
|
|
|
self.assertEqual(hotspots[0]["name"], "intro_streams")
|
2017-01-24 01:48:35 +01:00
|
|
|
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_some_done_some_not(self) -> None:
|
2023-12-01 11:52:41 +01:00
|
|
|
do_mark_onboarding_step_as_read(self.user, "intro_streams")
|
|
|
|
do_mark_onboarding_step_as_read(self.user, "intro_compose")
|
2023-12-01 14:36:24 +01:00
|
|
|
onboarding_steps = get_next_onboarding_steps(self.user)
|
2024-03-05 13:18:56 +01:00
|
|
|
self.assert_length(onboarding_steps, 4)
|
2023-12-02 13:34:05 +01:00
|
|
|
self.assertEqual(onboarding_steps[0]["name"], "visibility_policy_banner")
|
2024-03-05 12:03:05 +01:00
|
|
|
self.assertEqual(onboarding_steps[1]["name"], "intro_inbox_view_modal")
|
2024-03-05 13:18:56 +01:00
|
|
|
self.assertEqual(onboarding_steps[2]["name"], "intro_recent_view_modal")
|
|
|
|
self.assertEqual(onboarding_steps[3]["name"], "intro_topics")
|
2017-01-24 01:48:35 +01:00
|
|
|
|
2023-12-01 14:36:24 +01:00
|
|
|
def test_all_onboarding_steps_done(self) -> None:
|
2021-03-11 17:19:49 +01:00
|
|
|
with self.settings(TUTORIAL_ENABLED=True):
|
2021-05-08 11:00:12 +02:00
|
|
|
self.assertNotEqual(self.user.tutorial_status, UserProfile.TUTORIAL_FINISHED)
|
2023-04-09 16:48:08 +02:00
|
|
|
for hotspot in NON_INTRO_HOTSPOTS: # nocoverage
|
2023-12-01 11:52:41 +01:00
|
|
|
do_mark_onboarding_step_as_read(self.user, hotspot.name)
|
2021-05-08 11:00:12 +02:00
|
|
|
|
2023-12-01 14:36:24 +01:00
|
|
|
self.assertNotEqual(self.user.tutorial_status, UserProfile.TUTORIAL_FINISHED)
|
|
|
|
for one_time_notice in ONE_TIME_NOTICES: # nocoverage
|
|
|
|
do_mark_onboarding_step_as_read(self.user, one_time_notice.name)
|
|
|
|
|
2021-03-11 17:19:49 +01:00
|
|
|
self.assertNotEqual(self.user.tutorial_status, UserProfile.TUTORIAL_FINISHED)
|
|
|
|
for hotspot in INTRO_HOTSPOTS:
|
2023-12-01 11:52:41 +01:00
|
|
|
do_mark_onboarding_step_as_read(self.user, hotspot.name)
|
2021-05-08 11:00:12 +02:00
|
|
|
|
2021-03-11 17:19:49 +01:00
|
|
|
self.assertEqual(self.user.tutorial_status, UserProfile.TUTORIAL_FINISHED)
|
2023-12-01 14:36:24 +01:00
|
|
|
self.assertEqual(get_next_onboarding_steps(self.user), [])
|
2017-01-24 01:48:35 +01:00
|
|
|
|
2023-12-01 14:36:24 +01:00
|
|
|
def test_send_all_hotspots(self) -> None:
|
2021-02-12 08:19:30 +01:00
|
|
|
with self.settings(DEVELOPMENT=True, ALWAYS_SEND_ALL_HOTSPOTS=True):
|
2023-12-01 14:36:24 +01:00
|
|
|
self.assert_length(ALL_HOTSPOTS, len(get_next_onboarding_steps(self.user)))
|
2018-03-18 20:59:10 +01:00
|
|
|
|
2021-03-11 17:19:49 +01:00
|
|
|
def test_tutorial_disabled(self) -> None:
|
|
|
|
with self.settings(TUTORIAL_ENABLED=False):
|
2023-12-01 14:36:24 +01: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):
|
|
|
|
def test_do_mark_onboarding_step_as_read(self) -> None:
|
2021-02-12 08:20:45 +01:00
|
|
|
user = self.example_user("hamlet")
|
2023-12-01 11:52:41 +01:00
|
|
|
do_mark_onboarding_step_as_read(user, "intro_compose")
|
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)
|
|
|
|
),
|
2021-02-12 08:20:45 +01:00
|
|
|
["intro_compose"],
|
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(
|
|
|
|
"/json/users/me/onboarding_steps", {"onboarding_step": "intro_streams"}
|
|
|
|
)
|
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)
|
|
|
|
),
|
2021-12-07 15:43:26 +01:00
|
|
|
["intro_streams"],
|
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)
|
|
|
|
),
|
2021-12-07 15:43:26 +01:00
|
|
|
["intro_streams"],
|
2021-02-12 08:19:30 +01:00
|
|
|
)
|