Skip to content

Commit

Permalink
Update tests and docs to reflect that decorators require Ember 3.10 a…
Browse files Browse the repository at this point in the history
…nd higher
  • Loading branch information
lukemelia committed Jun 3, 2020
1 parent 9f262d5 commit 6dd644f
Show file tree
Hide file tree
Showing 8 changed files with 364 additions and 344 deletions.
133 changes: 68 additions & 65 deletions tests/acceptance/ember-keyboard-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { click, fillIn, blur, visit } from '@ember/test-helpers';
import { setupApplicationTest } from 'ember-qunit';
import { set } from '@ember/object';
import { module, test } from 'qunit';
import { gte } from 'ember-compatibility-helpers';

import {
mouseDown,
Expand All @@ -17,100 +18,102 @@ import { getValues, getMouseValues, getTouchValues } from '../helpers/get-values
module('Acceptance | ember keyboard', function(hooks) {
setupApplicationTest(hooks);

test('test standard functionality', async function(assert) {
assert.expect(11);
if (gte('3.10.0')) {
test('test standard functionality', async function(assert) {
assert.expect(11);

await visit('/test-scenario')
await visit('/test-scenario')

await mouseDown('left');
assert.deepEqual(getMouseValues(), [1], 'left mouse');
await mouseDown('left');
assert.deepEqual(getMouseValues(), [1], 'left mouse');

await mouseDown('right');
assert.deepEqual(getMouseValues(), [11], 'right mouse');
await mouseDown('right');
assert.deepEqual(getMouseValues(), [11], 'right mouse');

await mouseDown('middle');
assert.deepEqual(getMouseValues(), [1], 'middle mouse');
await mouseDown('middle');
assert.deepEqual(getMouseValues(), [1], 'middle mouse');

await touchStart();
assert.deepEqual(getTouchValues(), [1], 'touch event');
await touchStart();
assert.deepEqual(getTouchValues(), [1], 'touch event');

await keyDown('ArrowRight');
assert.deepEqual(getValues(), [1, 1, 1], 'equal responders all respond');
await keyDown('ArrowRight');
assert.deepEqual(getValues(), [1, 1, 1], 'equal responders all respond');

await fillIn(`${hook('counter-first')} ${hook('counter-priority-input')}`, '1');
await fillIn(`${hook('counter-first')} ${hook('counter-priority-input')}`, '1');

await blur(`${hook('counter-first')} ${hook('counter-priority-input')}`);
await blur(`${hook('counter-first')} ${hook('counter-priority-input')}`);

await keyDown('ArrowRight');
assert.deepEqual(getValues(), [2, 1, 1], 'highest responder responds first');
await keyDown('ArrowRight');
assert.deepEqual(getValues(), [2, 1, 1], 'highest responder responds first');

await click(`${hook('counter-second')} ${hook('counter-first-responder-toggle')}`);
await click(`${hook('counter-second')} ${hook('counter-first-responder-toggle')}`);

await keyDown('ArrowRight');
assert.deepEqual(getValues(), [2, 2, 1], 'first responder responds first');
await keyDown('ArrowRight');
assert.deepEqual(getValues(), [2, 2, 1], 'first responder responds first');

await click(`${hook('counter-second')} ${hook('counter-lax-priority-toggle')}`);
await click(`${hook('counter-second')} ${hook('counter-lax-priority-toggle')}`);

await keyDown('ArrowRight');
assert.deepEqual(getValues(), [3, 3, 1], 'lax priority does not block lower priority responders');
await keyDown('ArrowRight');
assert.deepEqual(getValues(), [3, 3, 1], 'lax priority does not block lower priority responders');

await click(`${hook('counter-first')} ${hook('counter-activated-toggle')}`);
await click(`${hook('counter-first')} ${hook('counter-activated-toggle')}`);

await keyDown('ArrowRight');
assert.deepEqual(getValues(), [3, 4, 2], 'deactivating a responder removes it from the stack');
await keyDown('ArrowRight');
assert.deepEqual(getValues(), [3, 4, 2], 'deactivating a responder removes it from the stack');

await keyDown('ArrowRight+ctrl+shift');
assert.deepEqual(getValues(), [3, 104, 102], 'modifier keys work');
await keyDown('ArrowRight+ctrl+shift');
assert.deepEqual(getValues(), [3, 104, 102], 'modifier keys work');

await keyUp('KeyR');
assert.deepEqual(getValues(), [3, 0, 0], 'keyUp works');
});
await keyUp('KeyR');
assert.deepEqual(getValues(), [3, 0, 0], 'keyUp works');
});

test('test event propagation', async function(assert) {
assert.expect(6);
test('test event propagation', async function(assert) {
assert.expect(6);

const keyboardService = getService('keyboard');
set(keyboardService, 'isPropagationEnabled', true);
const keyboardService = getService('keyboard');
set(keyboardService, 'isPropagationEnabled', true);

await visit('/test-scenario');
await keyDown('ArrowRight');
assert.deepEqual(getValues(), [1, 1, 1], 'equal responders all respond');
await visit('/test-scenario');
await keyDown('ArrowRight');
assert.deepEqual(getValues(), [1, 1, 1], 'equal responders all respond');

await fillIn(`${hook('counter-first')} ${hook('counter-priority-input')}`, '1');
await blur(`${hook('counter-first')} ${hook('counter-priority-input')}`);
await fillIn(`${hook('counter-first')} ${hook('counter-priority-input')}`, '1');
await blur(`${hook('counter-first')} ${hook('counter-priority-input')}`);

await keyDown('ArrowRight');
assert.deepEqual(getValues(), [2, 2, 2], 'highest responder responds first, lower responders follow');
await keyDown('ArrowRight');
assert.deepEqual(getValues(), [2, 2, 2], 'highest responder responds first, lower responders follow');

await fillIn(`${hook('counter-second')} ${hook('counter-priority-input')}`, '1');
await blur(`${hook('counter-second')} ${hook('counter-priority-input')}`);
await click(`${hook('counter-first')} ${hook('counter-stop-immediate-propagation-toggle')}`);
await fillIn(`${hook('counter-second')} ${hook('counter-priority-input')}`, '1');
await blur(`${hook('counter-second')} ${hook('counter-priority-input')}`);
await click(`${hook('counter-first')} ${hook('counter-stop-immediate-propagation-toggle')}`);

await keyDown('ArrowRight');
assert.deepEqual(getValues(), [3, 2, 3], 'highest responder responds first and stops immediate propagation, lower responders follow');
await keyDown('ArrowRight');
assert.deepEqual(getValues(), [3, 2, 3], 'highest responder responds first and stops immediate propagation, lower responders follow');

await click(`${hook('counter-first')} ${hook('counter-stop-immediate-propagation-toggle')}`);
await click(`${hook('counter-first')} ${hook('counter-stop-propagation-toggle')}`);
await click(`${hook('counter-first')} ${hook('counter-stop-immediate-propagation-toggle')}`);
await click(`${hook('counter-first')} ${hook('counter-stop-propagation-toggle')}`);

await keyDown('ArrowRight');
assert.deepEqual(getValues(), [4, 3, 3], 'highest responders responds first and block propagation to lower priority responders');
await keyDown('ArrowRight');
assert.deepEqual(getValues(), [4, 3, 3], 'highest responders responds first and block propagation to lower priority responders');

await click(`${hook('counter-first')} ${hook('counter-activated-toggle')}`);
await click(`${hook('counter-first')} ${hook('counter-activated-toggle')}`);

await keyDown('ArrowRight');
assert.deepEqual(getValues(), [4, 4, 4], 'deactivating a responder removes it from the stack, deactivated responders do not block propagation');
await keyDown('ArrowRight');
assert.deepEqual(getValues(), [4, 4, 4], 'deactivating a responder removes it from the stack, deactivated responders do not block propagation');

await fillIn(`${hook('counter-first')} ${hook('counter-priority-input')}`, '2');
await blur(`${hook('counter-first')} ${hook('counter-priority-input')}`);
await click(`${hook('counter-first')} ${hook('counter-stop-propagation-toggle')}`);
await click(`${hook('counter-first')} ${hook('counter-activated-toggle')}`);
await click(`${hook('counter-first')} ${hook('counter-first-responder-toggle')}`);
await click(`${hook('counter-second')} ${hook('counter-first-responder-toggle')}`);
await click(`${hook('counter-second')} ${hook('counter-stop-immediate-propagation-toggle')}`);
await fillIn(`${hook('counter-first')} ${hook('counter-priority-input')}`, '2');
await blur(`${hook('counter-first')} ${hook('counter-priority-input')}`);
await click(`${hook('counter-first')} ${hook('counter-stop-propagation-toggle')}`);
await click(`${hook('counter-first')} ${hook('counter-activated-toggle')}`);
await click(`${hook('counter-first')} ${hook('counter-first-responder-toggle')}`);
await click(`${hook('counter-second')} ${hook('counter-first-responder-toggle')}`);
await click(`${hook('counter-second')} ${hook('counter-stop-immediate-propagation-toggle')}`);

await click(`${hook('counter-third')} ${hook('counter-first-responder-toggle')}`);
await click(`${hook('counter-third')} ${hook('counter-first-responder-toggle')}`);

await keyDown('ArrowRight');
assert.deepEqual(getValues(), [5, 5, 4], 'first responders get called in priority order.');
});
await keyDown('ArrowRight');
assert.deepEqual(getValues(), [5, 5, 4], 'first responders get called in priority order.');
});
}
});
84 changes: 43 additions & 41 deletions tests/acceptance/keyboard-test.js
Original file line number Diff line number Diff line change
@@ -1,66 +1,68 @@
import { visit } from '@ember/test-helpers';
import { setupApplicationTest } from 'ember-qunit';
import { module, test } from 'qunit';

import { keyDown, keyUp, keyPress } from 'ember-keyboard/test-support/test-helpers';

import { textChanged } from '../helpers/text-changed';
import { gte } from 'ember-compatibility-helpers';

module('Acceptance | ember keyboard | keyboard', function(hooks) {
setupApplicationTest(hooks);

hooks.beforeEach(async function() {
await visit('/test-scenario/keyboard');
});
if (gte('3.10.0')) {

module('keyDown', function() {
module('Arrow keys', function() {
test('Left is pressed', async function(assert) {
assert.expect(2);
hooks.beforeEach(async function() {
await visit('/test-scenario/keyboard');
});

await textChanged(assert,
() => keyDown('ArrowLeft'), {
selectorName: 'counter-counter',
beforeValue: '0',
afterValue: '-1',
});
module('keyDown', function() {
module('Arrow keys', function() {
test('Left is pressed', async function(assert) {
assert.expect(2);

await textChanged(assert,
() => keyDown('ArrowLeft'), {
selectorName: 'counter-counter',
beforeValue: '0',
afterValue: '-1',
});
});
});
});
});

module('keyUp', function() {
module('Letters are pressed', function() {
module('R is configured to reset the counter', function(hooks) {
hooks.beforeEach(async function() {
await keyDown('ArrowRight');
module('keyUp', function() {
module('Letters are pressed', function() {
module('R is configured to reset the counter', function(hooks) {
hooks.beforeEach(async function() {
await keyDown('ArrowRight');
});

test('the counter is cleared', async function(assert) {
assert.expect(2);

await textChanged(assert,
() => keyUp('KeyR'), {
selectorName: 'counter-counter',
beforeValue: '1',
afterValue: '0'
});
});
});
});
});

test('the counter is cleared', async function(assert) {
module('keyPress', function() {
module('Numbers are pressed', function() {
test('pressing 5 sets the the counter', async function(assert) {
assert.expect(2);

await textChanged(assert,
() => keyUp('KeyR'), {
() => keyPress('Digit5'), {
selectorName: 'counter-counter',
beforeValue: '1',
afterValue: '0'
beforeValue: '0',
afterValue: '5'
});
});
});
});
});

module('keyPress', function() {
module('Numbers are pressed', function() {
test('pressing 5 sets the the counter', async function(assert) {
assert.expect(2);

await textChanged(assert,
() => keyPress('Digit5'), {
selectorName: 'counter-counter',
beforeValue: '0',
afterValue: '5'
});
});
});
});
}
});
Loading

0 comments on commit 6dd644f

Please sign in to comment.