Skip to content

Commit

Permalink
Add supporting files to the e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
rebkwok committed Mar 15, 2024
1 parent dfe91e6 commit f222fbe
Showing 1 changed file with 96 additions and 9 deletions.
105 changes: 96 additions & 9 deletions tests/functional/test_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,28 @@ def login_as(live_server, page, username):
expect(page.locator("body")).to_contain_text(f"Logged in as: {username}")


def tree_element_is_selected(page, locator):
# We need to wait for a tiny amount to ensure the js that swaps the
# selected classes around has run. An arbitrary 10ms seems to be enough.
page.wait_for_timeout(10)
classes = locator.get_attribute("class")
return "selected" in classes


def test_e2e_release_files(page, live_server, dev_users, release_files_stubber):
"""
Test full Airlock process to create, submit and release files
"""
# set up a workspace file in a subdirectory

# set up workspace files in a subdirectory
factories.write_workspace_file(
"test-workspace", "subdir/file.txt", "I am the file content"
)
factories.write_workspace_file(
"test-workspace",
"subdir/supporting_file.txt",
"I am the supporting file content",
)

# Log in as a researcher
login_as(live_server, page, "researcher")
Expand Down Expand Up @@ -100,6 +114,10 @@ def test_e2e_release_files(page, live_server, dev_users, release_files_stubber):
# Fill in the form with a new group name
page.locator("#id_new_filegroup").fill("my-new-group")

# By default, the selected filetype is OUTPUT
expect(page.locator("#id_filetype1")).to_be_checked()
expect(page.locator("#id_filetype2")).not_to_be_checked()

# Click the button to add the file to a release request
find_and_click(page.get_by_role("form").locator("#add-file-button"))

Expand All @@ -124,37 +142,106 @@ def test_e2e_release_files(page, live_server, dev_users, release_files_stubber):
# Note: `get_by_role`` gets all links on the page; `locator` searches
# for elements with the filegroup class; the `scope` pseudoselector
# lets us search on the elements themselves as well as their children
filegroup_link = page.get_by_role("link").locator(".filegroup:scope")
filegroup_link = page.get_by_role("link").locator(".output.filegroup:scope")
expect(filegroup_link).to_be_visible()
expect(filegroup_link).to_contain_text(re.compile("my-new-group", flags=re.I))

# supporting filegroup link
supporting_filegroup_link = page.get_by_role("link").locator(
".supporting.filegroup:scope"
)
# we have no supporting files yet
expect(supporting_filegroup_link).not_to_be_visible()

# In the initial request view, the tree is collapsed
file_link = page.get_by_role("link").locator(".file:scope")
file_link = page.get_by_role("link").locator(".output.file:scope")
assert file_link.all() == []

# Click to open the filegroup tree
filegroup_link.click()

# Click on the directory to ensure that renders correctly.
subdir_link = page.get_by_role("link").locator(".directory:scope")
# Click on the output directory to ensure that renders correctly.
subdir_link = page.get_by_role("link").locator(".output.directory:scope")
find_and_click(subdir_link)
expect(page.locator("#selected-contents")).to_contain_text("file.txt")

# Tree opens fully expanded, so now the file (in its subdir) is visible
find_and_click(file_link)
expect(page.locator("body")).to_contain_text("I am the file content")

# Go back to the Workspace view so we can add a supporting file
find_and_click(page.locator("#workspace-home-button"))
expect(page).to_have_url(live_server.url + "/workspaces/view/test-workspace/")

# Expand the tree and click on the supporting file
find_and_click(page.get_by_role("link", name="subdir").first)
find_and_click(page.get_by_role("link", name="supporting_file.txt").first)

# Add supporting file to request, choosing the group we created previously
# Find the add file button and click on it to open the modal
find_and_click(page.locator("[data-modal=addRequestFile]"))

page.locator("#id_filegroup").select_option("my-new-group")
# Select supporting file
page.locator("#id_filetype2").check()

# Click the button to add the file to a release request
find_and_click(page.get_by_role("form").locator("#add-file-button"))

# Go back to the request
find_and_click(page.locator("#current-request-button"))

# The supporting filegroup link is now visible
expect(supporting_filegroup_link).to_be_visible()
# Expand both trees
filegroup_link.click()
supporting_filegroup_link.click()

# Click on the output directory to ensure that renders correctly.
subdir_link = page.get_by_role("link").locator(".output.directory:scope")
assert not tree_element_is_selected(page, subdir_link)
find_and_click(subdir_link)
# subdir link is shown as selected
assert tree_element_is_selected(page, subdir_link)
expect(page.locator("#selected-contents")).to_contain_text("file.txt")

# Tree opens fully expanded, so now the file (in its subdir) is visible
find_and_click(file_link)
# File is selected, subdir is now unselected
assert tree_element_is_selected(page, file_link)
assert not tree_element_is_selected(page, subdir_link)
expect(page.locator("body")).to_contain_text("I am the file content")

# Click on the supporting files directory to ensure that renders correctly.
# Switching between selecting dir/file in output and supporting trees
# correctly applies/removes selected classes
supporting_subdir_link = page.get_by_role("link").locator(
".supporting.directory:scope"
)
find_and_click(supporting_subdir_link)
assert tree_element_is_selected(page, supporting_subdir_link)
assert not tree_element_is_selected(page, file_link)
expect(page.locator("#selected-contents")).to_contain_text("supporting_file.txt")

supporting_file_link = page.get_by_role("link").locator(".supporting.file:scope")
find_and_click(supporting_file_link)
assert tree_element_is_selected(page, supporting_file_link)
assert not tree_element_is_selected(page, supporting_subdir_link)
expect(page.locator("body")).to_contain_text("I am the supporting file content")

# Click back to the output file link and ensure the selected classes are correctly applied
find_and_click(file_link)
assert tree_element_is_selected(page, file_link)
assert not tree_element_is_selected(page, supporting_file_link)
expect(page.locator("body")).to_contain_text("I am the file content")

# Submit request
submit_button = page.locator("#submit-for-review-button")
find_and_click(submit_button)
expect(page.locator("body")).to_contain_text("SUBMITTED")
# After the request is submitted, the submit button is no longer visible
expect(submit_button).not_to_be_visible()

# Ensure researcher can go back to the Workspace view
find_and_click(page.locator("#workspace-home-button"))
expect(page).to_have_url(live_server.url + "/workspaces/view/test-workspace/")

# Before we log the researcher out and continue, let's just check
# their requests
find_and_click(page.get_by_test_id("nav-requests"))
Expand Down

0 comments on commit f222fbe

Please sign in to comment.