def test_widget(self): view = View([ Group("group1", [Text("content1")]), Group("group2", [Text("content2")])] ) widget = view.widget(None) self.assertTrue(isinstance(widget, ContentWidget)) contents = widget._w.body self.assertEqual(len(contents), 6) self.assertIsInstance(contents[0], TitleWidget) self.assertIsInstance(contents[1], SearchableText) self.assertIsInstance(contents[2], EmptyLine) self.assertIsInstance(contents[3], TitleWidget) self.assertIsInstance(contents[4], SearchableText) self.assertIsInstance(contents[5], EmptyLine)
def test_actions(self): action = mock.Mock() controller = mock.Mock() context = mock.Mock() context.config.keys = dict() view = View([ Group("group1", [Text("content1")]), Group("group2", [Text("content2")])], actions=dict(a=action) ) widget = view.widget("message", controller=controller, context=context) widget.keypress((0, 0), "a") action.assert_called_with(controller, "message") self.assertEqual( widget.keypress((0, 0), "b"), "b")
def test_empty_widget(self): view = View([]) contents = view.widget(None)._w.body self.assertEqual(len(contents), 1) self.assertIsInstance(contents[0], EmptyLine)