diff --git a/tests/functional/test_workspace_pages.py b/tests/functional/test_workspace_pages.py index 04ecfdf4..63e3276b 100644 --- a/tests/functional/test_workspace_pages.py +++ b/tests/functional/test_workspace_pages.py @@ -375,3 +375,137 @@ def test_csv_filtering(live_server, page, context, bll): column_filter.fill("") for age_band in age_bands: expect(page.locator("body")).to_contain_text(age_band) + + +def test_checkbox_caching(live_server, page, context): + workspace = factories.create_workspace("my-workspace") + + file_1 = "outputs/file1.csv" + file_2 = "outputs/file2.csv" + factories.write_workspace_file(workspace, file_1) + factories.write_workspace_file(workspace, file_2) + login_as_user( + live_server, + context, + user_dict={ + "username": "author", + "workspaces": { + "my-workspace": { + "project_details": {"name": "Project 1", "ongoing": True}, + "archived": False, + }, + }, + }, + ) + + # goto page with files + page.goto(live_server.url + workspace.get_url(UrlPath("outputs"))) + + file_1_selector = f"input[type=checkbox][value='{file_1}']" + file_2_selector = f"input[type=checkbox][value='{file_2}']" + + # checkboxes start unchecked + expect(page.locator(file_1_selector)).not_to_be_checked() + expect(page.locator(file_2_selector)).not_to_be_checked() + + # check the first box + page.check(file_1_selector) + + # go to a different page and then come back + page.goto(live_server.url + workspace.get_url(UrlPath("outputs/file1.csv"))) + page.goto(live_server.url + workspace.get_url(UrlPath("outputs"))) + + # the first checkbox state has persisted + expect(page.locator(file_1_selector)).to_be_checked() + expect(page.locator(file_2_selector)).not_to_be_checked() + + +def test_checkbox_caching_same_file_name_but_different_workspace( + live_server, page, context +): + workspace_1 = factories.create_workspace("my-workspace-1") + workspace_2 = factories.create_workspace("my-workspace-2") + + file_1 = "outputs/file1.txt" + factories.write_workspace_file(workspace_1, file_1) + factories.write_workspace_file(workspace_2, file_1) + login_as_user( + live_server, + context, + user_dict={ + "username": "author", + "workspaces": { + "my-workspace-1": { + "project_details": {"name": "Project 1", "ongoing": True}, + "archived": False, + }, + "my-workspace-2": { + "project_details": {"name": "Project 1", "ongoing": True}, + "archived": False, + }, + }, + }, + ) + + # goto page with files in workspace 1 + page.goto(live_server.url + workspace_1.get_url(UrlPath("outputs"))) + + file_1_selector = f"input[type=checkbox][value='{file_1}']" + + # checkboxes start unchecked + expect(page.locator(file_1_selector)).not_to_be_checked() + + # check the first box + page.check(file_1_selector) + + # go to different workspace + page.goto(live_server.url + workspace_2.get_url(UrlPath("outputs"))) + + # file with same name will not be checked + expect(page.locator(file_1_selector)).not_to_be_checked() + + # go back to original workspace + page.goto(live_server.url + workspace_1.get_url(UrlPath("outputs"))) + + # original file should still be checked + expect(page.locator(file_1_selector)).to_be_checked() + + +def test_select_all(live_server, page, context): + workspace = factories.create_workspace("my-workspace") + + file_1 = "outputs/file1.csv" + file_2 = "outputs/file2.csv" + factories.write_workspace_file(workspace, file_1) + factories.write_workspace_file(workspace, file_2) + login_as_user( + live_server, + context, + user_dict={ + "username": "author", + "workspaces": { + "my-workspace": { + "project_details": {"name": "Project 1", "ongoing": True}, + "archived": False, + }, + }, + }, + ) + + # goto page with files + page.goto(live_server.url + workspace.get_url(UrlPath("outputs"))) + + # confirm selectall is unchecked + expect(page.locator("input.selectall")).not_to_be_checked() + + # select 1 checkbox and expect selectall to remain unchecked + page.check(f"input[type=checkbox][value='{file_1}']") + expect(page.locator("input.selectall")).not_to_be_checked() + + # select the other checkbox, now expect select all to be checked + page.check(f"input[type=checkbox][value='{file_2}']") + expect(page.locator("input.selectall")).to_be_checked() + + # uncheck 1 checkbox, now select all should be unchecked again + page.uncheck(f"input[type=checkbox][value='{file_1}']") + expect(page.locator("input.selectall")).not_to_be_checked()