Example #1
0
    def test_next_then_previous_changes_direction(self, view, presenter,
                                                  editor):
        view.get_options.return_value = FindReplaceOptions(
            True, True, True, True)

        presenter.action_next()
        self.assertNotCalled(view.find.setFocus)
        self.assertEqual(presenter.current_direction, SearchDirection.FORWARD)

        view.get_options.assert_called_once_with()
        editor.findFirst.assert_called_once_with(self.default_search_string,
                                                 True, True, True, True, True)

        presenter.action_next()
        self.assertEqual(presenter.current_direction, SearchDirection.FORWARD)
        editor.findNext.assert_called_once_with()

        editor.findFirst.reset_mock()
        editor.findNext.reset_mock()
        view.get_options.reset_mock()

        presenter.action_previous()
        view.get_options.assert_called_once_with()
        self.assertEqual(presenter.current_direction, SearchDirection.BACKWARD)
        editor.findFirst.assert_called_once_with(self.default_search_string,
                                                 True, True, True, True, False)
        editor.findNext.assert_called_once_with()
        presenter.action_previous()
        self.assertEqual(2, editor.findNext.call_count)
Example #2
0
    def test_action_next_reset_search(self, view, presenter, editor):
        view.get_options.return_value = FindReplaceOptions(
            True, True, True, True)
        presenter.action_next()
        self.assertNotCalled(view.find.setFocus)

        view.get_options.assert_called_once_with()
        editor.findFirst.assert_called_once_with(self.default_search_string,
                                                 True, True, True, True, True)
        self.assertNotCalled(editor.findNext)
        self.assertEqual(presenter.current_direction, SearchDirection.FORWARD)

        presenter.action_next()
        editor.findNext.assert_called_once_with()

        presenter.action_next()
        self.assertEqual(2, editor.findNext.call_count)

        presenter.clear_search()
        view.find.currentText = Mock(return_value="wowowow")

        editor.findFirst.reset_mock()
        editor.findNext.reset_mock()

        presenter.action_next()
        self.assertEqual(presenter.current_direction, SearchDirection.FORWARD)
        editor.findFirst.assert_called_once_with("wowowow", True, True, True,
                                                 True, True)
        self.assertNotCalled(editor.findNext)

        for i in range(1, 10):
            presenter.action_next()
            self.assertEqual(i, editor.findNext.call_count)
Example #3
0
    def test_action_replace_all(self, view, presenter, editor):
        view.get_options.return_value = FindReplaceOptions(
            True, True, True, True)

        presenter.action_replace_all()
        editor.replaceAll.assert_called_once_with(self.default_search_string,
                                                  "tomato", True, True, True,
                                                  True, True)
Example #4
0
 def test_action_previous(self, view, presenter, editor):
     view.get_options.return_value = FindReplaceOptions(
         True, True, True, True)
     presenter.action_previous()
     view.get_options.assert_called_once_with()
     self.assertEqual(presenter.current_direction, SearchDirection.BACKWARD)
     editor.findFirst.assert_called_once_with(self.default_search_string,
                                              True, True, True, True, False)
     editor.findNext.assert_called_once_with()
Example #5
0
    def test_action_next(self, view, presenter, editor):
        view.get_options.return_value = FindReplaceOptions(
            True, True, True, True)
        presenter.action_next()
        self.assertNotCalled(view.find.setFocus)

        view.get_options.assert_called_once_with()
        editor.findFirst.assert_called_once_with(self.default_search_string,
                                                 True, True, True, True, True)

        presenter.action_next()
        editor.findNext.assert_called_once_with()

        # check that find next is called correctly each time
        for i in range(2, 10):
            presenter.action_next()
            self.assertEqual(i, editor.findNext.call_count)
Example #6
0
    def test_action_replace_no_selected_text_for_replacement(
            self, view, presenter, editor):
        view.get_options.return_value = FindReplaceOptions(
            True, True, True, True)
        editor.hasSelectedText = Mock(return_value=False)

        presenter.action_replace()

        editor.findFirst.assert_called_once_with(self.default_search_string,
                                                 True, True, True, True, True)

        # if text is selected, but something else is selected in the editor
        editor.hasSelectedText = Mock(return_value=True)
        editor.selectedText = Mock(return_value="not_a_doorway")

        presenter.action_replace()

        editor.findFirst.assert_called_once_with(self.default_search_string,
                                                 True, True, True, True, True)