| 1 |
# vim:fileencoding=utf-8 |
| 2 |
# License: GPL v3 Copyright: 2026, Kovid Goyal <kovid at kovidgoyal.net> |
| 3 |
from __python__ import hash_literals |
| 4 |
|
| 5 |
from book_list.sidebar import create_sidebar |
| 6 |
from book_list.ui_settings import get_ui_prefs |
| 7 |
from session import session_defaults |
| 8 |
from test_book_list_helpers import with_empty_session |
| 9 |
from testing import assert_equal, assert_false, assert_true, test |
| 10 |
from utils import parse_url_params |
| 11 |
|
| 12 |
|
| 13 |
@test |
| 14 |
def viewer_sidebar_setting_contract(): |
| 15 |
names = [x.name for x in get_ui_prefs()] |
| 16 |
assert_true(names.indexOf('show_sidebar_in_book_viewer') > -1) |
| 17 |
assert_equal(names.indexOf('show_sidebar_in_viewer'), -1) |
| 18 |
assert_equal(session_defaults().show_sidebar_in_book_viewer, False) |
| 19 |
assert_false(Object.prototype.hasOwnProperty.call(session_defaults(), 'show_sidebar_in_viewer')) |
| 20 |
|
| 21 |
|
| 22 |
@test |
| 23 |
def viewer_sidebar_setting_controls_reader_visibility(): |
| 24 |
def run(sd): |
| 25 |
previous_url = window.location.href |
| 26 |
previous_update_active = window.cs_update_sidebar_active |
| 27 |
previous_refresh = window.cs_refresh_sidebar_navigation |
| 28 |
try: |
| 29 |
sd.set('show_sidebar_in_book_viewer', False) |
| 30 |
window.history.replaceState(None, '', '#mode=read_book') |
| 31 |
parse_url_params.cache = {} |
| 32 |
root, left = create_sidebar() |
| 33 |
root |
| 34 |
assert_equal(left.style.display, 'none') |
| 35 |
|
| 36 |
sd.set('show_sidebar_in_book_viewer', True) |
| 37 |
window.cs_update_sidebar_active() |
| 38 |
assert_equal(left.style.display, 'flex') |
| 39 |
|
| 40 |
sd.set('show_sidebar_in_book_viewer', False) |
| 41 |
window.history.replaceState(None, '', '#mode=book_list') |
| 42 |
parse_url_params.cache = {} |
| 43 |
window.cs_update_sidebar_active() |
| 44 |
assert_equal(left.style.display, 'flex') |
| 45 |
finally: |
| 46 |
window.history.replaceState(None, '', previous_url) |
| 47 |
parse_url_params.cache = {} |
| 48 |
window.cs_update_sidebar_active = previous_update_active |
| 49 |
window.cs_refresh_sidebar_navigation = previous_refresh |
| 50 |
|
| 51 |
with_empty_session(run) |