示例#1
0
def test_adding_other_than_form_or_nav_is_not_allowed(web_fixture,
                                                      navbar_fixture):
    """Only Navs, Forms and Text may be added to a NavbarLayout."""

    navbar = navbar_fixture.navbar.use_layout(NavbarLayout())
    not_a_form_or_nav = Div(web_fixture.view)

    with expected(IsInstance):
        navbar.layout.add(not_a_form_or_nav)

    # Case: Form
    navbar = navbar_fixture.new_navbar().use_layout(NavbarLayout())
    navbar.layout.add(navbar_fixture.form)
    [added_widget] = navbar.children[0].children
    assert added_widget is navbar_fixture.form
    assert 'form-inline' in navbar_fixture.form.get_attribute('class')

    # Case: Nav
    navbar = navbar_fixture.new_navbar().use_layout(NavbarLayout())
    assert 'navbar-nav' not in navbar_fixture.nav.html_representation.get_attribute(
        'class').split(' ')
    navbar.layout.add(navbar_fixture.nav)
    [added_widget] = navbar.children[0].children
    assert added_widget is navbar_fixture.nav
    assert 'navbar-nav' in navbar_fixture.nav.html_representation.get_attribute(
        'class').split(' ')

    # Case: Text
    navbar = navbar_fixture.new_navbar().use_layout(NavbarLayout())
    navbar.layout.add(navbar_fixture.textnode)
    [added_widget] = navbar.children[0].children
    [textnode] = added_widget.children
    assert isinstance(added_widget, Span)
    assert textnode is navbar_fixture.textnode
    assert 'navbar-text' in added_widget.get_attribute('class').split(' ')
示例#2
0
def test_navbar_basics(web_fixture, navbar_fixture):
    """A typical Navbar is created by using its layout to add some brand text, a nav and form in it."""

    fixture = navbar_fixture

    navbar = Navbar(web_fixture.view).use_layout(NavbarLayout())

    navbar.layout.set_brand_text('Brandy')
    navbar.layout.add(fixture.nav)
    navbar.layout.add(fixture.form)

    [brand, nav, form] = navbar.children[0].children
    [ul] = nav.children

    # The Navbar itself
    assert navbar.children[0].tag_name == 'nav'
    assert 'navbar' in navbar.children[0].get_attribute('class').split(' ')

    # The added contents
    assert isinstance(brand, A)
    assert brand.href.path == '/'
    assert 'navbar-brand' in brand.get_attribute('class')

    assert 'navbar-nav' in ul.get_attribute('class')

    assert isinstance(form, Form)
    assert 'form-inline' in form.get_attribute('class')
示例#3
0
def test_navbar_toggle_requires_target_id(web_fixture, navbar_fixture):
    """To be able to hide an element, it is required to have an id"""

    navbar = navbar_fixture.navbar
    navbar.use_layout(NavbarLayout())
    element_without_id = P(web_fixture.view, text='Peek-A-Boo')

    with expected(ProgrammerError, test='.*has no css_id set.*'):
        navbar.layout.add_toggle(element_without_id)
示例#4
0
def test_customised_colour_scheme(web_fixture):
    """A ColourScheme is used to determine link colours and/or optionally a standard bootstrap background color."""

    layout = NavbarLayout(colour_theme='light', bg_scheme='dark')
    widget = Navbar(web_fixture.view).use_layout(layout)

    [navbar] = widget.children

    assert 'navbar-light' in navbar.get_attribute('class')
    assert 'bg-dark' in navbar.get_attribute('class')
示例#5
0
def adding_to_navbar_placement_for_device(fixture):
    """Placement of an added Widget can be specified to apply below a certain device size only."""
    fixture.navbar.use_layout(NavbarLayout())

    if fixture.side == 'left':
        fixture.navbar.layout.add(fixture.nav, left='md')
    else:
        fixture.navbar.layout.add(fixture.nav, right='md')

    [wrapping_div] = fixture.navbar.children[0].children
    vassert('pull-md-%s' % fixture.side in wrapping_div.get_attribute('class'))
示例#6
0
 def __init__(self, view):
     super().__init__(view)
     self.use_layout(
         PageLayout(
             document_layout=Container(),
             contents_layout=ColumnLayout(
                 ColumnOptions('main',
                               size=ResponsiveSize(lg=6))).with_slots()))
     navbar = Navbar(view).use_layout(NavbarLayout())
     navbar.layout.set_brand_text('My Site')
     self.layout.header.add_child(navbar)
示例#7
0
def adding_to_navbar_with_both_left_and_right_alignment_not_allowed(fixture):
    """You cannot place an added Widget to both left and right sides."""
    navbar = fixture.navbar.use_layout(NavbarLayout())

    def check_ex(ex):
        vassert(
            six.text_type(ex).startswith(
                'Both left= and right= have been given. Specify left or right, not both'
            ))

    with expected(ProgrammerError, test=check_ex):
        navbar.layout.add(fixture.nav, left=True, right=True)
示例#8
0
def test_adding_brand_widget(web_fixture, navbar_fixture):
    """Brand content can also be added as a Widget, instead of only text."""

    navbar_widget = navbar_fixture.navbar.use_layout(NavbarLayout())
    custom_brand = Div(web_fixture.view)
    navbar_widget.layout.set_brand(custom_brand)

    [navbar] = navbar_widget.children
    [actual_brand_widget] = navbar.children

    assert actual_brand_widget is custom_brand
    assert 'navbar-brand' in actual_brand_widget.get_attribute('class')
