def test_dictToAction_shouldRaiseValueIfCommandIsUnknown(self):
        # Given
        source: dict = {
            "command": "This is an invalid test command",
            "searchStrategy": 0,
            "searchIdentifier": "",
            "textToSend": "",
            "maxWait": 0.0
        }
        target = Action
        sut = DictActionConverter(source, target)

        # When / Then
        with self.assertRaises(ValueError):
            sut.getConverted()
    def test_actionToDict_QuitBrowserAction(self):
        # Given
        source = QuitBrowserAction()
        target = dict
        sut = DictActionConverter(source, target)

        # When
        dataDict = sut.getConverted()

        # Then
        self.assertIsInstance(dataDict, dict)
        self.assertEqual(ActionCmd.QUIT_BROWSER.value, dataDict.get("command"))
    def test_actionToDict_PauseAction(self):
        # Given
        source = PauseAction(seconds=-123.0)
        target = dict
        sut = DictActionConverter(source, target)

        # When
        dataDict = sut.getConverted()

        # Then
        self.assertIsInstance(dataDict, dict)
        self.assertEqual(ActionCmd.PAUSE.value, dataDict.get("command"))
        self.assertEqual(-123.0, dataDict.get("maxWait"))
    def test_actionToDict_LoadPageAction(self):
        # Given
        source = LoadPageAction(url="Test value of textToSend")
        target = dict
        sut = DictActionConverter(source, target)

        # When
        dataDict = sut.getConverted()

        # Then
        self.assertIsInstance(dataDict, dict)
        self.assertEqual(ActionCmd.LOAD_PAGE.value, dataDict.get("command"))
        self.assertEqual("Test value of textToSend",
                         dataDict.get("textToSend"))
    def test_actionToDict_SubmitAction(self):
        # Given
        searchConditions = Mock(spec_set=SearchConditions)
        searchConditions.searchStrategy = Strategy.BY_ID
        searchConditions.identifier = "Test value of searchIdentifier"
        source = SubmitAction(searchConditions=searchConditions)
        target = dict
        sut = DictActionConverter(source, target)

        # When
        dataDict = sut.getConverted()

        # Then
        self.assertIsInstance(dataDict, dict)
        self.assertEqual(ActionCmd.SUBMIT.value, dataDict.get("command"))
        self.assertEqual(Strategy.BY_ID.value, dataDict.get("searchStrategy"))
        self.assertEqual("Test value of searchIdentifier",
                         dataDict.get("searchIdentifier"))
    def test_dictToAction_QuitBrowserAction(self):
        # Given
        source: dict = {
            "command": ActionCmd.QUIT_BROWSER.value,
            "searchStrategy": Strategy.BY_TEXT.value,
            "searchIdentifier": "Test value of searchIdentifier",
            "textToSend": "Test value of textToSend",
            "maxWait": 0.0
        }
        target = Action
        sut = DictActionConverter(source, target)

        # When
        action = sut.getConverted()

        # Then
        self.assertIsInstance(action, QuitBrowserAction)
        self.assertEqual(ActionCmd.QUIT_BROWSER, action.command)
    def test_dictToAction_LoadPageAction(self):
        # Given
        source: dict = {
            "command": ActionCmd.LOAD_PAGE.value,
            "searchStrategy": Strategy.IGNORE.value,
            "searchIdentifier": "Test value of searchIdentifier",
            "textToSend": "Test value of textToSend",
            "maxWait": 0.0
        }
        target = Action
        sut = DictActionConverter(source, target)

        # When
        action = sut.getConverted()

        # Then
        self.assertIsInstance(action, LoadPageAction)
        self.assertEqual(ActionCmd.LOAD_PAGE, action.command)
        self.assertEqual("Test value of textToSend", action.textToSend)
    def test_dictToAction_PauseAction(self):
        # Given
        source: dict = {
            "command": ActionCmd.PAUSE.value,
            "searchStrategy": Strategy.BY_XPATH.value,
            "searchIdentifier": "Test value of searchIdentifier",
            "textToSend": "Test value of textToSend",
            "maxWait": 10
        }
        target = Action
        sut = DictActionConverter(source, target)

        # When
        action = sut.getConverted()

        # Then
        self.assertIsInstance(action, PauseAction)
        self.assertEqual(ActionCmd.PAUSE, action.command)
        self.assertEqual(10, action.maxWait)
    def test_dictToAction_ClickAction(self):
        # Given
        source: dict = {
            "command": ActionCmd.CLICK.value,
            "searchStrategy": Strategy.BY_ID.value,
            "searchIdentifier": "Test value of searchIdentifier",
            "textToSend": "Test value of textToSend",
            "maxWait": 0.0
        }
        target = Action
        sut = DictActionConverter(source, target)

        # When
        action = sut.getConverted()

        # Then
        self.assertIsInstance(action, ClickAction)
        self.assertEqual(ActionCmd.CLICK, action.command)
        self.assertEqual(Strategy.BY_ID,
                         action.searchConditions.searchStrategy)
        self.assertEqual("Test value of searchIdentifier",
                         action.searchConditions.identifier)
    def test_actionToDict_WaitUntilVisibleAction(self):
        # Given
        searchConditions = Mock(spec_set=SearchConditions)
        searchConditions.searchStrategy = Strategy.BY_XPATH
        searchConditions.identifier = "Test value of searchIdentifier"
        source = WaitUntilVisibleAction(searchConditions=searchConditions,
                                        maxWait=44.12)
        target = dict
        sut = DictActionConverter(source, target)

        # When
        dataDict = sut.getConverted()

        # Then
        self.assertIsInstance(dataDict, dict)
        self.assertEqual(ActionCmd.WAIT_UNTIL_VISIBLE.value,
                         dataDict.get("command"))
        self.assertEqual(Strategy.BY_XPATH.value,
                         dataDict.get("searchStrategy"))
        self.assertEqual("Test value of searchIdentifier",
                         dataDict.get("searchIdentifier"))
        self.assertEqual(44.12, dataDict.get("maxWait"))
    def test_dictToAction_WaitUntilVisibleAction(self):
        # Given
        source: dict = {
            "command": ActionCmd.WAIT_UNTIL_VISIBLE.value,
            "searchStrategy": Strategy.BY_XPATH.value,
            "searchIdentifier": "Test value of searchIdentifier",
            "textToSend": "Test value of textToSend",
            "maxWait": 2.65
        }
        target = Action
        sut = DictActionConverter(source, target)

        # When
        action = sut.getConverted()

        # Then
        self.assertIsInstance(action, WaitUntilVisibleAction)
        self.assertEqual(ActionCmd.WAIT_UNTIL_VISIBLE, action.command)
        self.assertEqual(Strategy.BY_XPATH,
                         action.searchConditions.searchStrategy)
        self.assertEqual("Test value of searchIdentifier",
                         action.searchConditions.identifier)
        self.assertEqual(2.65, action.maxWait)