Skip to content

Commit

Permalink
Added functional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rw251 committed Feb 11, 2025
1 parent 5080ff5 commit 6fa9226
Showing 1 changed file with 134 additions and 0 deletions.
134 changes: 134 additions & 0 deletions tests/functional/test_workspace_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 6fa9226

Please sign in to comment.