From faec808b08f0993e4af4e2abb30e4723d7dd8526 Mon Sep 17 00:00:00 2001 From: ria02 Date: Sat, 28 Aug 2021 19:48:57 +1000 Subject: [PATCH] test(fuzzy): add test for #20 --- tests/prompts/test_fuzzy.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/tests/prompts/test_fuzzy.py b/tests/prompts/test_fuzzy.py index 237a8ff..cb40cc4 100644 --- a/tests/prompts/test_fuzzy.py +++ b/tests/prompts/test_fuzzy.py @@ -1,7 +1,8 @@ +from InquirerPy.base.complex import BaseComplexPrompt import asyncio import unittest from typing import Callable, NamedTuple -from unittest.mock import ANY, MagicMock, patch +from unittest.mock import ANY, MagicMock, call, patch from prompt_toolkit.application.application import Application from prompt_toolkit.buffer import Buffer @@ -718,3 +719,17 @@ def test_on_rendered(self, mocked, mocked_change): mocked.assert_called_once() self.assertEqual(prompt._buffer.text, "yes") self.assertEqual(prompt._buffer.cursor_position, 3) + + @patch.object(FuzzyPrompt, "_on_rendered") + @patch.object(BaseComplexPrompt, "_register_kb") + def test_constructor_keybindings(self, mocked_kb, mocked_rendered): + prompt = FuzzyPrompt(message="", choices=[1, 2, 3]) + prompt._after_render(None) + try: + mocked_kb.assert_has_calls([call("space", filter=ANY)]) + mocked_kb.assert_has_calls([call("j", filter=ANY)]) + mocked_kb.assert_has_calls([call("k", filter=ANY)]) + except AssertionError: + pass + else: + self.fail("space/j/k kb was registered")