1
|
# SPDX-License-Identifier: CC0-1.0
|
2
|
|
3
|
"""
|
4
|
Haketilo unit tests - entire settings page
|
5
|
"""
|
6
|
|
7
|
# This file is part of Haketilo
|
8
|
#
|
9
|
# Copyright (C) 2022 Wojtek Kosior <koszko@koszko.org>
|
10
|
#
|
11
|
# This program is free software: you can redistribute it and/or modify
|
12
|
# it under the terms of the CC0 1.0 Universal License as published by
|
13
|
# the Creative Commons Corporation.
|
14
|
#
|
15
|
# This program is distributed in the hope that it will be useful,
|
16
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
17
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
18
|
# CC0 1.0 Universal License for more details.
|
19
|
|
20
|
import pytest
|
21
|
from .utils import *
|
22
|
|
23
|
from ..extension_crafting import ExtraHTML
|
24
|
from ..script_loader import load_script
|
25
|
from .utils import *
|
26
|
|
27
|
@pytest.mark.ext_data({
|
28
|
'background_script': broker_js,
|
29
|
'extra_html': ExtraHTML('html/settings.html', wrap_into_htmldoc=False)
|
30
|
})
|
31
|
@pytest.mark.usefixtures('webextension')
|
32
|
def test_settings_page_tabs(driver, execute_in_page):
|
33
|
"""
|
34
|
Test navigation throught the tabs of the settings page.
|
35
|
"""
|
36
|
# First, put some sample data in IndexedDB.
|
37
|
execute_in_page(load_script('common/indexeddb.js'))
|
38
|
execute_in_page(
|
39
|
'''
|
40
|
initial_data = arguments[0];
|
41
|
returnval(get_db().then(() => {}));
|
42
|
''',
|
43
|
make_complete_sample_data())
|
44
|
|
45
|
# Now navigate to settings page.
|
46
|
testpage_url = driver.execute_script('return window.location.href;')
|
47
|
driver.get(testpage_url.replace('testpage.html', 'html/settings.html'))
|
48
|
|
49
|
names = ['blocking', 'mappings', 'resources', 'new_payload', 'repos']
|
50
|
tabs = dict([(n, driver.find_element_by_id(f'{n}_tab')) for n in names])
|
51
|
heads = dict([(n, driver.find_element_by_id(f'{n}_head')) for n in names])
|
52
|
|
53
|
for i, tab_name in enumerate(['new_payload', *names]):
|
54
|
if (i > 0):
|
55
|
heads[tab_name].click()
|
56
|
|
57
|
assert 'active_head' in heads[tab_name].get_attribute('class')
|
58
|
assert 'active_tab' in tabs[tab_name].get_attribute('class')
|
59
|
assert tabs[tab_name].is_displayed()
|
60
|
for tab_name_2 in [n for n in names if n != tab_name]:
|
61
|
assert 'active_head' not in heads[tab_name_2].get_attribute('class')
|
62
|
assert 'active_tab' not in tabs[tab_name_2].get_attribute('class')
|
63
|
assert not tabs[tab_name_2].is_displayed()
|