From 00091433efd3f3affe01f778a7104ba48f0a8723 Mon Sep 17 00:00:00 2001 From: tangkong Date: Fri, 26 Jul 2024 10:40:33 -0700 Subject: [PATCH] TST: add test_apply_filter for search_page --- superscore/tests/conftest.py | 12 ++++++++++++ superscore/tests/test_page.py | 31 +++++++++++++++++++++++++++++-- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/superscore/tests/conftest.py b/superscore/tests/conftest.py index 70c9b69..8bb730f 100644 --- a/superscore/tests/conftest.py +++ b/superscore/tests/conftest.py @@ -720,3 +720,15 @@ def done(self): def mock_client(mock_backend: _Backend) -> Client: client = Client(backend=mock_backend) return client + + +@pytest.fixture(scope='function') +def sample_client( + filestore_backend: FilestoreBackend, + dummy_cl: ControlLayer +) -> Client: + """Return a client with actula data, but no communication capabilities""" + client = Client(backend=filestore_backend) + client.cl = dummy_cl + + return client diff --git a/superscore/tests/test_page.py b/superscore/tests/test_page.py index a32d958..03139f2 100644 --- a/superscore/tests/test_page.py +++ b/superscore/tests/test_page.py @@ -18,8 +18,8 @@ def collection_page(qtbot: QtBot): @pytest.fixture(scope='function') -def search_page(qtbot: QtBot, mock_client: Client): - page = SearchPage(client=mock_client) +def search_page(qtbot: QtBot, sample_client: Client): + page = SearchPage(client=sample_client) qtbot.addWidget(page) return page @@ -28,3 +28,30 @@ def search_page(qtbot: QtBot, mock_client: Client): def test_page_smoke(page: str, request: pytest.FixtureRequest): """smoke test, just create each page and see if they fail""" print(type(request.getfixturevalue(page))) + + +def test_apply_filter(search_page: SearchPage): + search_page.apply_filter_button.clicked.emit() + assert search_page.results_table_view.model().rowCount() == 6 + + search_page.snapshot_checkbox.setChecked(False) + search_page.apply_filter_button.clicked.emit() + assert search_page.results_table_view.model().rowCount() == 5 + + search_page.readback_checkbox.setChecked(False) + search_page.apply_filter_button.clicked.emit() + assert search_page.results_table_view.model().rowCount() == 2 + + search_page.setpoint_checkbox.setChecked(False) + search_page.apply_filter_button.clicked.emit() + assert search_page.results_table_view.model().rowCount() == 1 + + # reset and try name filter + for box in search_page.type_checkboxes: + box.setChecked(True) + search_page.apply_filter_button.clicked.emit() + assert search_page.results_table_view.model().rowCount() == 6 + + search_page.name_line_edit.setText('collection 1') + search_page.apply_filter_button.clicked.emit() + assert search_page.results_table_view.model().rowCount() == 1