Skip to content

Commit d69933d

Browse files
authored
Merge pull request #1598 from code-corps/rewrite-integration-tests-for-task-comment-list-component-to-use-page-objects
rewrite-integration-tests-for-task-comment-list-component-to-use-page-objects
2 parents cff9398 + fc52eb4 commit d69933d

4 files changed

Lines changed: 34 additions & 14 deletions

File tree

tests/acceptance/task-comments-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ test('Task comments are displayed correctly', function(assert) {
2222
});
2323

2424
andThen(() => {
25-
assert.equal(taskPage.comments().count, 4, 'The correct number of task comments is rendered');
25+
assert.equal(taskPage.taskCommentList.comments().count, 4, 'The correct number of task comments is rendered');
2626
});
2727
});
2828

@@ -50,7 +50,7 @@ test('A comment can be added to a task', function(assert) {
5050

5151
andThen(() => {
5252
assert.equal(server.schema.comments.all().models.length, 1, 'A new comment was created');
53-
assert.equal(taskPage.comments().count, 1, 'The comment is being rendered');
53+
assert.equal(taskPage.taskCommentList.comments().count, 1, 'The comment is being rendered');
5454
let [comment] = server.schema.comments.all().models;
5555

5656
assert.equal(comment.markdown, 'Test markdown', 'New comment has the correct markdown');

tests/integration/components/task-comment-list-test.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,36 @@ import RSVP from 'rsvp';
22
import { moduleForComponent, test } from 'ember-qunit';
33
import hbs from 'htmlbars-inline-precompile';
44
import stubService from 'code-corps-ember/tests/helpers/stub-service';
5+
import pageObject from 'ember-cli-page-object';
6+
import taskCommentList from 'code-corps-ember/tests/pages/components/task-comment-list';
7+
8+
let page = pageObject.create(taskCommentList);
9+
10+
function renderPage() {
11+
page.render(hbs`
12+
{{task-comment-list comments=comments}}`
13+
);
14+
}
515

616
moduleForComponent('task-comment-list', 'Integration | Component | task comment list', {
717
integration: true,
818
beforeEach() {
19+
page.setContext(this);
920
stubService(this, 'store', {
1021
query() {
1122
return RSVP.resolve([]);
1223
}
1324
});
25+
},
26+
afterEach() {
27+
page.removeContext();
1428
}
1529
});
1630

1731
test('it renders', function(assert) {
1832
assert.expect(1);
19-
this.render(hbs`{{task-comment-list}}`);
20-
assert.equal(this.$('.task-comment-list').length, 1, 'The component\'s element renders');
33+
renderPage();
34+
assert.ok(page.isVisible, 'The component\'s element renders');
2135
});
2236

2337
test('It renders a list of comments if there are comments', function(assert) {
@@ -30,14 +44,13 @@ test('It renders a list of comments if there are comments', function(assert) {
3044
];
3145

3246
this.set('comments', comments);
33-
this.render(hbs`{{task-comment-list comments=comments}}`);
34-
35-
assert.equal(this.$('.comment-item').length, 3, 'The correct number of comments is rendered');
47+
renderPage();
48+
assert.equal(page.comments().count, 3, 'The correct number of comments is rendered');
3649
});
3750

3851
test('it renders nothing when there are no comments', function(assert) {
3952
assert.expect(1);
4053
this.set('comments', []);
41-
this.render(hbs`{{task-comment-list comments=comments}}`);
42-
assert.equal(this.$('.comment-item').length, 0, 'No comments are rendered');
54+
renderPage();
55+
assert.equal(page.comments().count, 0, 'No comments are rendered');
4356
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import {
2+
collection
3+
} from 'ember-cli-page-object';
4+
5+
export default {
6+
comments: collection({
7+
scope: '.task-comment-list',
8+
itemScope: '.comment-item'
9+
})
10+
};

tests/pages/project/tasks/task.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,17 @@ import {
1010
import commentItem from '../../components/comment-item';
1111
import createCommentForm from '../../components/create-comment-form';
1212
import skillsTypeahead from 'code-corps-ember/tests/pages/components/skills-typeahead';
13+
import taskCommentList from 'code-corps-ember/tests/pages/components/task-comment-list';
1314

1415
export default create({
1516
commentItem,
1617
createCommentForm,
18+
taskCommentList,
1719

1820
visit: visitable(':organization/:project/tasks/:number'),
1921

2022
clickSave: clickable('.save'),
2123

22-
comments: collection({
23-
scope: '.task-comment-list',
24-
itemScope: '.comment-item'
25-
}),
26-
2724
editor: {
2825
scope: '.editor-with-preview',
2926

0 commit comments

Comments
 (0)