Search in sources :

Example 1 with PeripheralKeymap

use of com.ichi2.anki.reviewer.PeripheralKeymap in project Anki-Android by ankidroid.

the class PeripheralKeymapTest method flagAndAnswerDoNotConflict.

@Test
public void flagAndAnswerDoNotConflict() {
    List<ViewerCommand> processed = new ArrayList<>();
    PeripheralKeymap peripheralKeymap = new PeripheralKeymap(new MockReviewerUi(), processed::add);
    peripheralKeymap.setup(mock(SharedPreferences.class));
    KeyEvent event = mock(KeyEvent.class);
    when(event.getUnicodeChar()).thenReturn(0);
    when(event.isCtrlPressed()).thenReturn(true);
    when(event.getUnicodeChar(0)).thenReturn(49);
    when(event.getKeyCode()).thenReturn(KeyEvent.KEYCODE_1);
    assertThat((char) event.getUnicodeChar(), is('\0'));
    assertThat((char) event.getUnicodeChar(0), is('1'));
    peripheralKeymap.onKeyDown(KeyEvent.KEYCODE_1, event);
    assertThat(processed, hasSize(1));
    assertThat(processed.get(0), is(ViewerCommand.COMMAND_TOGGLE_FLAG_RED));
}
Also used : KeyEvent(android.view.KeyEvent) SharedPreferences(android.content.SharedPreferences) ArrayList(java.util.ArrayList) ViewerCommand(com.ichi2.anki.cardviewer.ViewerCommand) Test(org.junit.Test)

Aggregations

SharedPreferences (android.content.SharedPreferences)1 KeyEvent (android.view.KeyEvent)1 ViewerCommand (com.ichi2.anki.cardviewer.ViewerCommand)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1