def test_dropdown_menus(web_fixture): """You can add a DropdownMenu as a dropdown inside a Nav.""" menu = Nav(web_fixture.view) sub_menu = DropdownMenu(web_fixture.view) sub_menu.add_a(A(web_fixture.view, Url('/an/url'), description='sub menu item')) menu.add_dropdown('Dropdown title', sub_menu) [item] = menu.html_representation.children assert item.tag_name == 'li' assert 'dropdown' in item.get_attribute('class') [toggle, added_sub_menu] = item.children assert 'dropdown-toggle' in toggle.get_attribute('class') assert 'button' in toggle.get_attribute('role') assert 'true' in toggle.get_attribute('aria-haspopup') assert 'dropdown' in toggle.get_attribute('data-toggle') title_text = toggle.children[0].value assert title_text == 'Dropdown title' assert added_sub_menu is sub_menu assert 'dropdown-menu' in added_sub_menu.html_representation.get_attribute('class').split() assert isinstance(added_sub_menu.html_representation, Div) [dropdown_item] = added_sub_menu.html_representation.children assert isinstance(dropdown_item, A) assert 'dropdown-item' in dropdown_item.get_attribute('class').split()
def dropdown_menus(fixture): """You can add a DropdownMenu as a dropdown inside a Nav.""" menu = Nav(fixture.view) sub_menu = DropdownMenu(fixture.view) sub_menu.add_a(A(fixture.view, Url('/an/url'), description='sub menu item')) menu.add_dropdown('Dropdown title', sub_menu) [item] = menu.html_representation.children vassert(item.tag_name == 'li') vassert('dropdown' in item.get_attribute('class')) [toggle, added_sub_menu] = item.children vassert('dropdown-toggle' in toggle.get_attribute('class')) vassert('dropdown' in toggle.get_attribute('data-toggle')) vassert('-' in toggle.get_attribute('data-target')) vassert('caret' in toggle.children[1].get_attribute('class')) title_text = toggle.children[0].value vassert(title_text == 'Dropdown title') vassert(added_sub_menu is sub_menu) vassert('dropdown-menu' in added_sub_menu.html_representation.get_attribute('class').split()) vassert(isinstance(added_sub_menu.html_representation, Div)) [dropdown_item] = added_sub_menu.html_representation.children vassert(isinstance(dropdown_item, A)) vassert('dropdown-item' in dropdown_item.get_attribute('class').split())
def test_dropdown_menus_right_align(web_fixture): """Dropdown menus can be aligned to the bottom right of their toggle, instead of the default (left).""" defaulted_sub_menu = DropdownMenu(web_fixture.view).use_layout(DropdownMenuLayout()) assert 'dropdown-menu-right' not in defaulted_sub_menu.html_representation.get_attribute('class') right_aligned_sub_menu = DropdownMenu(web_fixture.view).use_layout(DropdownMenuLayout(align_right=True)) assert 'dropdown-menu-right' in right_aligned_sub_menu.html_representation.get_attribute('class')
def test_dropdown_menu_with_header(web_fixture): """You can add a header item to a DropdownMenu.""" sub_menu = DropdownMenu(web_fixture.view) my_header = H(web_fixture.view, 6, text='My header text') header = sub_menu.add_header(my_header) assert header is my_header [header] = sub_menu.html_representation.children assert 'dropdown-header' in header.get_attribute('class').split()
def test_dropdown_menu_with_form(web_fixture): """You can add form to a DropdownMenu.""" sub_menu = DropdownMenu(web_fixture.view) my_form = Form(web_fixture.view, 'myform') form = sub_menu.add_form(my_form) assert form is my_form [form] = sub_menu.html_representation.children assert 'px-4' in form.get_attribute('class').split() assert 'py-3' in form.get_attribute('class').split()
def test_dropdown_menus_with_divider(web_fixture): """You can add a divider to a DropdownMenu.""" sub_menu = DropdownMenu(web_fixture.view) sub_menu.add_a(A(web_fixture.view, Url('/an/url'), description='sub menu item')) sub_menu.add_divider() sub_menu.add_a(A(web_fixture.view, Url('/another/url'), description='another sub menu item')) [item1, divider, item2] = sub_menu.html_representation.children assert 'dropdown-divider' in divider.get_attribute('class').split()
def __init__(self, view, title, tab_key): self.tabs = [] self.menu = DropdownMenu(view) super().__init__(view, title, tab_key, None)