-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathlink-test.ts
150 lines (133 loc) · 4.77 KB
/
link-test.ts
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/* eslint-disable qunit/no-conditional-assertions, qunit/require-expect */
import { render, click, currentURL } from '@ember/test-helpers';
import { setupRenderingTest } from 'ember-qunit';
import { module, test } from 'qunit';
import { hbs } from 'ember-cli-htmlbars';
import { setupLink } from 'ember-link/test-support';
import waitForError from 'dummy/tests/helpers/wait-for-error';
module('Integration | Component | link', function (hooks) {
setupRenderingTest(hooks);
for (const withSetupLink of [false, true]) {
const prefix = withSetupLink ? 'with' : 'without';
const moduleName = `${prefix} \`setupLink(hooks)\``;
module(moduleName, function (innerHooks) {
if (withSetupLink) {
setupLink(innerHooks);
}
// Regression for: https://github.com/buschtoens/ember-link/issues/126
test('it renders', async function (assert) {
await render(hbs`
<Link @route="foo" as |l|>
<a
data-test-link
href={{l.href}}
class={{if l.isActive "is-active"}}
{{on "click" l.transitionTo}}
>
Link
</a>
</Link>
`);
assert
.dom('[data-test-link]')
.hasAttribute('href', withSetupLink ? /ember\d+/ : '');
assert.dom('[data-test-link]').hasNoClass('is-active');
});
test('triggering a transition has no effect', async function (assert) {
await render(hbs`
<Link @route="foo" as |l|>
<a
data-test-link
href={{l.href}}
class={{if l.isActive "is-active"}}
{{on "click" l.transitionTo}}
>
Link
</a>
</Link>
`);
assert.strictEqual(currentURL(), null);
if (withSetupLink) {
await click('[data-test-link]');
} else {
const error = await waitForError(() => click('[data-test-link]'));
assert.ok(error instanceof Error);
assert.strictEqual(
error.message,
'Assertion Failed: You can only call `transitionTo`, when the router is initialized, e.g. when using `setupApplicationTest`.'
);
}
assert.strictEqual(currentURL(), null);
});
module('with incomplete models', function () {
test('it renders', async function (assert) {
await render(hbs`
<Link @route="parent.second-child" as |l|>
<a
data-test-link
href={{l.href}}
class={{if l.isActive "is-active"}}
{{on "click" l.transitionTo}}
>
Link
</a>
</Link>
`);
assert
.dom('[data-test-link]')
.hasAttribute('href', withSetupLink ? /ember\d+/ : '');
assert.dom('[data-test-link]').hasNoClass('is-active');
});
test('triggering a transition has no effect', async function (assert) {
await render(hbs`
<Link @route="parent.second-child" as |l|>
<a
data-test-link
href={{l.href}}
class={{if l.isActive "is-active"}}
{{on "click" l.transitionTo}}
>
Link
</a>
</Link>
`);
assert.strictEqual(currentURL(), null);
if (withSetupLink) {
await click('[data-test-link]');
} else {
const error = await waitForError(() => click('[data-test-link]'));
assert.ok(error instanceof Error);
assert.strictEqual(
error.message,
'Assertion Failed: You can only call `transitionTo`, when the router is initialized, e.g. when using `setupApplicationTest`.'
);
}
assert.strictEqual(currentURL(), null);
});
test('it does not break any following LinkTo components', async function (assert) {
await render(hbs`
<Link @route="parent.second-child" as |l|>
<a
data-test-link
href={{l.href}}
class={{if l.isActive "is-active"}}
{{on "click" l.transitionTo}}
>
Link
</a>
</Link>
<LinkTo @route="parent.second-child" data-test-link-to>
Link
</LinkTo>
`);
assert
.dom('[data-test-link]')
.hasAttribute('href', withSetupLink ? /ember\d+/ : '');
assert.dom('[data-test-link]').hasNoClass('is-active');
assert.dom('[data-test-link-to]').hasNoAttribute('href');
assert.dom('[data-test-link-to]').hasNoClass('is-active');
});
});
});
}
});