Skip to content

Commit

Permalink
#203 Add editing to individual input tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alexhad6 committed Dec 14, 2023
1 parent 5be6c82 commit 1e39838
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 25 deletions.
4 changes: 2 additions & 2 deletions src/components/ParamSection/LeafItemContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,10 @@ function LeafItemEditModeContent({ editedLeaf, path }: LeafItemEditModeContentPr
color={changedInput ? "success" : undefined}
onChange={({ target: { value } }) => setInput(value)}
>
<MenuItem data-testid="boolean-input-option-True" value="True">
<MenuItem data-testid="bool-input-option-True" value="True">
True
</MenuItem>
<MenuItem data-testid="boolean-input-option-False" value="False">
<MenuItem data-testid="bool-input-option-False" value="False">
False
</MenuItem>
</TextField>
Expand Down
5 changes: 3 additions & 2 deletions tests/e2e/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
from paramdb import ParamDB
from tests.e2e.helpers import setup_db_and_start_server, clear, reset


HOST = "http://127.0.0.1"
STARTING_PORT = 7001 # xdist workers will increment up from this port
STARTING_PORT = 7000 # xdist workers will increment up from this port


@pytest.fixture(name="port", scope="session")
def fixture_port(request: pytest.FixtureRequest) -> int:
"""Port to run ParamView server on."""
"""Port to run ParamView server on, unique to the current xdist worker."""
worker_id = get_xdist_worker_id(request)
if worker_id == "master":
port_offset = 0
Expand Down
5 changes: 5 additions & 0 deletions tests/e2e/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ def get_date(commit_id: int) -> datetime:
return _START_DATE + timedelta(days=commit_id - 1)


def datetime_to_input_str(datetime_obj: datetime) -> str:
"""Format the datetime object in HTML datetime-local input format."""
return datetime_obj.astimezone().strftime("%Y-%m-%dT%H:%M")


def clear(db: ParamDB[Any]) -> None:
"""Clear the database."""
with db._Session.begin() as session: # pylint: disable=no-member,protected-access
Expand Down
95 changes: 74 additions & 21 deletions tests/e2e/test_parameter_editing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from __future__ import annotations
import pytest
from playwright.sync_api import Page, expect
from tests.e2e.helpers import get_date
from tests.e2e.helpers import get_date, datetime_to_input_str


@pytest.fixture(autouse=True)
Expand All @@ -12,30 +12,52 @@ def setup(_reset_single_db: None, _visit_page: None, page: Page) -> None:
page.get_by_test_id("edit-button").click()


def test_displays_input_int(page: Page) -> None:
"""Displays correct input for int parameters."""
def test_input_int(page: Page) -> None:
"""
Input for int parameters has the correct initial values can be edited and reset, and
is properly validated.
"""
item = page.get_by_test_id("parameter-list-item-int")
leaf_input = item.get_by_test_id("leaf-input").get_by_role("textbox")
leaf_type_input = item.get_by_test_id("leaf-type-input").get_by_role("combobox")

expect(leaf_input).to_have_value("123")
expect(leaf_input).to_have_attribute("aria-invalid", "false")
expect(item.get_by_test_id("leaf-unit-input")).not_to_be_attached()
expect(leaf_type_input).to_have_text("int/float")

leaf_input.fill("123a")
expect(leaf_input).to_have_attribute("aria-invalid", "true")
item.get_by_test_id("reset-leaf-button").click()
expect(leaf_input).to_have_value("123")
expect(leaf_input).to_have_attribute("aria-invalid", "false")


def test_displays_input_float(page: Page) -> None:
"""Displays correct input for float parameters."""
"""
Input for float parameters has the correct initial values can be edited and reset,
and is properly validated.
"""
item = page.get_by_test_id("parameter-list-item-float")
leaf_input = item.get_by_test_id("leaf-input").get_by_role("textbox")
leaf_type_input = item.get_by_test_id("leaf-type-input").get_by_role("combobox")

expect(leaf_input).to_have_value("1.2345")
expect(leaf_input).to_have_attribute("aria-invalid", "false")
expect(item.get_by_test_id("leaf-unit-input")).not_to_be_attached()
expect(leaf_type_input).to_have_text("int/float")

leaf_input.fill("1.2345a")
expect(leaf_input).to_have_attribute("aria-invalid", "true")
item.get_by_test_id("reset-leaf-button").click()
expect(leaf_input).to_have_value("1.2345")
expect(leaf_input).to_have_attribute("aria-invalid", "false")


def test_displays_input_bool(page: Page) -> None:
"""Displays correct input for bool parameters."""
"""
Input for bool parameters has the correct initial values can be edited and reset.
"""
item = page.get_by_test_id("parameter-list-item-bool")
leaf_input = item.get_by_test_id("leaf-input").get_by_role("combobox")
leaf_type_input = item.get_by_test_id("leaf-type-input").get_by_role("combobox")
Expand All @@ -44,9 +66,17 @@ def test_displays_input_bool(page: Page) -> None:
expect(item.get_by_test_id("leaf-unit-input")).not_to_be_attached()
expect(leaf_type_input).to_have_text("bool")

leaf_input.click()
page.get_by_test_id("bool-input-option-False").click()
expect(leaf_input).to_have_text("False")
item.get_by_test_id("reset-leaf-button").click()
expect(leaf_input).to_have_text("True")


def test_displays_input_str(page: Page) -> None:
"""Displays correct input for str parameters."""
"""
Input for str parameters has the correct initial values can be edited and reset.
"""
item = page.get_by_test_id("parameter-list-item-str")
leaf_input = item.get_by_test_id("leaf-input").get_by_role("textbox")
leaf_type_input = item.get_by_test_id("leaf-type-input").get_by_role("combobox")
Expand All @@ -55,9 +85,16 @@ def test_displays_input_str(page: Page) -> None:
expect(item.get_by_test_id("leaf-unit-input")).not_to_be_attached()
expect(leaf_type_input).to_have_text("str")

leaf_input.fill("testa")
expect(leaf_input).to_have_value("testa")
item.get_by_test_id("reset-leaf-button").click()
expect(leaf_input).to_have_value("test")


def test_displays_input_none(page: Page) -> None:
"""Displays correct input for None parameters."""
"""
Input for None parameters has the correct initial values can be edited and reset.
"""
item = page.get_by_test_id("parameter-list-item-None")
leaf_input = item.get_by_test_id("leaf-input").get_by_role("textbox")
leaf_type_input = item.get_by_test_id("leaf-type-input").get_by_role("combobox")
Expand All @@ -67,10 +104,18 @@ def test_displays_input_none(page: Page) -> None:
expect(item.get_by_test_id("leaf-unit-input")).not_to_be_attached()
expect(leaf_type_input).to_have_text("None")

item.get_by_test_id("reset-leaf-button").click()
expect(leaf_input).to_have_value("None")
expect(leaf_input).to_be_disabled()


def test_displays_input_datetime(page: Page) -> None:
"""Displays correct input for datetime parameters."""
datetime_input_value = get_date(1).astimezone().strftime("%Y-%m-%dT%H:%M")
"""
Input for datetime parameters has the correct initial values can be edited and
reset.
"""
datetime_input_value = datetime_to_input_str(get_date(1))
new_datetime_input_value = datetime_to_input_str(get_date(2))
item = page.get_by_test_id("parameter-list-item-datetime")
leaf_input = item.get_by_test_id("leaf-input").locator("input[type=datetime-local]")
leaf_type_input = item.get_by_test_id("leaf-type-input").get_by_role("combobox")
Expand All @@ -79,28 +124,36 @@ def test_displays_input_datetime(page: Page) -> None:
expect(item.get_by_test_id("leaf-unit-input")).not_to_be_attached()
expect(leaf_type_input).to_have_text("datetime")

leaf_input.fill(new_datetime_input_value)
expect(leaf_input).to_have_value(new_datetime_input_value)
item.get_by_test_id("reset-leaf-button").click()
expect(leaf_input).to_have_value(datetime_input_value)


def test_displays_input_quantity(page: Page) -> None:
"""Displays correct input for Quantity parameters."""
"""
Input for Quantity parameters has the correct initial values can be edited and
reset.
"""
item = page.get_by_test_id("parameter-list-item-Quantity")
leaf_input = item.get_by_test_id("leaf-input").get_by_role("textbox")
leaf_unit_input = item.get_by_test_id("leaf-unit-input").get_by_role("textbox")
leaf_type_input = item.get_by_test_id("leaf-type-input").get_by_role("combobox")

expect(leaf_input).to_have_value("1.2345")
expect(leaf_input).to_have_attribute("aria-invalid", "false")
expect(leaf_unit_input).to_have_value("m")
expect(leaf_unit_input).to_have_attribute("aria-invalid", "false")
expect(leaf_type_input).to_have_text("Quantity")


def test_can_edit_input_int(page: Page) -> None:
"""Input for int parameters can be edited and reset."""
item = page.get_by_test_id("parameter-list-item-int")
leaf_input = item.get_by_test_id("leaf-input").get_by_role("textbox")
reset_button = item.get_by_test_id("reset-leaf-button")

expect(leaf_input).to_have_attribute("aria-invalid", "false")
leaf_input.fill("123a")
leaf_input.fill("1.2345a")
expect(leaf_input).to_have_attribute("aria-invalid", "true")
reset_button.click()
expect(leaf_input).to_have_value("123")
leaf_unit_input.fill("ms")
expect(leaf_unit_input).to_have_attribute("aria-invalid", "false")
leaf_unit_input.fill("")
expect(leaf_unit_input).to_have_attribute("aria-invalid", "true")
item.get_by_test_id("reset-leaf-button").click()
expect(leaf_input).to_have_value("1.2345")
expect(leaf_input).to_have_attribute("aria-invalid", "false")
expect(leaf_unit_input).to_have_value("m")
expect(leaf_unit_input).to_have_attribute("aria-invalid", "false")

0 comments on commit 1e39838

Please sign in to comment.