From 107837c1fee561ae662cb135551765843fdd2383 Mon Sep 17 00:00:00 2001 From: Samuel Colvin Date: Sun, 17 Dec 2023 17:03:19 +0000 Subject: [PATCH] improve coverage --- src/python-fastui/tests/test_components.py | 23 +++++++++++++++- src/python-fastui/tests/test_forms.py | 31 ++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/src/python-fastui/tests/test_components.py b/src/python-fastui/tests/test_components.py index 7b118893..d18ad40e 100644 --- a/src/python-fastui/tests/test_components.py +++ b/src/python-fastui/tests/test_components.py @@ -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(): @@ -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', + } + ] diff --git a/src/python-fastui/tests/test_forms.py b/src/python-fastui/tests/test_forms.py index 48eaf349..751eb456 100644 --- a/src/python-fastui/tests/test_forms.py +++ b/src/python-fastui/tests/test_forms.py @@ -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)