def init_struct(self): self.node_list.extend([ components.Box(title='Edit note', node_list=[NoteForm(cid='note_form')]), components.Box(cid='notes_list_box', title='My notes tree', node_list=[ components.RecursiveTree( cid='notes_list', show_children=True, get_data='notes', disable_auto_update=True, data_interface={ 'id': None, 'label': 'title', 'show_children': None, 'icon_open': None, 'icon_close': None }) ]), components.LinkListLayout(cid="notes_link_list", slot='west', auto_update_children=True, show_pagination=False, show_search=False, get_data='notes', event_name='open_details', data_interface={ 'id': None, 'url': 'note/{id}', 'text': 'title' }) ])
class HomePage(epfl.Page): root_node = HomeRoot( constrained=True, node_list=[ components.Box(title="Welcome to EPFL!") ] )
def root_node(page, title_values): values = ['example value 1', 'another example value'] page.root_node = components.Box(title=title_values) page.handle_transaction() return page.root_node
def test_is_submit(page): page.root_node = components.Box(node_list=[ components.Button( cid='button', event_name='test_event', is_submit=False), components.Button( cid='button_is_submit', event_name='test_event', is_submit=True) ]) page.handle_transaction() assert 'type="button"' in page.button.render() assert 'type="submit"' in page.button_is_submit.render()
def test_tooltip(page): page.root_node = components.Box(node_list=[ components.Button(cid='button', event_name='test_event'), components.Button(cid='button_with_tooltip', event_name='test_event', tooltip='test tooltip') ]) page.handle_transaction() assert 'title=""' in page.button.render() assert 'title="test tooltip"' in page.button_with_tooltip.render()
def init_struct(self): self.node_list.extend([ components.Box(title='Edit note', node_list=[NoteForm(cid='note_form')]), components.Box( cid="notes_list", title='My notes', default_child_cls=components.Box(node_list=[ components.Text(value=self.reflect.container_compo.text), components.ColLayout(node_list=[ components.Button(value='Edit this note', color='primary', cols=6, event_name='edit_note'), components.Button(value='Delete this note', color='danger', cols=6, event_name='delete_note') ]) ]), data_interface={ 'id': None, 'text': None, 'title': None }, get_data='notes'), components.LinkListLayout(cid="notes_link_list", slot='west', auto_update_children=True, show_pagination=False, show_search=False, get_data='notes', event_name='open_details', data_interface={ 'id': None, 'url': 'note/{id}', 'text': 'title' }) ])
def test_label(page): page.root_node = components.Box(node_list=[ components.Button(cid='button', event_name='test_event'), components.Button(cid='button_with_label', event_name='test_event', label='test_label') ]) page.handle_transaction() assert '<label ' not in page.button.render() assert '<label ' in page.button_with_label.render() assert '>test_label<' in page.button_with_label.render()
def test_tag_class(page): page.root_node = components.Box(node_list=[ components.Text(cid='text_label_tag', value='test value', label='test label', tag='foo', tag_class='special-tag-class'), components.Text(cid='text_vertical_tag', value='test value', layout_vertical=True, label='test label', tag='foo', tag_class='special-tag-class'), components.Text(cid='text_verbose_tag', value='test value', verbose=True, tag='foo', tag_class='special-tag-class'), components.Text( cid='text_label_tag_no_class', value='test value', label='test label', tag='foo', ), components.Text( cid='text_vertical_tag_no_class', value='test value', layout_vertical=True, label='test label', tag='foo', ), components.Text( cid='text_verbose_tag_no_class', value='test value', verbose=True, tag='foo', ), ]) page.handle_transaction() assert 'class="special-tag-class"' in page.text_verbose_tag.render() assert 'class="special-tag-class"' in page.text_vertical_tag.render() assert 'class="special-tag-class"' in page.text_label_tag.render() assert 'class="special-tag-class"' not in page.text_verbose_tag_no_class.render( ) assert 'class="special-tag-class"' not in page.text_vertical_tag_no_class.render( ) assert 'class="special-tag-class"' not in page.text_label_tag_no_class.render( )
def test_disabled(page): page.root_node = components.Box(node_list=[ components.Button( cid='button', event_name='test_event', disabled=False), components.Button( cid='button_disabled', event_name='test_event', disabled=True) ]) page.handle_transaction() disabled = re.compile('class="[^"]*disabled[^"]*"') assert disabled.search(page.button_disabled.render()) assert not disabled.search(page.button.render())
def test_icon(page, bool_toggle): label = None if bool_toggle: label = 'some label' page.root_node = components.Box(node_list=[ components.Button(cid='button_with_icon', event_name='test_event', icon='times', label=label), components.Button(cid='button_with_icon_size', event_name='test_event', icon='times', icon_size=3, label=label), components.Button(cid='button_with_icon_color', event_name='test_event', icon='times', icon_color='primary', label=label), components.Button(cid='button_with_icon_size_color', event_name='test_event', icon='times', icon_size=3, icon_color='primary', label=label), ]) page.handle_transaction() assert 'fa fa-times' in page.button_with_icon.render() assert 'fa-3x' not in page.button_with_icon.render() assert 'text-primary' not in page.button_with_icon.render() assert 'fa fa-times' in page.button_with_icon_size.render() assert 'fa-3x' in page.button_with_icon_size.render() assert 'text-primary' not in page.button_with_icon_size.render() assert 'fa fa-times' in page.button_with_icon_color.render() assert 'fa-3x' not in page.button_with_icon_color.render() assert 'text-primary' in page.button_with_icon_color.render() assert 'fa fa-times' in page.button_with_icon_size_color.render() assert 'fa-3x' in page.button_with_icon_size_color.render() assert 'text-primary' in page.button_with_icon_size_color.render()
def test_value(page, bool_toggle): icon = None if bool_toggle: icon = 'times' page.root_node = components.Box(node_list=[ components.Button(cid='button', event_name='test_event', value='test value', icon=icon) ]) page.handle_transaction() assert 'test value' in page.button.render() page.button.reset_render_cache() page.button.value = None assert 'test value' not in page.button.render()
def test_patterns(page, bool_toggle): override_pattern = None if bool_toggle: override_pattern = 'override pattern' page.root_node = components.Box(node_list=[ components.NumberInput(input_pattern=override_pattern, cid='number_input', validation_type='number'), components.NumberInput(input_pattern=override_pattern, cid='float_input', validation_type='float'), components.NumberInput(input_pattern=override_pattern, cid='default_input', validation_type='default'), ]) page.handle_transaction() if bool_toggle: for compo in page.root_node.components: assert 'pattern="override pattern"' in compo.render() assert 'pattern="\d*"' not in compo.render() assert 'pattern="[0-9]+([\.|,][0-9]{1,2})?"' not in compo.render() assert 'pattern="[0-9]+([\.|,][0-9]+)?"' not in compo.render() else: assert 'pattern="\d*"' in page.number_input.render() assert 'pattern="\d*"' not in page.float_input.render() assert 'pattern="\d*"' not in page.default_input.render() assert 'pattern="[0-9]+([\.|,][0-9]{1,2})?"' in page.float_input.render( ) assert 'pattern="[0-9]+([\.|,][0-9]{1,2})?"' not in page.number_input.render( ) assert 'pattern="[0-9]+([\.|,][0-9]{1,2})?"' not in page.default_input.render( ) assert 'pattern="[0-9]+([\.|,][0-9]+)?"' in page.default_input.render() assert 'pattern="[0-9]+([\.|,][0-9]+)?"' not in page.float_input.render( ) assert 'pattern="[0-9]+([\.|,][0-9]+)?"' not in page.number_input.render( )
def test_value(page): page.root_node = components.Box(node_list=[ components.Text( cid='text_with_title', value='test value', title='test title'), components.Text( cid='text_label', value='test value', label='test label'), components.Text( cid='text_label_tag', value='test value', label='test label', tag='foo', ), components.Text(cid='text_vertical', value='test value', layout_vertical=True, label='test label'), components.Text(cid='text_vertical_tag', value='test value', layout_vertical=True, label='test label', tag='foo'), ]) page.handle_transaction() assert '>test value<' in page.text_with_title.render() assert 'title="test title"' in page.text_with_title.render() assert 'test value' in page.text_vertical.render() assert 'test value' in page.text_vertical_tag.render() assert 'test value' in page.text_label.render() assert '<foo ' in page.text_vertical_tag.render() assert '</foo>' in page.text_vertical_tag.render() assert '<foo ' in page.text_label_tag.render() assert '</foo>' in page.text_label_tag.render()
def performance_page(request, page, compo_count): page.model = MyModel if request.param: page.root_node = components.CardinalLayout(node_list=[ components.Box(node_list=[ components.Box(node_list=[ components.Box(node_list=[ components.ColLayout(node_list=[ components.SelectableList(skip_child_access=True, row_limit=compo_count, data_interface={ 'id': None, 'text': None }, get_data='my_data'), components.SelectableList(skip_child_access=True, row_limit=compo_count, data_interface={ 'id': None, 'text': None }, get_data='my_data'), components.SelectableList(skip_child_access=True, row_limit=compo_count, data_interface={ 'id': None, 'text': None }, get_data='my_data'), components.SelectableList(skip_child_access=True, row_limit=compo_count, data_interface={ 'id': None, 'text': None }, get_data='my_data'), ]) ]) ]) ]) ]) else: page.root_node = components.CardinalLayout(node_list=[ components.Box(node_list=[ components.Box(node_list=[ components.Box(node_list=[ components.ColLayout(node_list=[ components.SelectableList(skip_child_access=True, row_limit=compo_count * 4, data_interface={ 'id': None, 'text': None }, get_data='my_data'), ]) ]) ]) ]) ]) return page
def test_auto_visibility(page): """Box auto visibility does not imply an empty box will be invisible but instead deals with the child components of said box. If all child components are invisible the box is too, if on or more child component is visible or none exist the box is visible. """ page.root_node = components.Box(node_list=[ components.Box(cid='empty_box'), components.Box(cid='empty_box_no_auto_visibility', auto_visibility=False), components.Box(cid='filled_box', node_list=[ components.Text(value='text 1'), components.Text(value='text 2'), ]), components.Box(cid='filled_box_no_auto_visibility', auto_visibility=False, node_list=[ components.Text(value='text 1'), components.Text(value='text 2'), ]), ]) page.handle_transaction() page.after_event_handling( ) # Auto visibility is handled in after_event_handling # Initially all boxes should be visible. assert page.empty_box.is_visible() assert page.empty_box_no_auto_visibility.is_visible() assert page.filled_box.is_visible() assert page.filled_box_no_auto_visibility.is_visible() # Swap a single component on the filled boxes to invisible. page.filled_box.components[0].set_hidden() page.filled_box_no_auto_visibility.components[0].set_hidden() page.after_event_handling() # The boxes should still be visible. assert page.filled_box.is_visible() assert page.filled_box_no_auto_visibility.is_visible() # Swap the last remaining component on the filled boxes to invisible. page.filled_box.components[1].set_hidden() page.filled_box_no_auto_visibility.components[1].set_hidden() page.after_event_handling() # The auto visibility box should now be invisible, the other one not. assert not page.filled_box.is_visible() assert page.filled_box_no_auto_visibility.is_visible() # Add a dynamic component to the empty boxes. page.empty_box.add_component(components.Text(value='text 3')) page.empty_box_no_auto_visibility.add_component( components.Text(value='text 3')) page.after_event_handling() # The boxes should still be visible. assert page.empty_box.is_visible() assert page.empty_box_no_auto_visibility.is_visible() # Set the component on the previously empty boxes to invisible. page.empty_box.components[0].set_hidden() page.empty_box_no_auto_visibility.components[0].set_hidden() page.after_event_handling() # The auto visibility box should now be invisible, the other one not. assert not page.empty_box.is_visible() assert page.empty_box_no_auto_visibility.is_visible()
def test_button_size_and_color(page, bool_toggle): color = None if bool_toggle: color = 'default' page.root_node = components.Box(node_list=[ components.Button(cid='button', event_name='test_event', color=color), components.Button(cid='button_sm', event_name='test_event', button_size='btn-sm', color=color), components.Button(cid='button_md', event_name='test_event', button_size='btn-md', color=color), components.Button(cid='button_lg', event_name='test_event', button_size='btn-lg', color=color) ]) page.handle_transaction() btn = page.button btn_sm = page.button_sm btn_md = page.button_md btn_lg = page.button_lg color_set = re.compile('class="[^"]*btn-default[^"]*"') if bool_toggle: assert color_set.search(btn.render()) assert color_set.search(btn_sm.render()) assert color_set.search(btn_md.render()) assert color_set.search(btn_lg.render()) else: assert not color_set.search(btn.render()) assert not color_set.search(btn_sm.render()) assert not color_set.search(btn_md.render()) assert not color_set.search(btn_lg.render()) no_size = re.compile('class="[^"]*form-control[^"]*"') sm = re.compile('class="[^"]*btn-sm[^"]*"') md = re.compile('class="[^"]*btn-md[^"]*"') lg = re.compile('class="[^"]*btn-lg[^"]*"') assert no_size.search(btn.render()) assert not sm.search(btn.render()) assert not md.search(btn.render()) assert not lg.search(btn.render()) assert not no_size.search(btn_sm.render()) assert sm.search(btn_sm.render()) assert not md.search(btn_sm.render()) assert not lg.search(btn_sm.render()) assert not no_size.search(btn_md.render()) assert not sm.search(btn_md.render()) assert md.search(btn_md.render()) assert not lg.search(btn_md.render()) assert not no_size.search(btn_lg.render()) assert not sm.search(btn_lg.render()) assert not md.search(btn_lg.render()) assert lg.search(btn_lg.render())