def test_mergeGroups(self): """ L{methanal.widgets.TabGroup.mergeGroups} will merge two L{methanal.widgets.TabGroup}s together, preferring the metadata of the second specified group. """ tabs = [ widgets.Tab(u'id1', u'Title 1', None), widgets.Tab(u'id2', u'Title 2', None) ] tabGroup1 = widgets.TabGroup(u'id', u'Title', tabs=tabs) tabs = [widgets.Tab(u'id3', u'Title 3', None)] tabGroup2 = widgets.TabGroup(u'id', u'Hello', tabs=tabs) newGroup = widgets.TabGroup.mergeGroups(tabGroup1, tabGroup2) self.assertEquals(newGroup.id, u'id') self.assertEquals(newGroup.title, u'Hello') self.assertEquals(newGroup.tabs, tabGroup1.tabs + tabGroup2.tabs)
def test_repr(self): """ L{methanal.widgets.TabGroup} has an accurate string representation. """ tabs = [ widgets.Tab(u'id1', u'Title 1', None), widgets.Tab(u'id2', u'Title 2', None) ] tabGroup = widgets.TabGroup(u'id', u'Title', tabs=tabs) self.assertEquals(repr(tabGroup), "<TabGroup id=u'id' title=u'Title' tabs=%r>" % tabs)
def test_athenaSerializable(self): """ Tab groups implement L{nevow.inevow.IAthenaTransportable}. """ tabs = [ widgets.Tab(u'id1', u'Title 1', None), widgets.Tab(u'id2', u'Title 2', None) ] tabGroup = widgets.TabGroup(u'id', u'Title', tabs=tabs) self.assertEquals( inevow.IAthenaTransportable(tabGroup).getInitialArguments(), [u'id', u'Title', [u'id1', u'id2']])
def test_updateGroup(self): """ Updating a group on the server site manages it, and all the tabs it contains, and invokes methods on the client side to insert them. """ self.result = None def callRemote(methodName, *a): self.result = methodName == '_updateTabsFromServer' tab = widgets.Tab(u'id4', u'Title 4', self.contentFactory) group = widgets.TabGroup(u'group1', u'Group', tabs=[tab]) self.patch(self.tabView, 'callRemote', callRemote) self.tabView.updateGroup(group) self.assertTrue(self.result) self.assertNotIdentical(self.tabView.getTab(u'id4'), None) self.assertNotIdentical(self.tabView.getGroup(u'group1'), None) self.assertIdentical(self.tabView.tabs[-1], tab) # Update a group, and add a new tab. newTab = widgets.Tab(u'id5', u'Title 5', self.contentFactory) replacementGroup = widgets.TabGroup(u'group1', u'New Group', tabs=[newTab]) self.tabView.updateGroup(replacementGroup) self.assertIdentical(self.tabView.getGroup(u'group1'), replacementGroup) self.assertNotIdentical(self.tabView.getTab(u'id5'), None) self.assertRaises(errors.InvalidIdentifier, self.tabView.getTab, u'id4') self.assertNotIn(tab, self.tabView.tabs) # Remove a tab from a group. self.tabView.removeTabs([newTab]) self.assertRaises(errors.InvalidIdentifier, self.tabView.getTab, u'id5') self.assertNotIn(newTab, self.tabView.getGroup(u'group1').tabs)
def test_createGroup(self): """ Creating a L{methanal.widgets.TabView} widget initialises L{methanal.widgets.TabView._tabsByID}, L{methanal.widgets.TabView.tabs} and L{methanal.widgets.TabView._tabGroups} with the values originally specified, tab groups are merged in and managed. """ tabGroup = widgets.TabGroup( u'group1', u'Group', tabs=[widgets.Tab(u'id4', u'Title 4', self.contentFactory)]) tabs = self.tabs + [ tabGroup, widgets.Tab(u'id5', u'Title 5', self.contentFactory) ] tabView = widgets.TabView(tabs) self.assertEquals(tabView.getTabIDs(), [u'id1', u'id2', u'id3', u'id4', u'id5']) self.assertEquals(tabView._tabGroups, {u'group1': tabGroup})