Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#221 E2E tests for commit comparison #222

Merged
merged 3 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ jobs:
run: yarn

- name: Install Playwright browsers
run: poetry run playwright install --with-deps chromium
run: poetry run playwright install chromium

- name: Build frontend
run: yarn build
Expand Down
7 changes: 6 additions & 1 deletion src/components/ParamSection/CommitDialog/ComparisonList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,12 @@ function DataDiffListItem({ name: nameOrUndefined, dataDiff }: DataDiffListItemP
)}
</>
) : (
<ListItem sx={listItemSx} disableGutters disablePadding>
<ListItem
data-testid={`comparison-list-item-${name}`}
sx={listItemSx}
disableGutters
disablePadding
>
<CollapseItem
defaultOpen={true}
itemContent={
Expand Down
106 changes: 78 additions & 28 deletions tests/e2e/test_commit_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,61 +54,62 @@ def test_reopen_resets_commit_message(page: Page) -> None:
expect(commit_message_input).to_have_value("")


# pylint: disable-next=too-many-locals
def test_make_commit(page: Page) -> None:
"""Can edit data and make a commit."""
"""
Can edit data and make a commit, which also updates Param last updated timestamps.
"""
commit_select_combobox = page.get_by_test_id("commit-select-combobox")
commit_select_combobox_input = commit_select_combobox.get_by_role("combobox")
commit_message = page.get_by_test_id("commit-message-text-field")
commit_message_input = commit_message.get_by_role("textbox")

int_item = page.get_by_test_id("parameter-list-item-int")
int_item_input = int_item.get_by_test_id("leaf-input").get_by_role("textbox")
int_old_item = page.get_by_test_id("comparison-list-item-old-int")
int_new_item = page.get_by_test_id("comparison-list-item-new-int")

float_item = page.get_by_test_id("parameter-list-item-float")
float_item_input = float_item.get_by_test_id("leaf-input").get_by_role("textbox")
float_old_item = page.get_by_test_id("comparison-list-item-old-float")
float_new_item = page.get_by_test_id("comparison-list-item-new-float")

str_item = page.get_by_test_id("parameter-list-item-str")
str_item_input = str_item.get_by_test_id("leaf-input").get_by_role("textbox")
str_old_item = page.get_by_test_id("comparison-list-item-old-str")
str_new_item = page.get_by_test_id("comparison-list-item-new-str")
param_item = page.get_by_test_id("parameter-list-item-param")
param_str_item = param_item.get_by_test_id("parameter-list-item-str")
param_str_item_input = param_str_item.get_by_test_id("leaf-input").get_by_role(
"textbox"
)

# Initial values
expect(int_item_input).to_have_value("123")
expect(float_item_input).to_have_value("1.2345")
expect(str_item_input).to_have_value("test")
expect(param_item).to_contain_text(FIRST_COMMIT.date)
param_item.get_by_role("button").click()
expect(param_str_item_input).to_have_value("test")

# Edit parameter values
int_item_input.fill("456")
float_item_input.fill("5.6789")
param_str_item_input.fill("hello")

# Opem commit dialog
# Open commit dialog
page.get_by_test_id("open-commit-dialog-button").click()

# Commit list reflects what was changed
expect(page.get_by_test_id("commit-changes-message")).to_have_text(
f"Changes from latest commit ({FIRST_COMMIT.message})"
)
expect(int_old_item).to_have_text("int123")
expect(int_new_item).to_have_text("int456")
expect(float_old_item).to_have_text("float1.2345")
expect(float_new_item).to_have_text("float5.6789")
expect(str_old_item).not_to_be_attached()
expect(str_new_item).not_to_be_attached()
expect(page.get_by_test_id("comparison-list-item-old-int")).not_to_be_attached()
expect(page.get_by_test_id("comparison-list-item-new-int")).not_to_be_attached()
expect(page.get_by_test_id("comparison-list-item-old-float")).to_have_text(
"float1.2345"
)
expect(page.get_by_test_id("comparison-list-item-new-float")).to_have_text(
"float5.6789"
)
expect(page.get_by_test_id("comparison-list-item-param")).not_to_contain_text(
FIRST_COMMIT.date
)
expect(page.get_by_test_id("comparison-list-item-old-str")).to_have_text("strtest")
expect(page.get_by_test_id("comparison-list-item-new-str")).to_have_text("strhello")

# Enter message and make commit
commit_message_input.fill(NEW_COMMIT_MESSAGE)
commit_message_input.press("Enter")
expect(commit_select_combobox_input).to_have_value(NEW_COMMIT.message)

# Values were updated
expect(int_item).to_have_text("int456")
expect(float_item).to_have_text("float5.679")
expect(str_item).to_have_text("strtest")
expect(param_item).not_to_contain_text(FIRST_COMMIT.date)
expect(param_str_item).to_have_text("strhello")


def test_commit_backend_format(page: Page) -> None:
Expand All @@ -118,7 +119,6 @@ def test_commit_backend_format(page: Page) -> None:
"""
commit_message = page.get_by_test_id("commit-message-text-field")
commit_message_input = commit_message.get_by_role("textbox")

datetime_item = page.get_by_test_id("parameter-list-item-datetime")
datetime_item_input = datetime_item.get_by_test_id("leaf-input").locator(
"input[type=datetime-local]"
Expand All @@ -143,3 +143,53 @@ def test_commit_backend_format(page: Page) -> None:

# Load classes in the backend (test fails if this fails)
load_classes_from_db()


def test_comparison_list_collapse(page: Page) -> None:
"""Can collapse and expand items within the commit comparison list."""
float_item = page.get_by_test_id("parameter-list-item-float")
float_item_input = float_item.get_by_test_id("leaf-input").get_by_role("textbox")
list_item = page.get_by_test_id("parameter-list-item-list")
list_second_item = list_item.get_by_test_id("parameter-list-item-1")
list_second_item_input = list_second_item.get_by_test_id("leaf-input").get_by_role(
"textbox"
)
comparison_root_item = page.get_by_test_id("comparison-list-item-root")
comparison_root_item_button = comparison_root_item.get_by_role("button").first
comparison_list_item = page.get_by_test_id("comparison-list-item-list")
comparison_list_item_button = comparison_list_item.get_by_role("button").first
comparison_float_item = page.get_by_test_id("comparison-list-item-new-float")
comparison_list_second_item = comparison_list_item.get_by_test_id(
"comparison-list-item-new-1"
)

# Edit parameter values and open commit dialog
float_item_input.fill("5.6789")
list_item.get_by_role("button").click()
list_second_item_input.fill("hello")
page.get_by_test_id("open-commit-dialog-button").click()

# Comparison list group items are initially expanded
expect(comparison_float_item).to_be_attached()
expect(comparison_list_item).to_be_attached()
expect(comparison_list_second_item).to_be_attached()

# Can collapse the root item
comparison_root_item_button.click()
expect(comparison_float_item).not_to_be_attached()
expect(comparison_list_item).not_to_be_attached()
expect(comparison_list_second_item).not_to_be_attached()

# Can expand the root item
comparison_root_item_button.click()
expect(comparison_float_item).to_be_attached()
expect(comparison_list_item).to_be_attached()
expect(comparison_list_second_item).to_be_attached()

# Can collapse the list item
comparison_list_item_button.click()
expect(comparison_list_second_item).not_to_be_attached()

# Can expand the list item
comparison_list_item_button.click()
expect(comparison_list_second_item).to_be_attached()