Adding unit tests to WorkflowPlayer.py
This commit is contained in:
@@ -1,44 +1,15 @@
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
import pytest
|
||||
from fasthtml.components import *
|
||||
|
||||
from components.form.components.MyForm import FormField, MyForm
|
||||
from components.tabs.components.MyTabs import MyTabs
|
||||
from components.workflows.components.Workflows import Workflows
|
||||
from core.settings_management import SettingsManager, MemoryDbEngine
|
||||
from helpers import matches, div_icon, search_elements_by_name, Contains
|
||||
from my_mocks import tabs_manager
|
||||
|
||||
TEST_WORKFLOWS_ID = "testing_repositories_id"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def tabs_manager():
|
||||
class MockTabsManager(MagicMock):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, spec=MyTabs, **kwargs)
|
||||
self.request_new_tab_id = MagicMock(side_effect =["new_tab_id", "new_tab_2", "new_tab_3", StopIteration])
|
||||
self.tabs = {}
|
||||
self.tabs_by_key = {}
|
||||
|
||||
def add_tab(self, title, content, key: str | tuple = None, tab_id: str = None, icon=None):
|
||||
self.tabs[tab_id] = (title, content)
|
||||
self.tabs_by_key[key] = (title, content)
|
||||
|
||||
def set_tab_content(self, tab_id, content, title=None, key: str | tuple = None, active=None):
|
||||
self.tabs[tab_id] = (title, content)
|
||||
self.tabs_by_key[key] = (title, content)
|
||||
|
||||
def refresh(self):
|
||||
return Div(
|
||||
Div(
|
||||
[Div(title) for title in self.tabs.keys()]
|
||||
),
|
||||
list(self.tabs.values())[-1]
|
||||
)
|
||||
|
||||
return MockTabsManager()
|
||||
|
||||
boundaries = {"height": 500, "width": 800}
|
||||
|
||||
@pytest.fixture
|
||||
def workflows(session, tabs_manager):
|
||||
@@ -117,7 +88,7 @@ def test_i_can_add_a_new_workflow(workflows, tabs_manager):
|
||||
res = workflows.request_new_workflow()
|
||||
tab_id = list(res.tabs.keys())[0]
|
||||
|
||||
actual = workflows.add_new_workflow(tab_id, "Not relevant here", "New Workflow", {})
|
||||
actual = workflows.add_new_workflow(tab_id, "Not relevant here", "New Workflow", boundaries)
|
||||
|
||||
expected = (
|
||||
Div(
|
||||
@@ -134,11 +105,11 @@ def test_i_can_add_a_new_workflow(workflows, tabs_manager):
|
||||
|
||||
|
||||
def test_i_can_select_a_workflow(workflows):
|
||||
workflows.add_new_workflow("tab_id_1", "Not relevant", "workflow 1", {})
|
||||
workflows.add_new_workflow("tab_id_2", "Not relevant", "workflow 2", {})
|
||||
workflows.add_new_workflow("tab_id_3", "Not relevant", "workflow 3", {})
|
||||
workflows.add_new_workflow("tab_id_1", "Not relevant", "workflow 1", boundaries)
|
||||
workflows.add_new_workflow("tab_id_2", "Not relevant", "workflow 2", boundaries)
|
||||
workflows.add_new_workflow("tab_id_3", "Not relevant", "workflow 3", boundaries)
|
||||
|
||||
actual = workflows.show_workflow("workflow 2", {})
|
||||
actual = workflows.show_workflow("workflow 2", boundaries)
|
||||
|
||||
expected = (
|
||||
Div(
|
||||
@@ -150,4 +121,4 @@ def test_i_can_select_a_workflow(workflows):
|
||||
Div(), # Workflow Designer embedded in the tab
|
||||
)
|
||||
|
||||
assert matches(actual, expected)
|
||||
assert matches(actual, expected)
|
||||
|
||||
Reference in New Issue
Block a user