/
browser-navigation-buttons-test.js
111 lines (88 loc) · 3.39 KB
/
browser-navigation-buttons-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
import {
click,
currentURL,
currentRouteName,
visit,
} from '@ember/test-helpers';
import { module, test } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';
import {
setupBrowserNavigationButtons,
backButton,
forwardButton,
} from 'ember-cli-browser-navigation-button-test-helper/test-support';
module('Acceptance | test helpers', function (hooks) {
setupApplicationTest(hooks);
test('usage', async function (assert) {
setupBrowserNavigationButtons();
await visit('/');
await click('a.foo');
assert.equal(currentURL(), '/foo');
assert.equal(currentRouteName(), 'foo');
await click('a');
assert.equal(currentURL(), '/bar');
assert.equal(currentRouteName(), 'bar');
await backButton();
assert.equal(currentURL(), '/foo', 'url after back button');
assert.equal(currentRouteName(), 'foo', 'path after back button');
await backButton();
assert.equal(currentURL(), '/', 'url after another back button');
assert.equal(currentRouteName(), 'index', 'path after another back button');
await forwardButton();
assert.equal(currentURL(), '/foo', 'url after forward button');
assert.equal(currentRouteName(), 'foo', 'path after forward button');
await forwardButton();
assert.equal(currentURL(), '/bar', 'url after another forward button');
assert.equal(
currentRouteName(),
'bar',
'path after another forward button'
);
});
test('handles route substates', async function (assert) {
setupBrowserNavigationButtons();
await visit('/');
await click('a.uses-loading-substate');
assert.equal(currentRouteName(), 'uses-loading-substate');
await backButton();
assert.equal(currentRouteName(), 'index');
});
test('handles dynamic segments', async function (assert) {
setupBrowserNavigationButtons();
await visit('/');
await click('a.uses-dynamic-segment');
assert.equal(currentURL(), '/dynamic/item-id');
assert.equal(currentRouteName(), 'dynamic');
await click('a.uses-id-only');
assert.equal(currentURL(), '/dynamic/another-item-id');
assert.equal(currentRouteName(), 'dynamic');
await backButton();
assert.equal(currentURL(), '/dynamic/item-id');
assert.equal(currentRouteName(), 'dynamic');
await forwardButton();
assert.equal(currentURL(), '/dynamic/another-item-id');
assert.equal(currentRouteName(), 'dynamic');
});
test('handle query string parameters', async function (assert) {
setupBrowserNavigationButtons();
await visit('/');
await click('a.uses-query-params');
assert.equal(currentURL(), '/dynamic/yet-another-item-id?a=1&b=2&c=3');
assert.equal(currentRouteName(), 'dynamic');
await click('a.uses-id-and-query-params');
assert.equal(currentURL(), '/dynamic/a-different-item-id?a=9&b=8&c=7');
assert.equal(currentRouteName(), 'dynamic');
await click('a.uses-id-only');
assert.equal(currentURL(), '/dynamic/another-item-id');
assert.equal(currentRouteName(), 'dynamic');
await backButton();
assert.equal(currentURL(), '/dynamic/a-different-item-id?a=9&b=8&c=7');
assert.equal(currentRouteName(), 'dynamic');
await backButton();
assert.equal(currentURL(), '/dynamic/yet-another-item-id?a=1&b=2&c=3');
assert.equal(currentRouteName(), 'dynamic');
await backButton();
assert.equal(currentURL(), '/');
assert.equal(currentRouteName(), 'index');
});
});