示例#9
0
            def __init__(self, view):
                super(MainWidget, self).__init__(view)

                navbar = Navbar(view)
                navbar.use_layout(NavbarLayout())
                fixture.element_to_collapse = P(view,
                                                text='Peek-A-Boo',
                                                css_id='my_id')
                navbar.layout.add_toggle(fixture.element_to_collapse)

                self.add_child(fixture.element_to_collapse)
                self.add_child(navbar)
示例#10
0
def navbar_toggle_requires_target_id(fixture):
    """To be able to hide an element, it is required to have an id"""

    navbar = fixture.navbar
    navbar.use_layout(NavbarLayout())
    element_without_id = P(fixture.view, text='Peek-A-Boo')

    def check_ex(ex):
        vassert('has no css_id set' in six.text_type(ex))

    with expected(ProgrammerError, test=check_ex):
        navbar.layout.add_toggle(element_without_id)
示例#11
0
            def __init__(self, view):
                super().__init__(view)

                navbar = Navbar(view)
                navbar.use_layout(
                    NavbarLayout(colour_theme='dark', bg_scheme='dark'))
                fixture.element_to_collapse = P(view,
                                                text='Peek-A-Boo',
                                                css_id='my_id')
                navbar.layout.add_toggle(fixture.element_to_collapse)

                self.add_child(fixture.element_to_collapse)
                self.add_child(navbar)
示例#12
0
def test_navbar_with_centered_contents(web_fixture, navbar_fixture):
    """Contents of a Navbar appears centered when center_contents is set to True"""

    navbar_widget = navbar_fixture.navbar
    navbar_widget.use_layout(NavbarLayout(center_contents=True))
    navbar_widget.layout.set_brand_text(
        'Brandy')  #adding something to illustrate the structure change

    [navbar] = navbar_widget.children
    [centering_div] = navbar.children
    [brand_widget] = centering_div.children

    assert 'container' in centering_div.get_attribute('class')
    assert 'navbar-brand' in brand_widget.get_attribute('class')
示例#13
0
def adding_to_navbar_with_specific_placement(fixture):
    """Widgets can be added to a Navbar placed right or left in the NavBar."""
    navbar = fixture.navbar.use_layout(NavbarLayout())

    if fixture.side == 'left':
        added_widget = navbar.layout.add(fixture.nav, left=True)
    else:
        added_widget = navbar.layout.add(fixture.nav, right=True)

    [wrapping_div] = navbar.children[0].children

    vassert('pull-%s' % fixture.side in wrapping_div.get_attribute('class'))
    vassert(added_widget is fixture.nav)
    vassert([added_widget] == wrapping_div.children)
示例#14
0
def adding_other_than_form_or_nav_is_not_allowed(fixture):
    """Only Navs and Forms may be added."""

    navbar = fixture.navbar.use_layout(NavbarLayout())
    not_a_form_or_nav = Div(fixture.view)

    with expected(IsInstance):
        navbar.layout.add(not_a_form_or_nav)

    # Case: Form
    navbar = fixture.new_navbar().use_layout(NavbarLayout())
    navbar.layout.add(fixture.form)
    [added_widget] = navbar.children[0].children
    vassert(added_widget is fixture.form)

    # Case: Nav
    navbar = fixture.new_navbar().use_layout(NavbarLayout())
    vassert('navbar-nav' not in fixture.nav.html_representation.get_attribute(
        'class').split(' '))
    navbar.layout.add(fixture.nav)
    [added_widget] = navbar.children[0].children
    vassert(added_widget is fixture.nav)
    vassert('navbar-nav' in fixture.nav.html_representation.get_attribute(
        'class').split(' '))
示例#15
0
def navbar_basics(fixture):
    """A typical Navbar is created by using its layout to add some brand text, a nav and form in it."""

    navbar = Navbar(fixture.view).use_layout(NavbarLayout())

    navbar.layout.set_brand_text('Brandy')
    navbar.layout.add(fixture.nav)
    navbar.layout.add(fixture.form)

    [brand, nav, form] = navbar.children[0].children
    [ul] = nav.children

    # The Navbar itself
    vassert(navbar.children[0].tag_name == 'nav')
    vassert('navbar' in navbar.children[0].get_attribute('class').split(' '))

    # The added contents
    vassert(isinstance(brand, A))
    vassert('navbar-brand' in brand.get_attribute('class'))

    vassert('navbar-nav' in ul.get_attribute('class'))

    vassert(isinstance(form, Form))
示例#16
0
 def sticky_top(self):
     self.layout = NavbarLayout(fixed_to='sticky-top')
     self.expected_css_class = 'sticky-top'
示例#17
0
 def fixed_bottom(self):
     self.layout = NavbarLayout(fixed_to='fixed-bottom')
     self.expected_css_class = 'fixed-bottom'
示例#18
0
 def fixed_top(self):
     self.layout = NavbarLayout(fixed_to='fixed-top')
     self.expected_css_class = 'fixed-top'
示例#19
0
 def new_navbar_with_layout(self):
     return self.navbar.use_layout(NavbarLayout())
示例#20
0
 def default(self):
     self.layout = NavbarLayout()
     self.expected_css_class = None
示例#21
0
 def full(self):
     self.layout = NavbarLayout(full=True)
     self.expected_css_class = 'navbar-full'