2020-06-11 00:54:34 +02:00
|
|
|
from zerver.lib.test_classes import ZulipTestCase
|
2020-05-16 13:13:59 +02:00
|
|
|
from zerver.models import UserProfile
|
2020-06-11 00:54:34 +02:00
|
|
|
|
2018-06-15 20:56:36 +02:00
|
|
|
|
|
|
|
class ZcommandTest(ZulipTestCase):
|
|
|
|
def test_invalid_zcommand(self) -> None:
|
2021-02-12 08:20:45 +01:00
|
|
|
self.login("hamlet")
|
2018-06-15 20:56:36 +02:00
|
|
|
|
2018-06-20 20:46:33 +02:00
|
|
|
payload = dict(command="/boil-ocean")
|
2018-06-15 20:56:36 +02:00
|
|
|
result = self.client_post("/json/zcommand", payload)
|
|
|
|
self.assert_json_error(result, "No such command: boil-ocean")
|
|
|
|
|
2018-06-21 19:23:35 +02:00
|
|
|
payload = dict(command="boil-ocean")
|
|
|
|
result = self.client_post("/json/zcommand", payload)
|
|
|
|
self.assert_json_error(result, "There should be a leading slash in the zcommand.")
|
|
|
|
|
2018-06-15 20:56:36 +02:00
|
|
|
def test_ping_zcommand(self) -> None:
|
2021-02-12 08:20:45 +01:00
|
|
|
self.login("hamlet")
|
2018-06-15 20:56:36 +02:00
|
|
|
|
2018-06-20 20:46:33 +02:00
|
|
|
payload = dict(command="/ping")
|
2018-06-15 20:56:36 +02:00
|
|
|
result = self.client_post("/json/zcommand", payload)
|
|
|
|
self.assert_json_success(result)
|
|
|
|
|
|
|
|
def test_night_zcommand(self) -> None:
|
2021-02-12 08:20:45 +01:00
|
|
|
self.login("hamlet")
|
|
|
|
user = self.example_user("hamlet")
|
2020-05-16 13:13:59 +02:00
|
|
|
user.color_scheme = UserProfile.COLOR_SCHEME_LIGHT
|
2018-06-15 20:56:36 +02:00
|
|
|
user.save()
|
|
|
|
|
2018-06-20 20:46:33 +02:00
|
|
|
payload = dict(command="/night")
|
2018-06-15 20:56:36 +02:00
|
|
|
result = self.client_post("/json/zcommand", payload)
|
2022-06-07 01:37:01 +02:00
|
|
|
response_dict = self.assert_json_success(result)
|
|
|
|
self.assertIn("Changed to dark theme", response_dict["msg"])
|
2018-06-15 20:56:36 +02:00
|
|
|
|
|
|
|
result = self.client_post("/json/zcommand", payload)
|
2022-06-07 01:37:01 +02:00
|
|
|
response_dict = self.assert_json_success(result)
|
|
|
|
self.assertIn("still in dark theme", response_dict["msg"])
|
2018-06-15 20:56:36 +02:00
|
|
|
|
|
|
|
def test_day_zcommand(self) -> None:
|
2021-02-12 08:20:45 +01:00
|
|
|
self.login("hamlet")
|
|
|
|
user = self.example_user("hamlet")
|
2020-05-16 13:13:59 +02:00
|
|
|
user.color_scheme = UserProfile.COLOR_SCHEME_NIGHT
|
2018-06-15 20:56:36 +02:00
|
|
|
user.save()
|
|
|
|
|
2018-06-20 20:46:33 +02:00
|
|
|
payload = dict(command="/day")
|
2018-06-15 20:56:36 +02:00
|
|
|
result = self.client_post("/json/zcommand", payload)
|
2022-06-07 01:37:01 +02:00
|
|
|
response_dict = self.assert_json_success(result)
|
|
|
|
self.assertIn("Changed to light theme", response_dict["msg"])
|
2018-06-15 20:56:36 +02:00
|
|
|
|
|
|
|
result = self.client_post("/json/zcommand", payload)
|
2022-06-07 01:37:01 +02:00
|
|
|
response_dict = self.assert_json_success(result)
|
|
|
|
self.assertIn("still in light theme", response_dict["msg"])
|
2020-03-12 07:51:47 +01:00
|
|
|
|
|
|
|
def test_fluid_zcommand(self) -> None:
|
|
|
|
self.login("hamlet")
|
|
|
|
user = self.example_user("hamlet")
|
|
|
|
user.fluid_layout_width = False
|
|
|
|
user.save()
|
|
|
|
|
|
|
|
payload = dict(command="/fluid-width")
|
|
|
|
result = self.client_post("/json/zcommand", payload)
|
|
|
|
self.assert_json_success(result)
|
2021-02-12 08:20:45 +01:00
|
|
|
self.assert_in_response("Changed to fluid-width mode!", result)
|
2020-03-12 07:51:47 +01:00
|
|
|
|
|
|
|
result = self.client_post("/json/zcommand", payload)
|
|
|
|
self.assert_json_success(result)
|
2021-02-12 08:20:45 +01:00
|
|
|
self.assert_in_response("You are still in fluid width mode", result)
|
2020-03-12 07:51:47 +01:00
|
|
|
|
|
|
|
def test_fixed_zcommand(self) -> None:
|
|
|
|
self.login("hamlet")
|
|
|
|
user = self.example_user("hamlet")
|
|
|
|
user.fluid_layout_width = True
|
|
|
|
user.save()
|
|
|
|
|
|
|
|
payload = dict(command="/fixed-width")
|
|
|
|
result = self.client_post("/json/zcommand", payload)
|
|
|
|
self.assert_json_success(result)
|
2021-02-12 08:20:45 +01:00
|
|
|
self.assert_in_response("Changed to fixed-width mode!", result)
|
2020-03-12 07:51:47 +01:00
|
|
|
|
|
|
|
result = self.client_post("/json/zcommand", payload)
|
|
|
|
self.assert_json_success(result)
|
2021-02-12 08:20:45 +01:00
|
|
|
self.assert_in_response("You are still in fixed width mode", result)
|