@Test public void testOnInsertString() { // Given: selectedTU = currentPageRows.get(0); when(editor.getId()).thenReturn(selectedTU.getId()); when(display.getId()).thenReturn(selectedTU.getId()); when(display.getEditors()).thenReturn(Lists.newArrayList(editor)); when(tableEditorMessages.notifyCopied()).thenReturn("copied"); when(sourceContentPresenter.getSourceContent(selectedTU.getId())) .thenReturn(Optional.of("source content")); presenter.setStatesForTesting(selectedTU.getId(), 0, display); // When: presenter.onInsertString(new InsertStringInEditorEvent("", "suggestion")); // Then: verify(editor).insertTextInCursorPosition("suggestion"); verify(eventBus, atLeastOnce()).fireEvent(eventCaptor.capture()); NotificationEvent notificationEvent = TestFixture.extractFromEvents(eventCaptor.getAllValues(), NotificationEvent.class); MatcherAssert.assertThat(notificationEvent.getMessage(), Matchers.equalTo("copied")); RunValidationEvent runValidationEvent = TestFixture.extractFromEvents(eventCaptor.getAllValues(), RunValidationEvent.class); assertThat(runValidationEvent.getSourceContent(), equalTo("source content")); }
@Test public void testRegisterEditorActionKeys() { // by default user config settings when(messages.saveAsFuzzy()).thenReturn("save fuzzy"); when(messages.saveAsTranslated()).thenReturn("save approved"); when(messages.copyFromSource()).thenReturn("copy from source"); when(messages.switchBetweenEditor()).thenReturn("switch editor"); keyShortcuts.registerEditorActionKeys(targetContentsPresenter); verify(keyShortcutPresenter, times(4)).register(keyShortcutCaptor.capture()); List<KeyShortcut> keys = keyShortcutCaptor.getAllValues(); assertKeys(keys.get(0), "save fuzzy", true, true, new Keys(Keys.CTRL_KEY, 'S')); assertKeys( keys.get(1), "save approved", true, true, new Keys(Keys.CTRL_KEY, KeyCodes.KEY_ENTER)); assertKeys(keys.get(2), "copy from source", true, true, new Keys(Keys.ALT_KEY, 'G')); assertAttentionKeys(keys.get(2), new Keys('G')); assertKeys(keys.get(3), "switch editor", true, true, new Keys(Keys.CTRL_ALT_KEYS, 'H')); }
@Test public void testOnUserConfigChangedNavOption() throws Exception { // Given: change user config esc to close edit when(messages.nextDraft()).thenReturn("next fuzzy"); when(messages.prevDraft()).thenReturn("prev fuzzy"); keyShortcuts.registerNavigationKeys(targetContentsPresenter); configHolder.setNavOption(NavOption.FUZZY); // When: keyShortcuts.onUserConfigChanged(UserConfigChangeEvent.EDITOR_CONFIG_CHANGE_EVENT); // Then: verify(keyShortcutPresenter, atLeastOnce()).register(keyShortcutCaptor.capture()); List<KeyShortcut> allKeys = keyShortcutCaptor.getAllValues(); KeyShortcut nextState = allKeys.get(2); KeyShortcut prevState = allKeys.get(3); assertThat(nextState.getDescription(), Matchers.equalTo("next fuzzy")); assertThat(prevState.getDescription(), Matchers.equalTo("prev fuzzy")); }
@Test public void testRegisterCopyTMKeys() { when(messages.copyFromTM(1)).thenReturn("copy from tm 1"); when(messages.copyFromTM(2)).thenReturn("copy from tm 2"); when(messages.copyFromTM(3)).thenReturn("copy from tm 3"); when(messages.copyFromTM(4)).thenReturn("copy from tm 4"); keyShortcuts.registerCopyTMKeys(); verify(keyShortcutPresenter, times(4)).register(keyShortcutCaptor.capture()); List<KeyShortcut> keys = keyShortcutCaptor.getAllValues(); assertKeys( keys.get(0), "copy from tm 1", false, false, new Keys(Keys.CTRL_ALT_KEYS, Keys.KEY_1), new Keys(Keys.CTRL_ALT_KEYS, Keys.KEY_NUM_1)); assertKeys( keys.get(1), "copy from tm 2", false, false, new Keys(Keys.CTRL_ALT_KEYS, Keys.KEY_2), new Keys(Keys.CTRL_ALT_KEYS, Keys.KEY_NUM_2)); assertKeys( keys.get(2), "copy from tm 3", false, false, new Keys(Keys.CTRL_ALT_KEYS, Keys.KEY_3), new Keys(Keys.CTRL_ALT_KEYS, Keys.KEY_NUM_3)); assertKeys( keys.get(3), "copy from tm 4", false, false, new Keys(Keys.CTRL_ALT_KEYS, Keys.KEY_4), new Keys(Keys.CTRL_ALT_KEYS, Keys.KEY_NUM_4)); }
@Test public void testRegisterNavigationKeys() { when(messages.moveToNextRow()).thenReturn("next entry"); when(messages.moveToPreviousRow()).thenReturn("previous entry"); when(messages.nextIncomplete()).thenReturn("next fuzzy or untranslated"); when(messages.prevIncomplete()).thenReturn("previous fuzzy or untranslated"); keyShortcuts.registerNavigationKeys(targetContentsPresenter); verify(keyShortcutPresenter, times(4)).register(keyShortcutCaptor.capture()); List<KeyShortcut> keys = keyShortcutCaptor.getAllValues(); assertKeys( keys.get(0), "next entry", true, true, new Keys(Keys.ALT_KEY, KeyCodes.KEY_DOWN), new Keys(Keys.ALT_KEY, 'K')); assertKeys( keys.get(1), "previous entry", true, true, new Keys(Keys.ALT_KEY, KeyCodes.KEY_UP), new Keys(Keys.ALT_KEY, 'J')); assertKeys( keys.get(2), "next fuzzy or untranslated", true, true, new Keys(Keys.ALT_KEY, KeyCodes.KEY_PAGEDOWN)); assertKeys( keys.get(3), "previous fuzzy or untranslated", true, true, new Keys(Keys.ALT_KEY, KeyCodes.KEY_PAGEUP)); }
@Test public void registerEditorActionKeysAfterChangeUserConfig() { // enter and esc now active when(messages.saveAsFuzzy()).thenReturn("save fuzzy"); when(messages.saveAsTranslated()).thenReturn("save approved"); when(messages.copyFromSource()).thenReturn("copy from source"); when(messages.switchBetweenEditor()).thenReturn("switch editor"); configHolder.setEnterSavesApproved(true); keyShortcuts.registerEditorActionKeys(targetContentsPresenter); verify(keyShortcutPresenter, times(5)).register(keyShortcutCaptor.capture()); List<KeyShortcut> keys = keyShortcutCaptor.getAllValues(); assertKeys(keys.get(0), "save fuzzy", true, true, new Keys(Keys.CTRL_KEY, 'S')); assertKeys( keys.get(1), "save approved", true, true, new Keys(Keys.CTRL_KEY, KeyCodes.KEY_ENTER)); assertKeys( keys.get(2), "save approved", true, true, new Keys(Keys.NO_MODIFIER, KeyCodes.KEY_ENTER)); assertKeys(keys.get(3), "copy from source", true, true, new Keys(Keys.ALT_KEY, 'G')); assertAttentionKeys(keys.get(3), new Keys('G')); assertKeys(keys.get(4), "switch editor", true, true, new Keys(Keys.CTRL_ALT_KEYS, 'H')); }
@Test public void testOnTransMemoryCopy() { when(tableEditorMessages.notifyCopied()).thenReturn("copied"); selectedTU = currentPageRows.get(0); when(display.getId()).thenReturn(selectedTU.getId()); when(display.getEditors()).thenReturn(Lists.newArrayList(editor)); presenter.setStatesForTesting(selectedTU.getId(), 0, display); presenter.onDataCopy(new CopyDataToEditorEvent(Arrays.asList("target"))); verify(editor).setTextAndValidate("target"); verify(eventBus, atLeastOnce()).fireEvent(eventCaptor.capture()); NotificationEvent notificationEvent = TestFixture.extractFromEvents(eventCaptor.getAllValues(), NotificationEvent.class); MatcherAssert.assertThat(notificationEvent.getMessage(), Matchers.equalTo("copied")); }
@Test public void testOnUserConfigChangedToEnterSaves() throws Exception { // Given: change user config enter save approved when(messages.saveAsTranslated()).thenReturn("enter save as approved"); keyShortcuts.registerKeys(targetContentsPresenter); configHolder.setEnterSavesApproved(true); // When: keyShortcuts.onUserConfigChanged(UserConfigChangeEvent.EDITOR_CONFIG_CHANGE_EVENT); // Then: verify(keyShortcutPresenter, atLeastOnce()).register(keyShortcutCaptor.capture()); List<KeyShortcut> allKeys = keyShortcutCaptor.getAllValues(); KeyShortcut shortcut = allKeys.get(allKeys.size() - 1); // last key assertKeys( shortcut, "enter save as approved", true, true, new Keys(Keys.NO_MODIFIER, KeyCodes.KEY_ENTER)); }