def test_GIVEN_component_is_selected_WHEN_component_already_has_link_and_changing_button_states_THEN_create_link_button_is_disabled(
    component_tree_view,
    delete_action,
    duplicate_action,
    new_rotation_action,
    new_translation_action,
    create_link_action,
    zoom_action,
    edit_component_action,
    component_model,
    set_of_all_actions,
):
    # Create a link and then select the sample component
    sample_component_index = get_sample_index(component_tree_view)
    add_link_at_index(component_model, component_tree_view,
                      sample_component_index)
    component_tree_view.setCurrentIndex(sample_component_index)

    set_button_states(
        component_tree_view,
        delete_action,
        duplicate_action,
        new_rotation_action,
        new_translation_action,
        create_link_action,
        zoom_action,
        edit_component_action,
    )

    already_has_link_actions = set_of_all_actions - {create_link_action}
    assert all([action.isEnabled() for action in already_has_link_actions])
    assert not any([
        action.isEnabled()
        for action in set_of_all_actions - already_has_link_actions
    ])
def test_GIVEN_component_is_selected_WHEN_changing_button_state_THEN_all_buttons_are_enabled(
    component_tree_view,
    delete_action,
    duplicate_action,
    new_rotation_action,
    new_translation_action,
    create_link_action,
    zoom_action,
    edit_component_action,
    set_of_all_actions,
):
    sample_index = get_sample_index(component_tree_view)
    component_tree_view.setCurrentIndex(sample_index)

    set_button_states(
        component_tree_view,
        delete_action,
        duplicate_action,
        new_rotation_action,
        new_translation_action,
        create_link_action,
        zoom_action,
        edit_component_action,
    )

    assert all([action.isEnabled() for action in set_of_all_actions])
def test_GIVEN_items_selected_is_not_one_WHEN_interacting_with_tree_view_THEN_expected_buttons_are_disabled(
    component_tree_view,
    delete_action,
    duplicate_action,
    new_rotation_action,
    new_translation_action,
    create_link_action,
    zoom_action,
    edit_component_action,
):
    # Set the actions to enabled to make sure that their state changes
    actions = [
        delete_action,
        duplicate_action,
        new_rotation_action,
        new_translation_action,
        create_link_action,
        zoom_action,
    ]
    for action in actions:
        action.setEnabled(True)

    set_button_states(
        component_tree_view,
        delete_action,
        duplicate_action,
        new_rotation_action,
        new_translation_action,
        create_link_action,
        zoom_action,
        edit_component_action,
    )

    assert not any([action.isEnabled() for action in actions])
Example #4
0
 def _set_button_state(self):
     set_button_states(
         self.component_tree_view,
         self.delete_action,
         self.duplicate_action,
         self.new_rotation_action,
         self.new_translation_action,
         self.create_link_action,
         self.zoom_action,
         self.edit_component_action,
     )
def test_GIVEN_transformation_is_selected_WHEN_changing_button_states_THEN_expected_buttons_are_enabled(
    component_tree_view,
    delete_action,
    duplicate_action,
    new_rotation_action,
    new_translation_action,
    create_link_action,
    zoom_action,
    edit_component_action,
    component_model,
    set_of_all_actions,
):
    # Create a transformation and select it on the component list
    sample_component_index = get_sample_index(component_tree_view)
    add_transformation_at_index(component_model, component_tree_view,
                                sample_component_index)
    transformation_list_index = get_transformation_list_index(
        component_model, component_tree_view, sample_component_index)
    transformation_index = get_transformation_or_link_index(
        component_model, component_tree_view, transformation_list_index)
    component_tree_view.setCurrentIndex(transformation_index)

    set_button_states(
        component_tree_view,
        delete_action,
        duplicate_action,
        new_rotation_action,
        new_translation_action,
        create_link_action,
        zoom_action,
        edit_component_action,
    )

    transformation_selected_actions = {
        delete_action,
        duplicate_action,
        edit_component_action,
        new_rotation_action,
        new_translation_action,
        create_link_action,
    }
    assert all(
        [action.isEnabled() for action in transformation_selected_actions])
    assert not any([
        action.isEnabled()
        for action in set_of_all_actions - transformation_selected_actions
    ])
def test_GIVEN_transformation_list_is_selected_WHEN_component_doesnt_have_link_THEN_create_link_button_is_enabled(
    component_tree_view,
    delete_action,
    duplicate_action,
    new_rotation_action,
    new_translation_action,
    create_link_action,
    zoom_action,
    edit_component_action,
    component_model,
    set_of_all_actions,
):
    # Don't create a link and then select the transformation list
    sample_component_index = get_sample_index(component_tree_view)
    transformation_list_index = get_transformation_list_index(
        component_model, component_tree_view, sample_component_index)
    component_tree_view.setCurrentIndex(transformation_list_index)

    set_button_states(
        component_tree_view,
        delete_action,
        duplicate_action,
        new_rotation_action,
        new_translation_action,
        create_link_action,
        zoom_action,
        edit_component_action,
    )

    doesnt_have_link_actions = {
        new_translation_action,
        new_rotation_action,
        create_link_action,
    }
    assert all([action.isEnabled() for action in doesnt_have_link_actions])
    assert not any([
        action.isEnabled()
        for action in set_of_all_actions - doesnt_have_link_actions
    ])