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 = (
|
2024-07-09 09:00:30 +02:00
|
|
|
"You can switch between [light and dark theme](/help/dark-theme), "
|
|
|
|
"[pick your favorite emoji set](/help/emoji-and-emoticons#change-your-emoji-set), "
|
|
|
|
"[change your language](/help/change-your-language), and otherwise customize "
|
|
|
|
"your Zulip experience in your [Preferences](#settings/preferences)."
|
2021-10-16 10:29:21 +02:00
|
|
|
)
|
|
|
|
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-07-09 09:00:30 +02:00
|
|
|
"Channels organize conversations based on who needs to see them. "
|
|
|
|
"For example, it's common to have a channel for each team in an organization.\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-07-09 09:00:30 +02:00
|
|
|
"[Topics](/help/introduction-to-topics) summarize what each conversation in Zulip "
|
|
|
|
"is about. You can read Zulip one topic at a time, seeing each message in context, "
|
|
|
|
"no matter how many other conversations are going on.\n\n"
|
|
|
|
"When you start a conversation, label it with a new topic. For a good topic name, "
|
|
|
|
"think about finishing the sentence: “Hey, can we chat about…?”\n\n"
|
|
|
|
"Check out [Recent conversations](#recent) for a list of topics that are being discussed."
|
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 = (
|
2024-07-09 09:00:30 +02:00
|
|
|
"You can **format** *your* `message` using the handy formatting "
|
|
|
|
"buttons, or by typing your formatting with Markdown.\n\n"
|
|
|
|
"Check out the [cheat sheet](#message-formatting) to learn about "
|
|
|
|
"spoilers, global times, and more."
|
2021-10-16 10:29:21 +02:00
|
|
|
)
|
|
|
|
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)
|
2024-06-25 02:31:15 +02:00
|
|
|
# First undefined message sent.
|
|
|
|
self.send_personal_message(user, bot, "Hello")
|
|
|
|
expected_response = (
|
|
|
|
"You can chat with me as much as you like! To get help, try one of the following messages: "
|
|
|
|
"`apps`, `profile`, `theme`, `channels`, "
|
|
|
|
"`topics`, `message formatting`, `keyboard shortcuts`, `help`."
|
|
|
|
)
|
|
|
|
self.assertEqual(most_recent_message(user).content, expected_response)
|
|
|
|
|
|
|
|
# For future undefined messages, welcome bot won't send a reply.
|
2021-10-16 10:29:21 +02:00
|
|
|
for content in messages:
|
|
|
|
self.send_personal_message(user, bot, content)
|
2024-06-25 02:31:15 +02:00
|
|
|
self.assertEqual(most_recent_message(user).content, content)
|
|
|
|
|
|
|
|
# Check if Welcome bot still replies for bot commands
|
|
|
|
self.send_personal_message(user, bot, "apps")
|
|
|
|
expected_response = (
|
|
|
|
"You can [download](/apps/) the [mobile and desktop apps](/apps/). "
|
|
|
|
"Zulip also works great in a browser."
|
|
|
|
)
|
|
|
|
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)
|
2024-07-04 14:05:48 +02:00
|
|
|
self.send_group_direct_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)
|