Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce registerSelectHelper #14

Merged
merged 1 commit into from
May 14, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 16 additions & 0 deletions addon/helpers/register-select-helper.js
Original file line number Diff line number Diff line change
@@ -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');
});
});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seanpdoyle I decided to checkout this branch and see why Travis is hanging. It seems you can't use the fat arrow OR the string interpolation here.

Refactored (and not as nice ES6 😦 ) code:

var $el = app.testHelpers.findWithAssert(selector + "option:contains('" + text + "')");

$el.each(function() {
  var _this = this;

  Ember.run(function() {
    _this.selected = true;
    Ember.$(_this).trigger('change');
  });
});


return app.testHelpers.wait();
});
}
2 changes: 2 additions & 0 deletions app/helpers/register-select-helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import registerAsyncHelper from 'emberx-select/helpers/register-select-helper';
export default registerAsyncHelper;