Example #1
0
    def setUp(self):
        self.controller = mock.Mock()

        self.displayer_context = DisplayerContext(
            StaticDataStore(["summary 1", "summary 2"]),
            BaseDisplayer())

        self.context = mock.Mock()
        self.context.config = Config()

        self.widget = SummaryListWidget(
            self.displayer_context,
            controller=self.controller,
            context=self.context)

        self.displayer_context.store.setup()
Example #2
0
class TestSummaryListWidget(unittest.TestCase):
    def setUp(self):
        self.controller = mock.Mock()

        self.displayer_context = DisplayerContext(
            StaticDataStore(["summary 1", "summary 2"]),
            BaseDisplayer())

        self.context = mock.Mock()
        self.context.config = Config()

        self.widget = SummaryListWidget(
            self.displayer_context,
            controller=self.controller,
            context=self.context)

        self.displayer_context.store.setup()

    def test_render(self):
        self.assertEqual(
            render_to_content(self.widget, (9, 2)),
            render_widgets_to_content([
                urwid.AttrMap(urwid.Text("summary 1"), "summary"),
                urwid.AttrMap(urwid.Text("summary 2"), "summary")
            ], (9, 2))
        )

    def test_open_search(self):
        self.widget._open_search()
        self.controller.open_edit.assert_called_with(self.widget.search_widget)

    def test_filter(self):
        self.widget._filter("summary 1")
        self.assertIsInstance(self.widget.current_walker, FilterSummaryListWalker)
        self.assertEqual(len(self.widget.current_walker), 1)

    def test_filter_with_empty(self):
        self.widget._filter("")
        self.assertIs(
            self.widget.current_walker,
            self.widget.base_walker)

    def test_keypress_open_search(self):
        self.widget.keypress(None, "/")
        self.controller.open_edit.assert_called_with(self.widget.search_widget)

    def test_keypress_clear_search(self):
        self.widget._filter("test")
        self.assertEqual(len(self.widget.current_walker), 0)

        self.widget.keypress((0,), "q")
        self.assertIs(
            self.widget.current_walker,
            self.widget.base_walker)
        self.assertEqual(len(self.widget.current_walker), 2)

    def test_keypress_back(self):
        self.widget.keypress((0,), "q")
        self.controller.back.assert_called_with()

    def test_keypress_open_help(self):
        self.assertIsNone(self.widget.keypress((0, 0), "?"))
        self.controller.open_view.assert_called_with(self.widget.help_widget)

    def test_keypress_bottom_and_top(self):
        self.widget.keypress((10, 10), "G")
        self.assertEqual(self.widget._w.focus_position, 1)
        self.controller._update_info.assert_called_with(
            self.widget, "GViewer[2/2]")

        self.widget.keypress((10, 10), "g")
        self.assertEqual(self.widget._w.focus_position, 0)
        self.controller._update_info.assert_called_with(
            self.widget, "GViewer[1/2]")

    def test_keypress_bottom_and_top_when_search(self):
        self.widget._filter("summary")
        self.widget.keypress((10, 10), "G")
        self.assertEqual(self.widget._w.focus_position, 1)
        self.widget.keypress((10, 10), "g")
        self.assertEqual(self.widget._w.focus_position, 0)

    def test_keypress_clear_item(self):
        self.widget.keypress((10, 10), "x")
        self.assertEqual(len(self.widget.current_walker), 1)
        self.controller._update_info.assert_called_with(
            self.widget, "GViewer[1/1]")

    def test_keypress_clear_items(self):
        self.widget.keypress((10, 10), "X")
        self.assertEqual(len(self.widget.current_walker), 0)
        self.controller._update_info.assert_called_with(
            self.widget, "GViewer[0/0]")

    def test_keypress_up_and_down(self):
        self.widget.keypress((10, 10), "down")
        self.assertEqual(self.widget._w.focus_position, 1)
        self.controller._update_info.assert_called_with(
            self.widget, "GViewer[2/2]")

        self.widget.keypress((10, 10), "up")
        self.assertEqual(self.widget._w.focus_position, 0)
        self.controller._update_info.assert_called_with(
            self.widget, "GViewer[1/2]")

    def test_auto_scroll(self):
        displayer_context = DisplayerContext(
            StaticDataStore(["summary 1", "summary 2"]),
            BaseDisplayer())
        self.context.config = Config(auto_scroll=True)
        widget = SummaryListWidget(
            displayer_context,
            controller=self.controller,
            context=self.context)
        displayer_context.store.setup()

        self.assertEqual(widget._w.focus_position, 1)
        widget.current_walker.recv("summary 3")
        self.assertEqual(widget._w.focus_position, 2)

        widget._w.set_focus(0)
        widget.current_walker.recv("summary 4")
        self.assertEqual(widget._w.focus_position, 0)