Skip to content
This repository has been archived by the owner on Nov 7, 2024. It is now read-only.

Commit

Permalink
added corresponding tests and tidying
Browse files Browse the repository at this point in the history
  • Loading branch information
mattclarke committed Feb 15, 2023
1 parent 5485210 commit 0b8d756
Showing 1 changed file with 34 additions and 8 deletions.
42 changes: 34 additions & 8 deletions tests/ui_tests/test_ui_transformation_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from PySide6.QtGui import QVector3D
from pytestqt.qtbot import QtBot # noqa: F401

from nexus_constructor.common_attrs import CommonAttrs
from nexus_constructor.field_attrs import _get_human_readable_type
from nexus_constructor.model.component import Component
from nexus_constructor.model.model import Model
Expand Down Expand Up @@ -36,7 +37,6 @@ def create_corresponding_value_dataset(value: Any):
def test_UI_GIVEN_scalar_vector_WHEN_creating_translation_view_THEN_ui_is_filled_correctly(
qtbot, model, component
):

x = 1
y = 0
z = 0
Expand Down Expand Up @@ -85,6 +85,38 @@ def test_UI_GIVEN_scalar_angle_WHEN_creating_rotation_view_THEN_ui_is_filled_cor
)


def test_UI_GIVEN_a_translation_with_zero_offset_WHEN_setting_the_offset_to_nonzero_THEN_ui_is_filled_correctly(
qtbot, component, model
):
transform = component.add_translation(QVector3D(0, 0, 1), name="test")
transform.values = create_corresponding_value_dataset(123)
view = EditTranslation(parent=None, transformation=transform, model=model)
qtbot.addWidget(view)

view.transformation_frame.offset_box.setValue(9)
view.save_offset()

assert transform.attributes.get_attribute_value(CommonAttrs.OFFSET) == 9
assert view.transformation_frame.offset_box.value() == 9


def test_UI_GIVEN_a_translation_with_nonzero_offset_WHEN_setting_the_offset_to_zero_THEN_ui_is_filled_correctly(
qtbot, component, model
):
transform = component.add_translation(QVector3D(0, 0, 1), name="test")
transform.values = create_corresponding_value_dataset(123)
view = EditTranslation(parent=None, transformation=transform, model=model)
view.transformation_frame.offset_box.setValue(10)
qtbot.addWidget(view)
view.save_offset()

view.transformation_frame.offset_box.setValue(0)
view.save_offset()

assert transform.attributes.get_attribute_value(CommonAttrs.OFFSET) == 0
assert view.transformation_frame.offset_box.value() == 0


def test_UI_GIVEN_array_dataset_as_magnitude_WHEN_creating_translation_THEN_ui_is_filled_correctly(
qtbot, component, model
):
Expand Down Expand Up @@ -149,7 +181,6 @@ def test_UI_GIVEN_link_as_rotation_magnitude_WHEN_creating_rotation_view_THEN_ui
qtbot,
):
model = Model()

component = Component(name="test")

x = 0
Expand All @@ -158,9 +189,7 @@ def test_UI_GIVEN_link_as_rotation_magnitude_WHEN_creating_rotation_view_THEN_ui
path = "/entry"

transform = component.add_rotation(QVector3D(x, y, z), 0, name="test")
link = Link(parent_node=None, name="test", source=path)

transform.values = link
transform.values = Link(parent_node=None, name="test", source=path)

view = EditRotation(transformation=transform, model=model, parent=None)
qtbot.addWidget(view)
Expand All @@ -182,7 +211,6 @@ def test_UI_GIVEN_vector_updated_WHEN_saving_view_changes_THEN_model_is_updated(

transform = component.add_rotation(angle=angle, axis=QVector3D(x, y, z))
transform.values = create_corresponding_value_dataset(angle)

view = EditRotation(parent=None, transformation=transform, model=model)
qtbot.addWidget(view)

Expand All @@ -209,7 +237,6 @@ def test_UI_GIVEN_view_gains_focus_WHEN_transformation_view_exists_THEN_spinboxe

transform = component.add_rotation(angle=angle, axis=QVector3D(x, y, z))
transform.values = create_corresponding_value_dataset(angle)

view = EditRotation(parent=None, transformation=transform, model=model)
qtbot.addWidget(view)

Expand All @@ -231,7 +258,6 @@ def test_UI_GIVEN_view_loses_focus_WHEN_transformation_view_exists_THEN_spinboxe

transform = component.add_rotation(angle=angle, axis=QVector3D(x, y, z))
transform.values = create_corresponding_value_dataset(angle)

view = EditRotation(parent=None, transformation=transform, model=model)
qtbot.addWidget(view)

Expand Down

0 comments on commit 0b8d756

Please sign in to comment.