2022-04-14 23:33:30 +02:00
|
|
|
from zerver.actions.hotspots import do_mark_hotspot_as_read
|
|
|
|
from zerver.lib.actions import do_create_user
|
2021-02-18 15:17:03 +01:00
|
|
|
from zerver.lib.hotspots import ALL_HOTSPOTS, INTRO_HOTSPOTS, get_next_hotspots
|
2017-01-24 01:48:35 +01:00
|
|
|
from zerver.lib.test_classes import ZulipTestCase
|
2020-06-11 00:54:34 +02:00
|
|
|
from zerver.models import UserHotspot, UserProfile, get_realm
|
2017-01-24 01:48:35 +01:00
|
|
|
|
|
|
|
|
|
|
|
# Splitting this out, since I imagine this will eventually have most of the
|
|
|
|
# complicated hotspots logic.
|
|
|
|
class TestGetNextHotspots(ZulipTestCase):
|
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:
|
2017-08-31 18:20:03 +02:00
|
|
|
hotspots = get_next_hotspots(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:
|
2021-12-07 15:43:26 +01:00
|
|
|
do_mark_hotspot_as_read(self.user, "intro_streams")
|
2021-02-12 08:20:45 +01:00
|
|
|
do_mark_hotspot_as_read(self.user, "intro_compose")
|
2017-08-31 18:20:03 +02:00
|
|
|
hotspots = get_next_hotspots(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_topics")
|
2017-01-24 01:48:35 +01:00
|
|
|
|
2021-02-18 15:17:03 +01:00
|
|
|
def test_all_intro_hotspots_done(self) -> None:
|
2021-03-11 17:19:49 +01:00
|
|
|
with self.settings(TUTORIAL_ENABLED=True):
|
|
|
|
self.assertNotEqual(self.user.tutorial_status, UserProfile.TUTORIAL_FINISHED)
|
|
|
|
for hotspot in INTRO_HOTSPOTS:
|
|
|
|
do_mark_hotspot_as_read(self.user, hotspot)
|
|
|
|
self.assertEqual(self.user.tutorial_status, UserProfile.TUTORIAL_FINISHED)
|
|
|
|
self.assertEqual(get_next_hotspots(self.user), [])
|
2017-01-24 01:48:35 +01:00
|
|
|
|
2018-03-18 20:59:10 +01:00
|
|
|
def test_send_all(self) -> None:
|
2021-02-12 08:19:30 +01:00
|
|
|
with self.settings(DEVELOPMENT=True, ALWAYS_SEND_ALL_HOTSPOTS=True):
|
2021-05-17 05:41:32 +02:00
|
|
|
self.assert_length(ALL_HOTSPOTS, len(get_next_hotspots(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):
|
|
|
|
self.assertEqual(get_next_hotspots(self.user), [])
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2017-01-24 01:48:35 +01:00
|
|
|
class TestHotspots(ZulipTestCase):
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_do_mark_hotspot_as_read(self) -> None:
|
2021-02-12 08:20:45 +01:00
|
|
|
user = self.example_user("hamlet")
|
|
|
|
do_mark_hotspot_as_read(user, "intro_compose")
|
2021-02-12 08:19:30 +01:00
|
|
|
self.assertEqual(
|
2021-02-12 08:20:45 +01:00
|
|
|
list(UserHotspot.objects.filter(user=user).values_list("hotspot", flat=True)),
|
|
|
|
["intro_compose"],
|
2021-02-12 08:19:30 +01:00
|
|
|
)
|
2017-01-24 01:48:35 +01:00
|
|
|
|
2017-11-05 10:51:25 +01:00
|
|
|
def test_hotspots_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)
|
2021-12-07 15:43:26 +01:00
|
|
|
result = self.client_post("/json/users/me/hotspots", {"hotspot": "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(
|
2021-02-12 08:20:45 +01:00
|
|
|
list(UserHotspot.objects.filter(user=user).values_list("hotspot", 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
|
|
|
|
2021-05-04 09:54:27 +02:00
|
|
|
result = self.client_post("/json/users/me/hotspots", {"hotspot": "invalid"})
|
2017-03-29 23:04:25 +02:00
|
|
|
self.assert_json_error(result, "Unknown hotspot: invalid")
|
2021-02-12 08:19:30 +01:00
|
|
|
self.assertEqual(
|
2021-02-12 08:20:45 +01:00
|
|
|
list(UserHotspot.objects.filter(user=user).values_list("hotspot", flat=True)),
|
2021-12-07 15:43:26 +01:00
|
|
|
["intro_streams"],
|
2021-02-12 08:19:30 +01:00
|
|
|
)
|