verify(keyShortcutPresenter, times(3)).register(
keyShortcutCaptor.capture());
List<KeyShortcut> shortcuts = keyShortcutCaptor.getAllValues();
// test keys
KeyShortcut prevKey = shortcuts.get(0);
assertThat(prevKey.getAllKeys(), Matchers.equalTo(Keys.setOf(new Keys(
Keys.ALT_KEY, KeyCodes.KEY_UP), new Keys(Keys.ALT_KEY, 'J'))));
assertThat(prevKey.getDescription(), Matchers.equalTo("previous row"));
assertThat(prevKey.getContext(),
Matchers.equalTo(ShortcutContext.Navigation));
assertThat(prevKey.getKeyEvent(),
Matchers.equalTo(KeyShortcut.KeyEvent.KEY_DOWN));
KeyShortcut nextKey = shortcuts.get(1);
assertThat(nextKey.getAllKeys(), Matchers.equalTo(Keys.setOf(new Keys(
Keys.ALT_KEY, KeyCodes.KEY_DOWN), new Keys(Keys.ALT_KEY, 'K'))));
assertThat(nextKey.getDescription(), Matchers.equalTo("next row"));
assertThat(nextKey.getContext(),
Matchers.equalTo(ShortcutContext.Navigation));
assertThat(nextKey.getKeyEvent(),
Matchers.equalTo(KeyShortcut.KeyEvent.KEY_DOWN));
KeyShortcut enterKey = shortcuts.get(2);
assertThat(enterKey.getAllKeys(), Matchers.contains(new Keys(
Keys.NO_MODIFIER, KeyCodes.KEY_ENTER)));
assertThat(enterKey.getDescription(), Matchers.equalTo("open editor"));
assertThat(enterKey.getContext(),
Matchers.equalTo(ShortcutContext.Navigation));
assertThat(enterKey.getKeyEvent(),
Matchers.equalTo(KeyShortcut.KeyEvent.KEY_UP));
// test key handlers
prevKey.getHandler().onKeyShortcut(null);
verify(targetContentsPresenter, atLeastOnce())
.savePendingChangesIfApplicable();
verify(eventBus).fireEvent(
new NavTransUnitEvent(
NavTransUnitEvent.NavigationType.PrevEntry));
nextKey.getHandler().onKeyShortcut(null);
verify(targetContentsPresenter, atLeastOnce())
.savePendingChangesIfApplicable();
verify(eventBus).fireEvent(
new NavTransUnitEvent(
NavTransUnitEvent.NavigationType.NextEntry));
// by default all other presenters are not focused
when(translationEditorPresenter.getDisplay()).thenReturn(
translationEditorDisplay);
enterKey.getHandler().onKeyShortcut(null);
verify(targetContentsPresenter).setFocus();
verify(targetContentsPresenter).revealDisplay();
}