From 5b6adf2c0840c80f7b337aff9b6ca5fb41f79070 Mon Sep 17 00:00:00 2001 From: Sean Doyle Date: Tue, 14 Apr 2015 09:47:31 -0400 Subject: [PATCH] Introduce `registerSelectHelper` https://github.com/thefrontside/emberx-select/issues/13 Adds the `select` helper to deal with integration level tests. Closes #13. --- README.md | 22 ++++++++++++++++++++++ addon/helpers/register-select-helper.js | 16 ++++++++++++++++ app/helpers/register-select-helper.js | 2 ++ 3 files changed, 40 insertions(+) create mode 100644 addon/helpers/register-select-helper.js create mode 100644 app/helpers/register-select-helper.js diff --git a/README.md b/README.md index d888b32..84916f1 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,28 @@ The selections array will be initialized to an empty array if not present. > `hasMany` relationships. Just remember, you can't go wrong if you > use just a simple array. +### Test Helpers + +Since `emberx-select` uses internal identifiers as the `value` attribute, it +doesn't integrate with the `fillIn` test helper. + +Instead, select options based on their `text` values. To do so, +import and invoke the `registerSelectHelper` in your `tests/test-helper.js`: + +```js +// tests/test-helper.js +import registerSelectHelper from 'emberx-select/helpers/register-select-helper'; + +registerSelectHelper(); +``` + +Then in your test: + +```js +andThen(function() { + select('.my-drop-down', 'My Option'); +}); +``` ## EmberX diff --git a/addon/helpers/register-select-helper.js b/addon/helpers/register-select-helper.js new file mode 100644 index 0000000..9b22aed --- /dev/null +++ b/addon/helpers/register-select-helper.js @@ -0,0 +1,16 @@ +import Ember from 'ember'; + +export default function() { + Ember.Test.registerAsyncHelper('select', function(app, selector, text) { + const $el = app.testHelpers.findWithAssert(`${selector} option:contains("${text}")`); + + $el.each(function() { + Ember.run(() => { + this.selected = true; + Ember.$(this).trigger('change'); + }); + }); + + return app.testHelpers.wait(); + }); +} diff --git a/app/helpers/register-select-helper.js b/app/helpers/register-select-helper.js new file mode 100644 index 0000000..bcd2bdf --- /dev/null +++ b/app/helpers/register-select-helper.js @@ -0,0 +1,2 @@ +import registerAsyncHelper from 'emberx-select/helpers/register-select-helper'; +export default registerAsyncHelper;