2019-07-15 21:29:47 +02:00
|
|
|
|
from django.conf import settings
|
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
|
2020-06-11 00:54:34 +02:00
|
|
|
|
from zerver.models import UserProfile, get_system_bot
|
2017-09-27 19:43:28 +02:00
|
|
|
|
|
2016-09-15 18:45:04 +02:00
|
|
|
|
|
|
|
|
|
class TutorialTests(ZulipTestCase):
|
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."
|
2021-02-18 19:58:04 +01:00
|
|
|
|
internal_send_private_message(welcome_bot, user, content)
|
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 = (
|
|
|
|
|
"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)
|
|
|
|
|
|
|
|
|
|
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 = (
|
|
|
|
|
"Go to [Display settings](#settings/display-settings) "
|
|
|
|
|
"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 = (
|
|
|
|
|
"In Zulip, streams [determine who gets a message](/help/streams-and-topics). "
|
|
|
|
|
"They are similar to channels in other chat apps.\n\n"
|
|
|
|
|
"[Browse and subscribe to streams](#streams/all)."
|
|
|
|
|
)
|
|
|
|
|
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 = (
|
|
|
|
|
"In Zulip, topics [tell you what a message is about](/help/streams-and-topics). "
|
|
|
|
|
"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! "
|
2021-10-16 10:29:21 +02:00
|
|
|
|
'You can return to this conversation by clicking "Private messages" in the upper left.'
|
|
|
|
|
)
|
|
|
|
|
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`, "
|
2021-10-16 10:29:21 +02:00
|
|
|
|
"`streams`, `topics`, `message formatting`, `keyboard shortcuts`.\n\n"
|
|
|
|
|
"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: "
|
2021-12-02 08:15:17 +01:00
|
|
|
|
"`apps`, `profile`, `theme`, `streams`, "
|
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)
|
|
|
|
|
# Welcome bot should still respond to initial PM after group PM.
|
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)
|