Skip to content

Commit

Permalink
Keycodes: Accurately test non-primary event key modifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
aduth committed Mar 9, 2020
1 parent 743f93d commit 05bd721
Showing 1 changed file with 34 additions and 22 deletions.
56 changes: 34 additions & 22 deletions packages/keycodes/src/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,11 @@ describe( 'isKeyboardEvent', () => {
expect.assertions( 3 );
const attachNode = attachEventListeners( ( event ) => {
expect(
isKeyboardEvent.primary( event, undefined, isAppleOSFalse )
isKeyboardEvent.primaryShift(
event,
undefined,
isAppleOSFalse
)
).toBe( true );
} );

Expand All @@ -374,7 +378,11 @@ describe( 'isKeyboardEvent', () => {
expect.assertions( 3 );
const attachNode = attachEventListeners( ( event ) => {
expect(
isKeyboardEvent.primary( event, undefined, isAppleOSTrue )
isKeyboardEvent.primaryShift(
event,
undefined,
isAppleOSTrue
)
).toBe( true );
} );

Expand All @@ -389,7 +397,7 @@ describe( 'isKeyboardEvent', () => {
expect.assertions( 3 );
const attachNode = attachEventListeners( ( event ) => {
expect(
isKeyboardEvent.primary( event, 'm', isAppleOSFalse )
isKeyboardEvent.primaryShift( event, 'm', isAppleOSFalse )
).toBe( true );
} );

Expand All @@ -404,7 +412,7 @@ describe( 'isKeyboardEvent', () => {
expect.assertions( 3 );
const attachNode = attachEventListeners( ( event ) => {
expect(
isKeyboardEvent.primary( event, 'm', isAppleOSTrue )
isKeyboardEvent.primaryShift( event, 'm', isAppleOSTrue )
).toBe( true );
} );

Expand All @@ -421,7 +429,11 @@ describe( 'isKeyboardEvent', () => {
expect.assertions( 3 );
const attachNode = attachEventListeners( ( event ) => {
expect(
isKeyboardEvent.primary( event, undefined, isAppleOSFalse )
isKeyboardEvent.secondary(
event,
undefined,
isAppleOSFalse
)
).toBe( true );
} );

Expand All @@ -437,7 +449,7 @@ describe( 'isKeyboardEvent', () => {
expect.assertions( 3 );
const attachNode = attachEventListeners( ( event ) => {
expect(
isKeyboardEvent.primary( event, undefined, isAppleOSTrue )
isKeyboardEvent.secondary( event, undefined, isAppleOSTrue )
).toBe( true );
} );

Expand All @@ -453,7 +465,7 @@ describe( 'isKeyboardEvent', () => {
expect.assertions( 3 );
const attachNode = attachEventListeners( ( event ) => {
expect(
isKeyboardEvent.primary( event, 'm', isAppleOSFalse )
isKeyboardEvent.secondary( event, 'm', isAppleOSFalse )
).toBe( true );
} );

Expand All @@ -469,7 +481,7 @@ describe( 'isKeyboardEvent', () => {
expect.assertions( 3 );
const attachNode = attachEventListeners( ( event ) => {
expect(
isKeyboardEvent.primary( event, 'm', isAppleOSTrue )
isKeyboardEvent.secondary( event, 'm', isAppleOSTrue )
).toBe( true );
} );

Expand All @@ -483,61 +495,61 @@ describe( 'isKeyboardEvent', () => {
} );

describe( 'access', () => {
it( 'should identify modifier key when Alt + Ctrl is pressed', () => {
it( 'should identify modifier key when Shift + Alt is pressed', () => {
expect.assertions( 3 );
const attachNode = attachEventListeners( ( event ) => {
expect(
isKeyboardEvent.primary( event, undefined, isAppleOSFalse )
isKeyboardEvent.access( event, undefined, isAppleOSFalse )
).toBe( true );
} );

keyPress( attachNode, {
ctrlKey: true,
shiftKey: true,
altKey: true,
key: 'Ctrl',
key: 'Alt',
} );
} );

it( 'should identify modifier key when ⌥⌘ is pressed', () => {
it( 'should identify modifier key when Ctrl + ⌥ is pressed', () => {
expect.assertions( 3 );
const attachNode = attachEventListeners( ( event ) => {
expect(
isKeyboardEvent.primary( event, undefined, isAppleOSTrue )
isKeyboardEvent.access( event, undefined, isAppleOSTrue )
).toBe( true );
} );

keyPress( attachNode, {
metaKey: true,
ctrlKey: true,
altKey: true,
key: 'Meta',
key: 'Alt',
} );
} );

it( 'should identify modifier key when Ctrl + ALt + M is pressed', () => {
it( 'should identify modifier key when Shift + Alt + M is pressed', () => {
expect.assertions( 3 );
const attachNode = attachEventListeners( ( event ) => {
expect(
isKeyboardEvent.primary( event, 'm', isAppleOSFalse )
isKeyboardEvent.access( event, 'm', isAppleOSFalse )
).toBe( true );
} );

keyPress( attachNode, {
ctrlKey: true,
shiftKey: true,
altKey: true,
key: 'm',
} );
} );

it( 'should identify modifier key when ⌥⌘M is pressed', () => {
it( 'should identify modifier key when Ctrl + ⌥M is pressed', () => {
expect.assertions( 3 );
const attachNode = attachEventListeners( ( event ) => {
expect(
isKeyboardEvent.primary( event, 'm', isAppleOSTrue )
isKeyboardEvent.access( event, 'm', isAppleOSTrue )
).toBe( true );
} );

keyPress( attachNode, {
metaKey: true,
ctrlKey: true,
altKey: true,
key: 'm',
} );
Expand Down

0 comments on commit 05bd721

Please sign in to comment.