| 1 |
""" |
| 2 |
Tests for QtAwesome Icon Browser. |
| 3 |
""" |
| 4 |
|
| 5 |
|
| 6 |
from qtpy import QtCore, QtWidgets |
| 7 |
import pytest |
| 8 |
|
| 9 |
|
| 10 |
from qtawesome.icon_browser import IconBrowser |
| 11 |
from qtawesome.styles import DEFAULT_DARK_PALETTE |
| 12 |
|
| 13 |
|
| 14 |
@pytest.fixture |
| 15 |
def browser(qtbot): |
| 16 |
browser = IconBrowser() |
| 17 |
browser._updateStyle(DEFAULT_DARK_PALETTE) |
| 18 |
qtbot.add_widget(browser) |
| 19 |
browser.show() |
| 20 |
return browser |
| 21 |
|
| 22 |
|
| 23 |
def test_browser_init(browser): |
| 24 |
""" |
| 25 |
Ensure the browser opens without error |
| 26 |
""" |
| 27 |
|
| 28 |
def close(): |
| 29 |
browser.close() |
| 30 |
|
| 31 |
timer = QtCore.QTimer() |
| 32 |
timer.timeout.connect(close) |
| 33 |
timer.setSingleShot(2000) |
| 34 |
timer.start() |
| 35 |
|
| 36 |
|
| 37 |
def test_copy(qtbot, browser): |
| 38 |
""" |
| 39 |
Ensure the copy UX works |
| 40 |
""" |
| 41 |
clipboard = QtWidgets.QApplication.instance().clipboard() |
| 42 |
|
| 43 |
clipboard.setText("") |
| 44 |
|
| 45 |
assert clipboard.text() == "" |
| 46 |
|
| 47 |
|
| 48 |
qtbot.keyClicks(browser._lineEditFilter, "penguin") |
| 49 |
qtbot.keyPress(browser._lineEditFilter, QtCore.Qt.Key_Enter) |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
model = browser._listView.model() |
| 54 |
selectionModel = browser._listView.selectionModel() |
| 55 |
selectionModel.setCurrentIndex( |
| 56 |
model.index(0, 0), QtCore.QItemSelectionModel.ClearAndSelect |
| 57 |
) |
| 58 |
|
| 59 |
|
| 60 |
qtbot.mouseClick(browser._copyButton, QtCore.Qt.LeftButton) |
| 61 |
|
| 62 |
assert "penguin" in clipboard.text() |
| 63 |
|
| 64 |
|
| 65 |
def test_filter(qtbot, browser): |
| 66 |
""" |
| 67 |
Ensure the filter UX works when searching for `penguin` |
| 68 |
""" |
| 69 |
initRowCount = browser._listView.model().rowCount() |
| 70 |
assert initRowCount > 0 |
| 71 |
|
| 72 |
|
| 73 |
qtbot.keyClicks(browser._lineEditFilter, "penguin") |
| 74 |
qtbot.keyPress(browser._lineEditFilter, QtCore.Qt.Key_Enter) |
| 75 |
|
| 76 |
filteredRowCount = browser._listView.model().rowCount() |
| 77 |
assert initRowCount > filteredRowCount |
| 78 |
|
| 79 |
|
| 80 |
def test_filter_no_results(qtbot, browser): |
| 81 |
""" |
| 82 |
Ensure the filter doesn't show results (the text doesn't match any icon) |
| 83 |
""" |
| 84 |
initRowCount = browser._listView.model().rowCount() |
| 85 |
assert initRowCount > 0 |
| 86 |
|
| 87 |
|
| 88 |
qtbot.keyClicks(browser._lineEditFilter, "I-AM-NOT-penguin-A-penguin") |
| 89 |
|
| 90 |
|
| 91 |
qtbot.keyPress(browser._lineEditFilter, QtCore.Qt.Key_Enter) |
| 92 |
|
| 93 |
filteredRowCount = browser._listView.model().rowCount() |
| 94 |
assert filteredRowCount == 0 |
| 95 |
|
| 96 |
|
| 97 |
if __name__ == "__main__": |
| 98 |
pytest.main() |