34 lines
1.0 KiB
Python
34 lines
1.0 KiB
Python
from unittest.mock import MagicMock
|
|
|
|
import pytest
|
|
from fasthtml.components import *
|
|
|
|
from components.tabs.components.MyTabs import MyTabs
|
|
|
|
|
|
@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() |