-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from simonihmig/callbacks
Add onCreate and onUpdate actions
- Loading branch information
Showing
2 changed files
with
97 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { moduleForComponent, test } from 'ember-qunit'; | ||
import hbs from 'htmlbars-inline-precompile'; | ||
import { triggerEvent } from 'ember-native-dom-helpers'; | ||
import wait from 'ember-test-helpers/wait'; | ||
import hasEmberVersion from 'ember-test-helpers/has-ember-version'; | ||
|
||
if (hasEmberVersion(1, 13)) { | ||
moduleForComponent('ember-popper', 'Integration | Component | actions', { | ||
integration: true | ||
}); | ||
|
||
test('it calls onCreate', function(assert) { | ||
assert.expect(2); | ||
let called = 0; | ||
const action = (data) => { | ||
called++; | ||
assert.ok(data && data.instance, 'onCreate action is called with dataObject'); | ||
}; | ||
this.on('create', action); | ||
this.render(hbs` | ||
{{#ember-popper onCreate=(action "create")}} | ||
template block text | ||
{{/ember-popper}} | ||
`); | ||
|
||
return wait() | ||
.then(() => assert.equal(called, 1, 'onCreate action has been called')); | ||
}); | ||
|
||
test('it calls onUpdate', function(assert) { | ||
assert.expect(2); | ||
let called = 0; | ||
const action = (data) => { | ||
called++; | ||
assert.ok(data && data.instance, 'onUpdate action is called with dataObject'); | ||
}; | ||
this.on('update', action); | ||
this.render(hbs` | ||
{{#ember-popper onUpdate=(action "update")}} | ||
template block text | ||
{{/ember-popper}} | ||
`); | ||
|
||
return wait() | ||
.then(() => triggerEvent(document.querySelector('body'), 'scroll')) | ||
.then(wait) | ||
.then(() => { | ||
assert.equal(called, 1, 'onUpdate action has been called after event'); | ||
return wait(); | ||
}); | ||
}); | ||
} |