Files
dss/tests/test_atomic_dss.py
2025-12-11 07:13:06 -03:00

96 lines
3.2 KiB
Python

"""Tests for the atomic DSS structure."""
import asyncio
from pathlib import Path
from unittest.mock import MagicMock, patch
import pytest
from httpx import Response
from dss.models.component import AtomicType
from dss.project.manager import DSSProject, ProjectManager, ProjectRegistry
@pytest.fixture
def project_manager(tmp_path: Path) -> ProjectManager:
"""
Fixture for the ProjectManager.
"""
registry_path = tmp_path / "registry.json"
registry = ProjectRegistry(registry_path=registry_path)
return ProjectManager(registry=registry)
@pytest.fixture
def dss_project(project_manager: ProjectManager, tmp_path: Path) -> DSSProject:
"""
Fixture for a DSSProject.
"""
project_path = tmp_path / "test_project"
project = project_manager.init(project_path, "test_project")
project.config.figma = MagicMock()
project.config.figma.files = [MagicMock(key="fake_key", name="fake_name")]
return project
@patch("httpx.AsyncClient")
def test_recursive_figma_import(
mock_async_client, dss_project: DSSProject, project_manager: ProjectManager
):
"""
Test that the Figma import is recursive and that the components are
classified correctly.
"""
# Mock the httpx.AsyncClient to return a sample Figma file
mock_client_instance = mock_async_client.return_value
mock_client_instance.get.return_value = Response(
200,
json={
"document": {
"id": "0:0",
"name": "Document",
"type": "DOCUMENT",
"children": [
{
"id": "1:0",
"name": "Page 1",
"type": "CANVAS",
"children": [
{
"id": "1:1",
"name": "Icon",
"type": "COMPONENT",
},
{
"id": "1:2",
"name": "Button",
"type": "COMPONENT",
"children": [{"id": "1:1", "name": "Icon", "type": "COMPONENT"}],
},
{
"id": "1:3",
"name": "Card",
"type": "COMPONENT_SET",
"children": [{"id": "1:2", "name": "Button", "type": "COMPONENT"}],
},
],
}
],
}
},
)
# Run the sync
dss_project = asyncio.run(project_manager.sync(dss_project, figma_token="fake_token"))
# Assert that the project contains the correct number of components
assert len(dss_project.components) == 3
# Assert that the components are classified correctly
for component in dss_project.components:
if component.name == "Icon":
assert component.classification == AtomicType.ATOM
elif component.name == "Button":
assert component.classification == AtomicType.ATOM
elif component.name == "Card":
assert component.classification == AtomicType.MOLECULE