feat: Implement atomic design system core structure and recursive Figma import
This commit is contained in:
91
tests/test_figma_ingest.py
Normal file
91
tests/test_figma_ingest.py
Normal file
@@ -0,0 +1,91 @@
|
||||
"""
|
||||
Tests for the Figma ingestion source.
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
from unittest.mock import patch, AsyncMock, MagicMock
|
||||
|
||||
import pytest
|
||||
|
||||
from dss.ingest.sources.figma import FigmaTokenSource
|
||||
from dss.models.component import AtomicType
|
||||
|
||||
|
||||
# Mock Figma client with async context manager and async methods
|
||||
class MockAsyncClient:
|
||||
def __init__(self, *args, **kwargs):
|
||||
pass
|
||||
|
||||
async def __aenter__(self):
|
||||
return self
|
||||
|
||||
async def __aexit__(self, exc_type, exc_val, exc_tb):
|
||||
pass
|
||||
|
||||
async def get_file(self, file_key: str):
|
||||
return {
|
||||
"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"}
|
||||
],
|
||||
},
|
||||
],
|
||||
}
|
||||
],
|
||||
}
|
||||
}
|
||||
|
||||
async def get_file_variables(self, file_key: str):
|
||||
return {"meta": {"variables": {}, "variableCollections": {}}}
|
||||
|
||||
|
||||
@patch("dss.ingest.sources.figma.IntelligentFigmaClient", new=MockAsyncClient)
|
||||
def test_figma_component_extraction():
|
||||
"""
|
||||
Test that the Figma ingestion source correctly extracts and classifies
|
||||
components from a mock Figma file.
|
||||
"""
|
||||
source = FigmaTokenSource(figma_token="fake_token")
|
||||
|
||||
token_collection, components = asyncio.run(source.extract("fake_file_key"))
|
||||
|
||||
# Assert that the correct number of components were extracted
|
||||
assert len(components) == 1
|
||||
|
||||
# Assert that the components are classified correctly
|
||||
card_component_found = False
|
||||
for component in components:
|
||||
if component.name == "Card":
|
||||
card_component_found = True
|
||||
assert component.classification == AtomicType.MOLECULE
|
||||
assert component.sub_components # should not be empty
|
||||
assert len(component.sub_components) == 1 # Card has one child
|
||||
assert component.figma_node_id == "1:3"
|
||||
|
||||
assert card_component_found, "Card component not found in extracted components."
|
||||
Reference in New Issue
Block a user