-
-
Notifications
You must be signed in to change notification settings - Fork 138
/
Copy pathusers-view-test.js
58 lines (44 loc) · 1.85 KB
/
users-view-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { module, test } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';
import {
buildList,
makeList,
mockFindAll,
setupFactoryGuy,
} from 'ember-data-factory-guy';
import { visit } from '@ember/test-helpers';
module('Acceptance | Users View', function (hooks) {
setupApplicationTest(hooks);
setupFactoryGuy(hooks);
test('Show users by using mockFindAll to create default users', async function (assert) {
mockFindAll('user', 3);
await visit('/users');
assert.dom('li.user').exists({ count: 3 });
});
test('Show users with projects by build(ing) json and using returns with json', async function (assert) {
// build a json payload with list of users
let users = buildList('user', 1);
mockFindAll('user').returns({ json: users });
await visit('/users');
assert.dom('li.user').exists({ count: 1 });
});
test('Show users by make(ing) list of models and using returns with those models', async function (assert) {
// make a user with projects ( which will be in the store )
let [bo, bif] = makeList('user', { name: 'Bo' }, { name: 'Bif' });
mockFindAll('user').returns({ models: [bo, bif] });
await visit('/users');
assert.dom('li.user:nth-child(1)').containsText(bo.get('name'));
assert.dom('li.user:nth-child(2)').containsText(bif.get('name'));
});
test('reuse mockFindAll to show return different users', async function (assert) {
let mock = mockFindAll('user'); // returns no users
await visit('/users');
assert.dom('li.user').doesNotExist();
let [bo, bif] = makeList('user', { name: 'Bo' }, { name: 'Bif' });
mock.returns({ models: [bo, bif] });
await visit('/users');
assert.dom('.user').exists({ count: 2 });
assert.dom('.user:nth-child(1)').containsText(bo.get('name'));
assert.dom('.user:nth-child(2)').containsText(bif.get('name'));
});
});