def test_tabs_with_sub_options(web_fixture): """A TabbedPanel can have Tabs that are each composed of multiple sub-options.""" web_fixture.request.query_string = 'tab=mult2' tabbed_panel = TabbedPanel(web_fixture.view) multi_tab = MultiTab(web_fixture.view, 'tab 1 name', 'multitab-main') multi_tab.add_tab(Tab(web_fixture.view, 'multi tab 1', 'mult1', P.factory(text='tab 1/1 content'))) multi_tab.add_tab(Tab(web_fixture.view, 'multi tab 2', 'mult2', P.factory(text='tab 1/2 content'))) tabbed_panel.add_tab(multi_tab) tester = WidgetTester(tabbed_panel) expected_html = \ '''<ul role="tablist" class="nav nav-tabs reahl-menu">'''\ '''<li class="dropdown nav-item">'''\ '''<a aria-haspopup="true" data-toggle="dropdown" href="/?open_item=tab+1+name&tab=mult2" role="button" class="active dropdown-toggle nav-link reahl-ajaxlink">tab 1 name</a>'''\ '''<div class="dropdown-menu">'''\ '''<a id="nav_tab_mult1_tab" aria-controls="tab_mult1" aria-selected="false" data-target="#tab_mult1" data-toggle="tab" href="/?tab=mult1" role="tab" class="dropdown-item">multi tab 1</a>'''\ '''<a id="nav_tab_mult2_tab" aria-controls="tab_mult2" aria-selected="true" data-target="#tab_mult2" data-toggle="tab" href="/?tab=mult2" role="tab" class="active dropdown-item">multi tab 2</a>'''\ '''</div>'''\ '''</li>'''\ '''</ul>'''\ '''<div class="tab-content">'''\ '''<div id="tab_mult1" aria-labelledby="nav_tab_mult1_tab" role="tabpanel" class="tab-pane"><p>tab 1/1 content</p></div>'''\ '''<div id="tab_mult2" aria-labelledby="nav_tab_mult2_tab" role="tabpanel" class="active tab-pane"><p>tab 1/2 content</p></div>'''\ '''</div>''' actual = tester.render_html() assert actual == expected_html
def tabs_with_sub_options(fixture): """A TabbedPanel can have Tabs that are each composed of multiple sub-options.""" fixture.request.query_string = 'tab=mult2' tabbed_panel = TabbedPanel(fixture.view) multi_tab = MultiTab(fixture.view, 'tab 1 name', 'multitab-main') multi_tab.add_tab( Tab(fixture.view, 'multi tab 1', 'mult1', P.factory(text='tab 1/1 content'))) multi_tab.add_tab( Tab(fixture.view, 'multi tab 2', 'mult2', P.factory(text='tab 1/2 content'))) tabbed_panel.add_tab(multi_tab) tester = WidgetTester(tabbed_panel) expected_html = \ '''<ul class="nav nav-tabs reahl-menu">'''\ '''<li class="dropdown nav-item">'''\ '''<a data-target="-" data-toggle="dropdown" href="/?open_item=tab+1+name&tab=mult2" class="active dropdown-toggle nav-link reahl-ajaxlink">tab 1 name<span class="caret"></span></a>'''\ '''<div class="dropdown-menu">'''\ '''<a data-target="#tab_mult1" data-toggle="tab" href="/?tab=mult1" class="dropdown-item">multi tab 1</a>'''\ '''<a data-target="#tab_mult2" data-toggle="tab" href="/?tab=mult2" class="active dropdown-item">multi tab 2</a>'''\ '''</div>'''\ '''</li>'''\ '''</ul>'''\ '''<div class="tab-content">'''\ '''<div id="tab_mult1" class="tab-pane"><p>tab 1/1 content</p></div>'''\ '''<div id="tab_mult2" class="active tab-pane"><p>tab 1/2 content</p></div>'''\ '''</div>''' actual = tester.render_html() vassert(actual == expected_html)
def __init__(self, view): super(MyPage, self).__init__(view) tabbed_panel = self.body.add_child(TabbedPanel(view)) contents1 = P.factory(text='A paragraph to give content to the first tab.') tabbed_panel.add_tab(Tab(view, 'Tab 1', '1', contents1)) contents2 = P.factory(text='And another ... to give content to the second tab.') tabbed_panel.add_tab(Tab(view, 'Tab 2', '2', contents2)) contents3 = P.factory(text='Something else on the third tab.') tabbed_panel.add_tab(Tab(view, 'Tab 3', '3', contents3))
def __init__(self, view): super(PopulatedTabbedPanel, self).__init__(view) multi_tab = MultiTab(view, 'multitab name', 'multi-main') tab1 = Tab(view, 'tab 1 name', 'multi1', P.factory(text='tab 1/1 content')) tab2 = Tab(view, 'tab 2 name', 'multi2', P.factory(text='tab 1/2 content')) multi_tab.add_tab(tab1) multi_tab.add_tab(tab2) self.add_tab(multi_tab) tab3 = Tab(view, 'tab 3 name', 'tab3', P.factory(text='tab 3 content')) self.add_tab(tab3) tab4 = Tab(view, 'tab 4 name', 'tab4', P.factory(text='tab 4 content')) self.add_tab(tab4)
def test_default_active_tab(web_fixture, default_tab_scenarios): """The first tab is active by default (if the active tab is not indicated in the query_string).""" tab1 = Tab(web_fixture.view, 'tab 1 name', 'tab1', P.factory(text='tab 1 content')) tab2 = Tab(web_fixture.view, 'tab 2 name', 'tab2', P.factory(text='tab 2 content')) tabbed_panel = TabbedPanel(web_fixture.view) tabbed_panel.add_tab(tab1) tabbed_panel.add_tab(tab2) [menu_item1, menu_item2] = tabbed_panel.nav.menu_items assert menu_item1.is_active == default_tab_scenarios.tab1_active assert menu_item2.is_active == default_tab_scenarios.tab2_active tester = WidgetTester(tabbed_panel) panel_contents = tester.get_html_for('//div[@class="tab-content"]/div[contains(@class, "active")]/*') assert panel_contents == default_tab_scenarios.expected_contents
def basic_rendering(fixture): """A TabbedPanel consists of a Nav (its tabs) and a Div in which tab contents are displayed.""" fixture.request.query_string = 'tab=tab1' tabbed_panel = TabbedPanel(fixture.view) tabbed_panel.add_tab( Tab(fixture.view, 'tab 1 name', 'tab1', P.factory(text='tab 1 content'))) tester = WidgetTester(tabbed_panel) expected_html = \ '''<ul class="nav nav-tabs reahl-menu">'''\ '''<li class="nav-item">'''\ '''<a data-target="#tab_tab1" data-toggle="tab" href="/?tab=tab1" class="active nav-link">tab 1 name</a>'''\ '''</li>'''\ '''</ul>'''\ '''<div class="tab-content">'''\ '''<div id="tab_tab1" class="active tab-pane"><p>tab 1 content</p></div>'''\ '''</div>'''\ actual = tester.render_html() vassert(actual == expected_html)
def test_basic_rendering(web_fixture): """A TabbedPanel consists of a Nav (its tabs) and a Div in which tab contents are displayed.""" web_fixture.request.query_string = 'tab=tab1' tabbed_panel = TabbedPanel(web_fixture.view) tabbed_panel.add_tab(Tab(web_fixture.view, 'tab 1 name', 'tab1', P.factory(text='tab 1 content'))) tester = WidgetTester(tabbed_panel) expected_html = \ '''<ul role="tablist" class="nav nav-tabs reahl-menu">'''\ '''<li class="nav-item">'''\ '''<a id="nav_tab_tab1_tab" aria-controls="tab_tab1" aria-selected="true" data-target="#tab_tab1" data-toggle="tab" href="/?tab=tab1" role="tab" class="active nav-link">tab 1 name</a>'''\ '''</li>'''\ '''</ul>'''\ '''<div class="tab-content">'''\ '''<div id="tab_tab1" aria-labelledby="nav_tab_tab1_tab" role="tabpanel" class="active tab-pane"><p>tab 1 content</p></div>'''\ '''</div>'''\ actual = tester.render_html() assert actual == expected_html