From 1e3983843e42fd60f8d86ec4dcdd6f3fb92d687a Mon Sep 17 00:00:00 2001 From: Alex Hadley Date: Wed, 13 Dec 2023 18:50:35 -0800 Subject: [PATCH] #203 Add editing to individual input tests --- .../ParamSection/LeafItemContent.tsx | 4 +- tests/e2e/conftest.py | 5 +- tests/e2e/helpers.py | 5 + tests/e2e/test_parameter_editing.py | 95 +++++++++++++++---- 4 files changed, 84 insertions(+), 25 deletions(-) diff --git a/src/components/ParamSection/LeafItemContent.tsx b/src/components/ParamSection/LeafItemContent.tsx index a479fdd..ab8e264 100644 --- a/src/components/ParamSection/LeafItemContent.tsx +++ b/src/components/ParamSection/LeafItemContent.tsx @@ -172,10 +172,10 @@ function LeafItemEditModeContent({ editedLeaf, path }: LeafItemEditModeContentPr color={changedInput ? "success" : undefined} onChange={({ target: { value } }) => setInput(value)} > - + True - + False diff --git a/tests/e2e/conftest.py b/tests/e2e/conftest.py index 117b664..dec48d6 100644 --- a/tests/e2e/conftest.py +++ b/tests/e2e/conftest.py @@ -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 diff --git a/tests/e2e/helpers.py b/tests/e2e/helpers.py index f165bc7..f88fdda 100644 --- a/tests/e2e/helpers.py +++ b/tests/e2e/helpers.py @@ -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 diff --git a/tests/e2e/test_parameter_editing.py b/tests/e2e/test_parameter_editing.py index 8ba8ea7..036406b 100644 --- a/tests/e2e/test_parameter_editing.py +++ b/tests/e2e/test_parameter_editing.py @@ -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) @@ -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") @@ -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") @@ -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") @@ -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") @@ -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")