Skip to content

Commit

Permalink
improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelcolvin committed Dec 17, 2023
1 parent 7ca989e commit 107837c
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/python-fastui/tests/test_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
NOTE: we do NOT want to exhaustively construct every component just for the same of it -
that's just testing pydantic!
"""
from fastui import components
from fastui import FastUI, components


def test_div_text():
Expand All @@ -29,3 +29,24 @@ def test_div_class_name():
'className': 'foobar',
'type': 'Div',
}


def test_root_model():
m = FastUI(root=[components.Text(text='hello world')])
assert m.model_dump(by_alias=True, exclude_none=True) == [
{
'text': 'hello world',
'type': 'Text',
}
]


def test_root_model_single():
# fixed by validator
m = FastUI(root=components.Text(text='hello world'))
assert m.model_dump(by_alias=True, exclude_none=True) == [
{
'text': 'hello world',
'type': 'Text',
}
]
31 changes: 31 additions & 0 deletions src/python-fastui/tests/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,37 @@ def test_simple_form_fields():
}


def test_inline_form_fields():
m = components.ModelForm[SimpleForm](submit_url='/foobar/', display_mode='inline')

assert m.model_dump(by_alias=True, exclude_none=True) == {
'submitUrl': '/foobar/',
'method': 'POST',
'type': 'ModelForm',
'displayMode': 'inline',
'footer': [],
'formFields': [
{
'name': 'name',
'title': ['Name'],
'required': True,
'locked': False,
'htmlType': 'text',
'type': 'FormFieldInput',
},
{
'name': 'size',
'title': ['Size'],
'initial': 4,
'required': False,
'locked': False,
'htmlType': 'number',
'type': 'FormFieldInput',
},
],
}


async def test_simple_form_submit():
form_dep = fastui_form(SimpleForm)

Expand Down

0 comments on commit 107837c

Please sign in to comment.