Пример #1
0
def test_is_active_tab(page):
    page.root_node = components.TabsLayout(node_list=[
        components.Text(value='Text value 1'),
        components.Text(value='Text value 2'),
        components.Text(value='Text value 3'),
    ])

    page.handle_transaction()
    root_node = page.root_node

    assert not root_node.is_active_tab(2, root_node.components[0])
    assert not root_node.is_active_tab(2, root_node.components[1])
    assert not root_node.is_active_tab(2, root_node.components[2])

    assert root_node.is_active_tab(1, root_node.components[0])
    assert root_node.is_active_tab(1, root_node.components[1])
    assert root_node.is_active_tab(1, root_node.components[2])

    root_node.handle_toggle_tab(root_node.components[0].cid)
    assert root_node.is_active_tab(2, root_node.components[0])

    root_node.handle_toggle_tab(root_node.components[1].cid)
    assert root_node.is_active_tab(2, root_node.components[1])

    root_node.handle_toggle_tab(root_node.components[2].cid)
    assert root_node.is_active_tab(2, root_node.components[2])
Пример #2
0
def test_deleting_active_tab(page):
    page.root_node = components.TabsLayout(node_list=[
        components.Text(value='Text value 1'),
        components.Text(value='Text value 2', cid='tab2'),
        components.Text(value='Text value 3'),
    ])

    page.handle_transaction()
    root_node = page.root_node
    root_node.handle_toggle_tab(root_node.components[1].cid)

    root_node.del_component(root_node.components[1].cid)

    assert root_node.active_tab_cid == ''
Пример #3
0
    def handle_open_details(self):
        """ Handler to open a modal with some note details, triggered via click on the
        LinkListLayout entries in the west slot. """
        calling_cid = self.epfl_event_trace[0]
        note_id = self.page.components[calling_cid].id
        note_data = self.page.model.get_note(note_id)

        self.add_component(
            components.ModalBox(cid='note_detail_box',
                                title='Note Details',
                                node_list=[
                                    components.Text(tag='h3',
                                                    verbose=True,
                                                    value=note_data['title']),
                                    components.Text(value=note_data['text'])
                                ]))
        self.redraw()
Пример #4
0
class User(components.Box):
    """ Display a box to verify, that the current user is authenticated. """
    title = 'User Box'

    node_list = [
        components.Text(
            value='This box is visible for all authenticated prinicipals.')
    ]
Пример #5
0
def test_visibility_settings_on_rendering(tab_selector, page):
    page.root_node = components.TabsLayout(node_list=[
        components.Text(value='Text value 1'),
        components.Text(value='Text value 2'),
        components.Text(value='Text value 3'),
    ])

    page.handle_transaction()
    root_node = page.root_node
    root_node.handle_toggle_tab(root_node.components[tab_selector].cid)

    page.render()

    for i, compo in enumerate(root_node.components):
        if i == tab_selector:
            assert compo.is_visible()
        else:
            assert not compo.is_visible()
Пример #6
0
class Admin(components.Box):
    """ Display a box to verify, that the current user is 'admin'. """

    title = 'Admin Box'

    node_list = [
        components.Text(
            value='This box is only visible for the admin prinicipal.')
    ]
Пример #7
0
class Logout(components.Box):
    """ Component that displays the Logout Button with some text. """
    title = 'Logout Box'
    node_list = [
        components.Text(
            value='This box is only visible for all authenticated users'),
        components.Button(value='Logout', color='warning', event_name='logout')
    ]

    def handle_logout(self):
        self.page.forget()
        self.page.show_fading_message('Logout done.', 'success')
        self.page.jump(self.page.request.matched_route.name, 1000)
Пример #8
0
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()
Пример #9
0
def test_component_separation(page, cardinal):
    default_compo = components.Text(value='some text')

    page.root_node = components.CardinalLayout(node_list=[
        default_compo(slot=cardinal),
        default_compo(slot=cardinal),
        default_compo(slot=cardinal),
        components.CardinalLayout(slot=cardinal,
                                  cid='fixed_layout',
                                  node_list=[
                                      default_compo(cid='east', slot='east'),
                                      default_compo(cid='west', slot='west'),
                                      default_compo(cid='north', slot='north'),
                                      default_compo(cid='south', slot='south'),
                                      default_compo(cid='default'),
                                      default_compo(cid='center',
                                                    slot='center'),
                                  ])
    ])

    page.handle_transaction()
    fixed_layout = page.fixed_layout

    for c in ['center', 'east', 'west', 'north', 'south']:
        if cardinal == c:
            assert page.root_node.has_cardinal(c)
        else:
            assert not page.root_node.has_cardinal(c)

    assert fixed_layout.has_cardinal('east')
    assert fixed_layout.has_cardinal('west')
    assert fixed_layout.has_cardinal('north')
    assert fixed_layout.has_cardinal('south')
    assert fixed_layout.has_cardinal('center')

    assert ['east'
            ] == [c.cid for c in fixed_layout.cardinal_components('east')]
    assert ['west'
            ] == [c.cid for c in fixed_layout.cardinal_components('west')]
    assert ['north'
            ] == [c.cid for c in fixed_layout.cardinal_components('north')]
    assert ['south'
            ] == [c.cid for c in fixed_layout.cardinal_components('south')]

    assert ['default', 'center'
            ] == [c.cid for c in fixed_layout.cardinal_components('center')]
Пример #10
0
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(
    )
Пример #11
0
 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_render_number_of_shown_pages(page):
    row_offset = 0
    row_limit = 20
    row_count = 500
    paginated_node_list = []
    for i in range(0, row_limit):
        paginated_node_list.append(components.Text(value='some text'))

    page.root_node = components.PaginatedListLayout(
        show_pagination=True,
        visible_pages_limit=9,
        row_offset=row_offset,
        row_limit=row_limit,
        row_count=row_count,
        node_list=paginated_node_list)
    page.handle_transaction()

    compo = page.root_node
    compo_html = compo.render()
    # lxml has problems with these html characters
    entities_to_replace = [(u'laquo', 'amp'), (u'raquo', 'amp')]
    for before, after in entities_to_replace:
        compo_html = compo_html.replace(before, after)

    compo_html = etree.fromstring(compo_html)
    pagination_bar = compo_html.find(
        ".//ul[@class='pagination-sm pagination']")
    li_tags = pagination_bar.findall("li")
    assert len(li_tags) == 13
    for i, elem in enumerate(li_tags):
        if i == 0:
            continue  # prev first
        if i == 1:
            continue  # prev
        if i < 11:
            # pages 1 - 9
            assert "<span>%s</span>" % (i - 1) in etree.tostring(elem)
Пример #13
0
def test_label(page, bool_quad):
    on, vertical = bool_quad
    label = None
    if on:
        label = 'test label'

    page.root_node = components.Text(value='test value',
                                     label=label,
                                     layout_vertical=vertical)

    page.handle_transaction()

    assert 'test value' in page.root_node.render()
    if on and vertical:
        assert '<label for="root_node_text" class="control-label"' in page.root_node.render(
        )
    elif on:
        assert '<label for="root_node_text" class="control-label col-sm-2"' in page.root_node.render(
        )
    else:
        assert '<label for="root_node_text" class="control-label"' not in page.root_node.render(
        )
        assert '<label for="root_node_text" class="control-label col-sm-2"' not in page.root_node.render(
        )
Пример #14
0
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()