Files
zulip/zerver/tests/test_zcommand.py
MariaGkoulta b10f156250 settings: Add automatic theme detection feature.
With this implementation of the feature of the automatic theme
detection, we make the following changes in the backend, frontend and
documentation.

This replaces the previous night_mode boolean with an enum, with the
default value being to use the prefers-color-scheme feature of the
operating system to determine which theme to use.

Fixes: #14451.

Co-authored-by: @kPerikou <44238834+kPerikou@users.noreply.github.com>
2020-06-21 01:09:01 -07:00

84 lines
3.0 KiB
Python

from zerver.lib.test_classes import ZulipTestCase
from zerver.models import UserProfile
class ZcommandTest(ZulipTestCase):
def test_invalid_zcommand(self) -> None:
self.login('hamlet')
payload = dict(command="/boil-ocean")
result = self.client_post("/json/zcommand", payload)
self.assert_json_error(result, "No such command: boil-ocean")
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.")
def test_ping_zcommand(self) -> None:
self.login('hamlet')
payload = dict(command="/ping")
result = self.client_post("/json/zcommand", payload)
self.assert_json_success(result)
def test_night_zcommand(self) -> None:
self.login('hamlet')
user = self.example_user('hamlet')
user.color_scheme = UserProfile.COLOR_SCHEME_LIGHT
user.save()
payload = dict(command="/night")
result = self.client_post("/json/zcommand", payload)
self.assert_json_success(result)
self.assertIn('Changed to night', result.json()['msg'])
result = self.client_post("/json/zcommand", payload)
self.assert_json_success(result)
self.assertIn('still in night mode', result.json()['msg'])
def test_day_zcommand(self) -> None:
self.login('hamlet')
user = self.example_user('hamlet')
user.color_scheme = UserProfile.COLOR_SCHEME_NIGHT
user.save()
payload = dict(command="/day")
result = self.client_post("/json/zcommand", payload)
self.assert_json_success(result)
self.assertIn('Changed to day', result.json()['msg'])
result = self.client_post("/json/zcommand", payload)
self.assert_json_success(result)
self.assertIn('still in day mode', result.json()['msg'])
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)
self.assert_in_response('Changed to fluid-width mode!', result)
result = self.client_post("/json/zcommand", payload)
self.assert_json_success(result)
self.assert_in_response('You are still in fluid width mode', result)
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)
self.assert_in_response('Changed to fixed-width mode!', result)
result = self.client_post("/json/zcommand", payload)
self.assert_json_success(result)
self.assert_in_response('You are still in fixed width mode', result)