2019-07-15 21:29:47 +02:00
|
|
|
|
from django.conf import settings
|
2023-10-12 19:43:45 +02:00
|
|
|
|
from typing_extensions import override
|
2016-09-15 18:45:04 +02:00
|
|
|
|
|
2022-04-14 23:50:10 +02:00
|
|
|
|
from zerver.actions.message_send import internal_send_private_message
|
2017-09-27 19:43:28 +02:00
|
|
|
|
from zerver.lib.test_classes import ZulipTestCase
|
|
|
|
|
from zerver.lib.test_helpers import message_stream_count, most_recent_message
|
2023-12-15 01:16:00 +01:00
|
|
|
|
from zerver.models import UserProfile
|
|
|
|
|
from zerver.models.users import get_system_bot
|
2017-09-27 19:43:28 +02:00
|
|
|
|
|
2016-09-15 18:45:04 +02:00
|
|
|
|
|
|
|
|
|
class TutorialTests(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-09-27 19:43:28 +02:00
|
|
|
|
# This emulates the welcome message sent by the welcome bot to hamlet@zulip.com
|
|
|
|
|
# This is only a quick fix - ideally, we would have this message sent by the initialization
|
|
|
|
|
# code in populate_db.py
|
2021-02-12 08:20:45 +01:00
|
|
|
|
user = self.example_user("hamlet")
|
2021-03-08 11:54:39 +01:00
|
|
|
|
welcome_bot = get_system_bot(settings.WELCOME_BOT, user.realm_id)
|
2021-02-12 08:20:45 +01:00
|
|
|
|
content = "Shortened welcome message."
|
2022-10-22 13:25:06 +02:00
|
|
|
|
internal_send_private_message(
|
|
|
|
|
welcome_bot,
|
|
|
|
|
user,
|
|
|
|
|
content,
|
|
|
|
|
# disable_external_notifications set to False will still lead
|
|
|
|
|
# the tests to pass. Setting this to True, because we contextually
|
|
|
|
|
# set this to true for welcome_bot in the codebase.
|
|
|
|
|
disable_external_notifications=True,
|
|
|
|
|
)
|
2017-09-27 19:43:28 +02:00
|
|
|
|
|
2017-11-05 10:51:25 +01:00
|
|
|
|
def test_tutorial_status(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)
|
2016-09-15 18:45:04 +02:00
|
|
|
|
|
|
|
|
|
cases = [
|
2021-02-12 08:20:45 +01:00
|
|
|
|
("started", UserProfile.TUTORIAL_STARTED),
|
|
|
|
|
("finished", UserProfile.TUTORIAL_FINISHED),
|
2016-09-15 18:45:04 +02:00
|
|
|
|
]
|
|
|
|
|
for incoming_status, expected_db_status in cases:
|
2021-05-04 16:59:17 +02:00
|
|
|
|
params = dict(status=incoming_status)
|
2021-02-12 08:20:45 +01:00
|
|
|
|
result = self.client_post("/json/users/me/tutorial_status", params)
|
2016-09-15 18:45:04 +02:00
|
|
|
|
self.assert_json_success(result)
|
2021-02-12 08:20:45 +01:00
|
|
|
|
user = self.example_user("hamlet")
|
2016-09-15 18:45:04 +02:00
|
|
|
|
self.assertEqual(user.tutorial_status, expected_db_status)
|
2017-09-27 19:43:28 +02:00
|
|
|
|
|
2021-10-16 10:29:21 +02:00
|
|
|
|
def test_response_to_pm_for_app(self) -> None:
|
2021-02-12 08:20:45 +01:00
|
|
|
|
user = self.example_user("hamlet")
|
2021-03-08 11:54:39 +01:00
|
|
|
|
bot = get_system_bot(settings.WELCOME_BOT, user.realm_id)
|
2021-10-16 10:29:21 +02:00
|
|
|
|
messages = ["app", "Apps"]
|
|
|
|
|
self.login_user(user)
|
|
|
|
|
for content in messages:
|
|
|
|
|
self.send_personal_message(user, bot, content)
|
|
|
|
|
expected_response = (
|
2023-03-23 03:59:33 +01:00
|
|
|
|
"You can [download](/apps/) the [mobile and desktop apps](/apps/). "
|
2021-10-16 10:29:21 +02:00
|
|
|
|
"Zulip also works great in a browser."
|
|
|
|
|
)
|
|
|
|
|
self.assertEqual(most_recent_message(user).content, expected_response)
|
|
|
|
|
|
|
|
|
|
def test_response_to_pm_for_edit(self) -> None:
|
|
|
|
|
user = self.example_user("hamlet")
|
|
|
|
|
bot = get_system_bot(settings.WELCOME_BOT, user.realm_id)
|
|
|
|
|
messages = ["profile", "Profile"]
|
|
|
|
|
self.login_user(user)
|
|
|
|
|
for content in messages:
|
|
|
|
|
self.send_personal_message(user, bot, content)
|
|
|
|
|
expected_response = (
|
|
|
|
|
"Go to [Profile settings](#settings/profile) "
|
|
|
|
|
"to add a [profile picture](/help/change-your-profile-picture) "
|
|
|
|
|
"and edit your [profile information](/help/edit-your-profile)."
|
|
|
|
|
)
|
|
|
|
|
self.assertEqual(most_recent_message(user).content, expected_response)
|
|
|
|
|
|
|
|
|
|
def test_response_to_pm_for_theme(self) -> None:
|
|
|
|
|
user = self.example_user("hamlet")
|
|
|
|
|
bot = get_system_bot(settings.WELCOME_BOT, user.realm_id)
|
|
|
|
|
messages = ["theme", "Theme"]
|
|
|
|
|
self.login_user(user)
|
|
|
|
|
for content in messages:
|
|
|
|
|
self.send_personal_message(user, bot, content)
|
|
|
|
|
expected_response = (
|
2023-06-29 15:28:38 +02:00
|
|
|
|
"Go to [Preferences](#settings/preferences) "
|
2021-10-16 10:29:21 +02:00
|
|
|
|
"to [switch between the light and dark themes](/help/dark-theme), "
|
|
|
|
|
"[pick your favorite emoji theme](/help/emoji-and-emoticons#change-your-emoji-set), "
|
|
|
|
|
"[change your language](/help/change-your-language), and make other tweaks to your Zulip experience."
|
|
|
|
|
)
|
|
|
|
|
self.assertEqual(most_recent_message(user).content, expected_response)
|
|
|
|
|
|
|
|
|
|
def test_response_to_pm_for_stream(self) -> None:
|
|
|
|
|
user = self.example_user("hamlet")
|
|
|
|
|
bot = get_system_bot(settings.WELCOME_BOT, user.realm_id)
|
|
|
|
|
messages = ["Streams", "streams", "channels"]
|
|
|
|
|
self.login_user(user)
|
|
|
|
|
for content in messages:
|
|
|
|
|
self.send_personal_message(user, bot, content)
|
|
|
|
|
expected_response = (
|
2024-05-06 21:25:38 +02:00
|
|
|
|
"In Zulip, channels [determine who gets a message](/help/introduction-to-channels).\n\n"
|
2024-04-30 13:30:24 +02:00
|
|
|
|
"[Browse and subscribe to channels](#channels/all)."
|
2021-10-16 10:29:21 +02:00
|
|
|
|
)
|
|
|
|
|
self.assertEqual(most_recent_message(user).content, expected_response)
|
|
|
|
|
|
|
|
|
|
def test_response_to_pm_for_topic(self) -> None:
|
|
|
|
|
user = self.example_user("hamlet")
|
|
|
|
|
bot = get_system_bot(settings.WELCOME_BOT, user.realm_id)
|
|
|
|
|
messages = ["Topics", "topics"]
|
|
|
|
|
self.login_user(user)
|
|
|
|
|
for content in messages:
|
|
|
|
|
self.send_personal_message(user, bot, content)
|
|
|
|
|
expected_response = (
|
2024-05-07 09:51:46 +02:00
|
|
|
|
"In Zulip, topics [tell you what a message is about](/help/introduction-to-topics). "
|
2021-10-16 10:29:21 +02:00
|
|
|
|
"They are light-weight subjects, very similar to the subject line of an email.\n\n"
|
2022-10-24 12:18:09 +02:00
|
|
|
|
"Check out [Recent conversations](#recent) to see what's happening! "
|
2023-01-24 15:36:03 +01:00
|
|
|
|
'You can return to this conversation by clicking "Direct messages" in the upper left.'
|
2021-10-16 10:29:21 +02:00
|
|
|
|
)
|
|
|
|
|
self.assertEqual(most_recent_message(user).content, expected_response)
|
|
|
|
|
|
|
|
|
|
def test_response_to_pm_for_shortcuts(self) -> None:
|
|
|
|
|
user = self.example_user("hamlet")
|
|
|
|
|
bot = get_system_bot(settings.WELCOME_BOT, user.realm_id)
|
|
|
|
|
messages = ["Keyboard shortcuts", "shortcuts", "Shortcuts"]
|
|
|
|
|
self.login_user(user)
|
|
|
|
|
for content in messages:
|
|
|
|
|
self.send_personal_message(user, bot, content)
|
|
|
|
|
expected_response = (
|
|
|
|
|
"Zulip's [keyboard shortcuts](#keyboard-shortcuts) "
|
|
|
|
|
"let you navigate the app quickly and efficiently.\n\n"
|
|
|
|
|
"Press `?` any time to see a [cheat sheet](#keyboard-shortcuts)."
|
|
|
|
|
)
|
|
|
|
|
self.assertEqual(most_recent_message(user).content, expected_response)
|
|
|
|
|
|
|
|
|
|
def test_response_to_pm_for_formatting(self) -> None:
|
|
|
|
|
user = self.example_user("hamlet")
|
|
|
|
|
bot = get_system_bot(settings.WELCOME_BOT, user.realm_id)
|
|
|
|
|
messages = ["message formatting", "Formatting"]
|
|
|
|
|
self.login_user(user)
|
|
|
|
|
for content in messages:
|
|
|
|
|
self.send_personal_message(user, bot, content)
|
|
|
|
|
expected_response = (
|
|
|
|
|
"Zulip uses [Markdown](/help/format-your-message-using-markdown), "
|
|
|
|
|
"an intuitive format for **bold**, *italics*, bulleted lists, and more. "
|
|
|
|
|
"Click [here](#message-formatting) for a cheat sheet.\n\n"
|
|
|
|
|
"Check out our [messaging tips](/help/messaging-tips) to learn about emoji reactions, "
|
|
|
|
|
"code blocks and much more!"
|
|
|
|
|
)
|
|
|
|
|
self.assertEqual(most_recent_message(user).content, expected_response)
|
|
|
|
|
|
|
|
|
|
def test_response_to_pm_for_help(self) -> None:
|
|
|
|
|
user = self.example_user("hamlet")
|
|
|
|
|
bot = get_system_bot(settings.WELCOME_BOT, user.realm_id)
|
|
|
|
|
messages = ["help", "Help", "?"]
|
|
|
|
|
self.login_user(user)
|
|
|
|
|
for content in messages:
|
|
|
|
|
self.send_personal_message(user, bot, content)
|
|
|
|
|
expected_response = (
|
|
|
|
|
"Here are a few messages I understand: "
|
2021-12-02 08:15:17 +01:00
|
|
|
|
"`apps`, `profile`, `theme`, "
|
2024-04-17 15:37:13 +02:00
|
|
|
|
"`channels`, `topics`, `message formatting`, `keyboard shortcuts`.\n\n"
|
2021-10-16 10:29:21 +02:00
|
|
|
|
"Check out our [Getting started guide](/help/getting-started-with-zulip), "
|
|
|
|
|
"or browse the [Help center](/help/) to learn more!"
|
|
|
|
|
)
|
|
|
|
|
self.assertEqual(most_recent_message(user).content, expected_response)
|
|
|
|
|
|
|
|
|
|
def test_response_to_pm_for_undefined(self) -> None:
|
|
|
|
|
user = self.example_user("hamlet")
|
|
|
|
|
bot = get_system_bot(settings.WELCOME_BOT, user.realm_id)
|
|
|
|
|
messages = ["Hello", "HAHAHA", "OKOK", "LalulaLapas"]
|
2020-03-06 18:40:46 +01:00
|
|
|
|
self.login_user(user)
|
2021-10-16 10:29:21 +02:00
|
|
|
|
for content in messages:
|
|
|
|
|
self.send_personal_message(user, bot, content)
|
|
|
|
|
expected_response = (
|
|
|
|
|
"I’m sorry, I did not understand your message. Please try one of the following commands: "
|
2024-04-17 15:37:13 +02:00
|
|
|
|
"`apps`, `profile`, `theme`, `channels`, "
|
2021-12-06 19:55:22 +01:00
|
|
|
|
"`topics`, `message formatting`, `keyboard shortcuts`, `help`."
|
2021-10-16 10:29:21 +02:00
|
|
|
|
)
|
|
|
|
|
self.assertEqual(most_recent_message(user).content, expected_response)
|
2017-09-27 19:43:28 +02:00
|
|
|
|
|
2017-11-05 10:51:25 +01:00
|
|
|
|
def test_no_response_to_group_pm(self) -> None:
|
2021-02-12 08:20:45 +01:00
|
|
|
|
user1 = self.example_user("hamlet")
|
|
|
|
|
user2 = self.example_user("cordelia")
|
2021-03-08 11:54:39 +01:00
|
|
|
|
bot = get_system_bot(settings.WELCOME_BOT, user1.realm_id)
|
2017-09-27 19:43:28 +02:00
|
|
|
|
content = "whatever"
|
2020-03-06 18:40:46 +01:00
|
|
|
|
self.login_user(user1)
|
2020-03-07 11:43:05 +01:00
|
|
|
|
self.send_huddle_message(user1, [bot, user2], content)
|
2017-09-27 19:43:28 +02:00
|
|
|
|
user1_messages = message_stream_count(user1)
|
|
|
|
|
self.assertEqual(most_recent_message(user1).content, content)
|
2023-06-19 16:26:12 +02:00
|
|
|
|
# Welcome bot should still respond to initial direct message
|
|
|
|
|
# after group direct message.
|
2020-03-07 11:43:05 +01:00
|
|
|
|
self.send_personal_message(user1, bot, content)
|
2021-02-12 08:19:30 +01:00
|
|
|
|
self.assertEqual(message_stream_count(user1), user1_messages + 2)
|