Skip to content

Commit 4b730ab

Browse files
Dave Connisbegedin
Dave Connis
authored andcommitted
Rewrite integration tests for user-dropdown component to use page objects (#1585)
* created user-dropdown page object * added user-dropdown component page object and changed integration test to include it * fixed indentation
1 parent 593c7e8 commit 4b730ab

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

tests/integration/components/user-dropdown-test.js

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
11
import { computed } from '@ember/object';
2-
import { run } from '@ember/runloop';
32
import { moduleForComponent, test } from 'ember-qunit';
3+
import PageObject from 'ember-cli-page-object';
44
import hbs from 'htmlbars-inline-precompile';
5+
import userDropdownComponent from 'code-corps-ember/tests/pages/component/user-dropdown';
6+
7+
let page = PageObject.create(userDropdownComponent);
8+
9+
function renderPage() {
10+
page.render(hbs`{{user-dropdown user=user action='hide'}}`);
11+
}
512

613
moduleForComponent('user-dropdown', 'Integration | Component | user dropdown', {
7-
integration: true
14+
integration: true,
15+
beforeEach() {
16+
page.setContext(this);
17+
},
18+
afterEach() {
19+
page.removeContext();
20+
}
821
});
922

1023
const stubUser = {
@@ -23,10 +36,11 @@ const stubUser = {
2336

2437
test('it renders', function(assert) {
2538
assert.expect(1);
39+
2640
this.set('user', stubUser);
27-
this.render(hbs`{{user-dropdown user=user}}`);
41+
renderPage();
2842

29-
assert.equal(this.$('.dropdown-menu').length, 1, 'The component renders');
43+
assert.ok(page.isVisible, 'The component renders');
3044
});
3145

3246
test('it triggers the hide action when clicked', function(assert) {
@@ -36,6 +50,8 @@ test('it triggers the hide action when clicked', function(assert) {
3650
this.on('hide', function() {
3751
assert.ok(true, 'It triggers the hide action when clicked');
3852
});
39-
this.render(hbs`{{user-dropdown user=user action='hide'}}`);
40-
run(() => this.$('.dropdown-menu').click());
53+
54+
renderPage();
55+
page.click();
56+
4157
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import {
2+
clickable,
3+
hasClass
4+
} from 'ember-cli-page-object';
5+
6+
export default {
7+
scope: '.dropdown-menu',
8+
9+
clickDropdownMenu: clickable('.dropdown-menu'),
10+
dropdownIsHidden: hasClass('menu-hidden')
11+
};

0 commit comments

Comments
 (0)