forked from emberjs/ember-qunit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasic-test.js
117 lines (94 loc) · 3.3 KB
/
basic-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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import { module, test } from 'qunit';
import EmberRouter from '@ember/routing/router';
import Route from '@ember/routing/route';
import { hbs } from 'ember-cli-htmlbars';
import { setupApplicationTest } from 'ember-qunit';
import {
visit,
currentRouteName,
currentURL,
click,
} from '@ember/test-helpers';
import { setResolverRegistry } from '../helpers/resolver';
module('setupApplicationTest tests', function (hooks) {
const Router = EmberRouter.extend({ location: 'none' });
Router.map(function () {
this.route('widgets');
this.route('posts', function () {
this.route('post', { path: ':post_id' });
});
});
hooks.beforeEach(function () {
setResolverRegistry({
'router:main': Router,
'template:application': hbs`
<div class="nav"><LinkTo @route="posts">posts</LinkTo> | <LinkTo @route="widgets">widgets</LinkTo></div>
{{outlet}}
`,
'template:index': hbs`<h1>Hello World!</h1>`,
'template:posts': hbs`<h1>Posts Page</h1>{{outlet}}`,
'template:posts/post': hbs`<div class="post-id">{{this.model.post_id}}</div>`,
'route:posts/post': Route.extend({
model(params) {
return params;
},
}),
});
});
setupApplicationTest(hooks);
test('can render', async function (assert) {
await visit('/');
assert.equal(currentRouteName(), 'index');
assert.equal(currentURL(), '/');
assert.equal(
this.element.querySelector('.nav').textContent,
'posts | widgets'
);
assert.equal(this.element.querySelector('h1').textContent, 'Hello World!');
});
test('can perform a basic template rendering for nested route', async function (assert) {
await visit('/posts/1');
assert.equal(currentRouteName(), 'posts.post');
assert.equal(currentURL(), '/posts/1');
assert.equal(
this.element.querySelector('.nav').textContent,
'posts | widgets'
);
assert.equal(this.element.querySelector('.post-id').textContent, '1');
});
test('can visit multiple times', async function (assert) {
await visit('/posts/1');
assert.equal(currentRouteName(), 'posts.post');
assert.equal(currentURL(), '/posts/1');
assert.equal(
this.element.querySelector('.nav').textContent,
'posts | widgets'
);
assert.equal(this.element.querySelector('.post-id').textContent, '1');
await visit('/');
assert.equal(currentRouteName(), 'index');
assert.equal(currentURL(), '/');
assert.equal(
this.element.querySelector('.nav').textContent,
'posts | widgets'
);
assert.equal(this.element.querySelector('h1').textContent, 'Hello World!');
await visit('/posts/2');
assert.equal(currentRouteName(), 'posts.post');
assert.equal(currentURL(), '/posts/2');
assert.equal(
this.element.querySelector('.nav').textContent,
'posts | widgets'
);
assert.equal(this.element.querySelector('.post-id').textContent, '2');
});
test('can navigate amongst routes', async function (assert) {
await visit('/');
assert.equal(currentRouteName(), 'index');
assert.equal(currentURL(), '/');
await click('a[href="/posts"]');
assert.equal(currentRouteName(), 'posts.index');
assert.equal(currentURL(), '/posts');
assert.equal(this.element.querySelector('h1').textContent, 'Posts Page');
});
});