diff options
Diffstat (limited to 'tests/unit/mainwindow/statusbar/test_backforward.py')
-rw-r--r-- | tests/unit/mainwindow/statusbar/test_backforward.py | 71 |
1 files changed, 44 insertions, 27 deletions
diff --git a/tests/unit/mainwindow/statusbar/test_backforward.py b/tests/unit/mainwindow/statusbar/test_backforward.py index d3e033b34..ac73f8ee1 100644 --- a/tests/unit/mainwindow/statusbar/test_backforward.py +++ b/tests/unit/mainwindow/statusbar/test_backforward.py @@ -31,55 +31,72 @@ def backforward_widget(qtbot): return widget +@pytest.fixture +def tabs(tabbed_browser_stubs): + tabbed_browser = tabbed_browser_stubs[0] + tabbed_browser.widget.current_index = 1 + return tabbed_browser + + @pytest.mark.parametrize('can_go_back, can_go_forward, expected_text', [ (False, False, ''), (True, False, '[<]'), (False, True, '[>]'), (True, True, '[<>]'), ]) -def test_backforward_widget(backforward_widget, tabbed_browser_stubs, - fake_web_tab, can_go_back, can_go_forward, - expected_text): +def test_widget_state(backforward_widget, tabs, + fake_web_tab, can_go_back, can_go_forward, + expected_text): """Ensure the Backforward widget shows the correct text.""" tab = fake_web_tab(can_go_back=can_go_back, can_go_forward=can_go_forward) - tabbed_browser = tabbed_browser_stubs[0] - tabbed_browser.widget.current_index = 1 - tabbed_browser.widget.tabs = [tab] + tabs.widget.tabs = [tab] backforward_widget.enabled = True - backforward_widget.on_tab_cur_url_changed(tabbed_browser) + backforward_widget.on_tab_cur_url_changed(tabs) assert backforward_widget.text() == expected_text assert backforward_widget.isVisible() == bool(expected_text) - # Check that the widget stays hidden if not in the statusbar - backforward_widget.enabled = False - backforward_widget.hide() - backforward_widget.on_tab_cur_url_changed(tabbed_browser) - assert backforward_widget.isHidden() - # Check that the widget gets reset if empty. - if can_go_back and can_go_forward: - tab = fake_web_tab(can_go_back=False, can_go_forward=False) - tabbed_browser.widget.tabs = [tab] - backforward_widget.enabled = True - backforward_widget.on_tab_cur_url_changed(tabbed_browser) - assert backforward_widget.text() == '' - assert not backforward_widget.isVisible() +def test_state_changes_on_tab_change(backforward_widget, tabs, fake_web_tab): + """Test we go invisible when switching to a tab without history.""" + tab_with_history = fake_web_tab(can_go_back=True, can_go_forward=True) + tab_without_history = fake_web_tab(can_go_back=False, can_go_forward=False) + tabs.widget.tabs = [tab_with_history] + backforward_widget.enabled = True + + backforward_widget.on_tab_cur_url_changed(tabs) + assert backforward_widget.isVisible() + + tabs.widget.tabs = [tab_without_history] + backforward_widget.on_tab_cur_url_changed(tabs) + assert backforward_widget.text() == '' + assert not backforward_widget.isVisible() -def test_none_tab(backforward_widget, tabbed_browser_stubs, fake_web_tab): +def test_none_tab(backforward_widget, tabs, fake_web_tab): """Make sure nothing crashes when passing None as tab.""" tab = fake_web_tab(can_go_back=True, can_go_forward=True) - tabbed_browser = tabbed_browser_stubs[0] - tabbed_browser.widget.current_index = 1 - tabbed_browser.widget.tabs = [tab] + tabs.widget.tabs = [tab] backforward_widget.enabled = True - backforward_widget.on_tab_cur_url_changed(tabbed_browser) + backforward_widget.on_tab_cur_url_changed(tabs) assert backforward_widget.text() == '[<>]' assert backforward_widget.isVisible() - tabbed_browser.widget.current_index = -1 - backforward_widget.on_tab_cur_url_changed(tabbed_browser) + tabs.widget.current_index = -1 + backforward_widget.on_tab_cur_url_changed(tabs) assert backforward_widget.text() == '' assert not backforward_widget.isVisible() + + +def test_not_shown_when_disabled(backforward_widget, tabs, fake_web_tab): + """The widget shouldn't get shown on an event when it's disabled.""" + tab = fake_web_tab(can_go_back=True, can_go_forward=True) + tabs.widget.tabs = [tab] + + backforward_widget.enabled = False + backforward_widget.on_tab_cur_url_changed(tabs) + assert not backforward_widget.isVisible() + + backforward_widget.on_tab_changed(tab) + assert not backforward_widget.isVisible() |