diff --git a/MIGRATION_GUIDE_V2.md b/MIGRATION_GUIDE_V2.md index 8b4bd28a..bba810e1 100644 --- a/MIGRATION_GUIDE_V2.md +++ b/MIGRATION_GUIDE_V2.md @@ -101,6 +101,4 @@ ### Testing 1. The `drag` and `reorder` test helpers are no longer global `async` helpers. They are now importable. -```javascript -import { drag, reorder } from 'ember-sortable/test-helpers' -``` \ No newline at end of file +Refer to [Testing Section](/README.md#Testing) for more details. \ No newline at end of file diff --git a/README.md b/README.md index a19e7964..d0c50af3 100644 --- a/README.md +++ b/README.md @@ -305,14 +305,41 @@ and returns a `string` constructed from the `config`. * [`drag`][drag]: Drags elements by an offset specified in pixels. * [`reorder`][reorder]: Reorders elements to the specified state. +* [`keyboard`][keyboard]: Keycode constants for quick. -[drag]: addon/helpers/drag.js -[reorder]: addon/helpers/reorder.js +[drag]: addon-test-support/helpers/drag.js +[reorder]: addon-test-support/helpers/reorder.js +[keyboard]: addon-test-support/utils/kebyoard.js To include them in your application, you can import them: ```js -import { drag, reorder } from 'ember-sortable/test-helpers'; +import { drag, reorder } from 'ember-sortable/test-support/helpers'; +import { ENTER_KEY_CODE, SPACE_KEY_CODE, ESCAPE_KEY_CODE, ARROW_KEY_CODES } from "ember-sortable/test-support/utils/keyboard"; +``` + +### Examples +`Reorder` +```js +await reorder( + 'mouse', + '[data-test-vertical-demo-handle]', + ...order +); +``` + +`Drag` +```js +await drag('mouse', '[data-test-scrollable-demo-handle] .handle', () => { return {dy: itemHeight() * 2 + 1, dx: undefined}}); +``` + +`Keyboard` +```js +await triggerKeyEvent( + '[data-test-vertical-demo-handle]', + 'keydown', + ENTER_KEY_CODE +); ``` ## Developing diff --git a/test-support/ember-sortable/helpers/drag.js b/addon-test-support/helpers/drag.js similarity index 100% rename from test-support/ember-sortable/helpers/drag.js rename to addon-test-support/helpers/drag.js diff --git a/addon-test-support/helpers/index.js b/addon-test-support/helpers/index.js new file mode 100644 index 00000000..b549d6e3 --- /dev/null +++ b/addon-test-support/helpers/index.js @@ -0,0 +1,7 @@ +import { drag } from './drag'; +import { reorder } from './reorder'; + +export { + drag, + reorder, +} \ No newline at end of file diff --git a/test-support/ember-sortable/helpers/reorder.js b/addon-test-support/helpers/reorder.js similarity index 96% rename from test-support/ember-sortable/helpers/reorder.js rename to addon-test-support/helpers/reorder.js index 83acc4c5..743f07bc 100644 --- a/test-support/ember-sortable/helpers/reorder.js +++ b/addon-test-support/helpers/reorder.js @@ -1,5 +1,5 @@ import { find, findAll } from '@ember/test-helpers'; -import { drag } from '../helpers/drag'; +import { drag } from './drag'; import { getOffset } from '../utils/offset'; /** In tests, the dummy app is rendered at half size. diff --git a/test-support/ember-sortable/utils/keyboard.js b/addon-test-support/utils/keyboard.js similarity index 100% rename from test-support/ember-sortable/utils/keyboard.js rename to addon-test-support/utils/keyboard.js diff --git a/test-support/ember-sortable/utils/offset.js b/addon-test-support/utils/offset.js similarity index 100% rename from test-support/ember-sortable/utils/offset.js rename to addon-test-support/utils/offset.js diff --git a/tests/acceptance/smoke-test.js b/tests/acceptance/smoke-test.js index 98b61201..d3540787 100644 --- a/tests/acceptance/smoke-test.js +++ b/tests/acceptance/smoke-test.js @@ -1,9 +1,8 @@ import { module, test } from 'qunit'; import { visit, find, findAll, triggerKeyEvent, focus, blur } from '@ember/test-helpers'; import { setupApplicationTest } from 'ember-qunit'; -import { drag } from '../ember-sortable/helpers/drag'; -import { reorder } from '../ember-sortable/helpers/reorder'; -import { ENTER_KEY_CODE, SPACE_KEY_CODE, ESCAPE_KEY_CODE, ARROW_KEY_CODES } from "../ember-sortable/utils/keyboard"; +import { drag, reorder } from 'ember-sortable/test-support/helpers'; +import { ENTER_KEY_CODE, SPACE_KEY_CODE, ESCAPE_KEY_CODE, ARROW_KEY_CODES } from "ember-sortable/test-support/utils/keyboard"; import a11yAudit from 'ember-a11y-testing/test-support/audit'; module('Acceptance | smoke', function(hooks) {