diff options
author | Jimmy <jimmy@spalge.com> | 2018-09-01 18:37:18 +1200 |
---|---|---|
committer | Jimmy <jimmy@spalge.com> | 2020-02-13 20:59:57 +1300 |
commit | 832568af42d0e7d7d4bdc2d244c0d09e53e970c7 (patch) | |
tree | bb09795358fc7d87a0ac17921ac0b295d8d241ed /tests/unit/completion/test_models.py | |
parent | 14b36bfb53d0e346d39f1492dafb6d5d85a1ddba (diff) | |
download | qutebrowser-832568af42d0e7d7d4bdc2d244c0d09e53e970c7.tar.gz qutebrowser-832568af42d0e7d7d4bdc2d244c0d09e53e970c7.zip |
Add unit test for :back/:forward completion.
Tests that the right items show up and they are in the right order.
These could be simplified and expanded by putting them in a class or
turning the setup into a fixture and paramatizing them bassed off of the
`current_idx` so it also tested edge cases but I'm not sure if that is
warrented.
Diffstat (limited to 'tests/unit/completion/test_models.py')
-rw-r--r-- | tests/unit/completion/test_models.py | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/tests/unit/completion/test_models.py b/tests/unit/completion/test_models.py index a5232490a..7c77db3f3 100644 --- a/tests/unit/completion/test_models.py +++ b/tests/unit/completion/test_models.py @@ -23,9 +23,16 @@ import collections import random import string from datetime import datetime +from unittest import mock import pytest from PyQt5.QtCore import QUrl +try: + from PyQt5.QtWebEngineWidgets import ( + QWebEngineHistory, QWebEngineHistoryItem + ) +except ImportError: + pass from qutebrowser.misc import objects from qutebrowser.completion import completer @@ -1144,3 +1151,59 @@ def test_url_completion_benchmark(benchmark, info, model.set_pattern('ex 123') benchmark(bench) + + +@pytest.fixture +def tab_with_history(fake_web_tab, tabbed_browser_stubs, info, monkeypatch): + """Returns a fake tab with some fake history items.""" + pytest.importorskip('PyQt5.QtWebEngineWidgets') + tab = fake_web_tab(QUrl('https://github.com'), 'GitHub', 0) + + history = [] + for url, title in [ + ("http://example.com/index", "list of things"), + ("http://example.com/thing1", "thing1 detail"), + ("http://example.com/thing2", "thing2 detail"), + ("http://example.com/thing3", "thing3 detail"), + ("http://example.com/thing4", "thing4 detail"), + ]: + entry = mock.Mock(spec=QWebEngineHistoryItem) + entry.url.return_value = QUrl(url) + entry.title.return_value = title + history.append(entry) + tab.history._history = mock.Mock(spec=QWebEngineHistory) + tab.history._history.items.return_value = history + + monkeypatch.setattr( + tab.history, 'current_idx', + lambda: 2, + ) + tabbed_browser_stubs[0].widget.tabs = [tab] + tabbed_browser_stubs[0].widget.current_index = 0 + return tab + + +def test_back_completion(tab_with_history, info): + """Test back tab history completion.""" + model = miscmodels.back(info=info) + model.set_pattern('') + + _check_completions(model, { + "History": [ + ("1", "http://example.com/thing1", "thing1 detail"), + ("0", "http://example.com/index", "list of things"), + ], + }) + + +def test_forward_completion(tab_with_history, info): + """Test forward tab history completion.""" + model = miscmodels.forward(info=info) + model.set_pattern('') + + _check_completions(model, { + "History": [ + ("3", "http://example.com/thing3", "thing3 detail"), + ("4", "http://example.com/thing4", "thing4 detail"), + ], + }) |