1
1
import { module , test } from 'qunit' ;
2
2
import { setupRenderingTest } from 'frontend/tests/helpers' ;
3
- import { render } from '@ember/test-helpers' ;
3
+ import { render , waitFor } from '@ember/test-helpers' ;
4
4
import { hbs } from 'ember-cli-htmlbars' ;
5
5
import component from 'frontend/tests/pages/components/user-menu' ;
6
6
import a11yAudit from 'ember-a11y-testing/test-support/audit' ;
@@ -11,6 +11,9 @@ module('Integration | Component | user-menu', function (hooks) {
11
11
setupRenderingTest ( hooks ) ;
12
12
setupMirage ( hooks ) ;
13
13
14
+ // My Profile and Logout
15
+ const linkCount = 2 ;
16
+
14
17
hooks . beforeEach ( async function ( ) {
15
18
await setupAuthentication ( ) ;
16
19
} ) ;
@@ -32,22 +35,22 @@ module('Integration | Component | user-menu', function (hooks) {
32
35
33
36
assert . strictEqual ( component . links . length , 0 ) ;
34
37
await component . toggle . click ( ) ;
35
- assert . strictEqual ( component . links . length , 2 ) ;
38
+ assert . strictEqual ( component . links . length , linkCount ) ;
36
39
} ) ;
37
40
38
41
test ( 'down opens menu' , async function ( assert ) {
39
42
await render ( hbs `<UserMenu />` ) ;
40
43
41
44
assert . strictEqual ( component . links . length , 0 ) ;
42
45
await component . toggle . down ( ) ;
43
- assert . strictEqual ( component . links . length , 2 ) ;
46
+ assert . strictEqual ( component . links . length , linkCount ) ;
44
47
} ) ;
45
48
46
49
test ( 'escape closes menu' , async function ( assert ) {
47
50
await render ( hbs `<UserMenu />` ) ;
48
51
49
52
await component . toggle . down ( ) ;
50
- assert . strictEqual ( component . links . length , 2 ) ;
53
+ assert . strictEqual ( component . links . length , linkCount ) ;
51
54
await component . toggle . esc ( ) ;
52
55
assert . strictEqual ( component . links . length , 0 ) ;
53
56
} ) ;
@@ -56,8 +59,62 @@ module('Integration | Component | user-menu', function (hooks) {
56
59
await render ( hbs `<UserMenu />` ) ;
57
60
58
61
await component . toggle . down ( ) ;
59
- assert . strictEqual ( component . links . length , 2 ) ;
62
+ assert . strictEqual ( component . links . length , linkCount ) ;
63
+ await component . toggle . click ( ) ;
64
+ assert . strictEqual ( component . links . length , 0 ) ;
65
+ } ) ;
66
+
67
+ test ( 'keyboard navigation' , async function ( assert ) {
68
+ await render ( hbs `<UserMenu />` ) ;
69
+ await component . toggle . click ( ) ;
70
+ assert . strictEqual ( component . links . length , linkCount , `has ${ linkCount } links` ) ;
71
+
72
+ // slight delay to allow for proper loading of popup menu
73
+ await waitFor ( '.user-menu .menu' ) ;
74
+
75
+ assert . ok ( component . links [ 0 ] . link . hasFocus , 'first link has focus' ) ;
76
+ assert . notOk ( component . links [ 1 ] . link . hasFocus , 'second link does NOT have focus' ) ;
77
+
78
+ // regular down/up navigation
79
+ await component . links [ 0 ] . down ( ) ;
80
+ assert . notOk (
81
+ component . links [ 0 ] . link . hasFocus ,
82
+ 'after moving down from first link, it DOES not have focus' ,
83
+ ) ;
84
+ assert . ok ( component . links [ 1 ] . link . hasFocus , 'second link has focus' ) ;
85
+ await component . links [ 1 ] . up ( ) ;
86
+ assert . notOk (
87
+ component . links [ 1 ] . link . hasFocus ,
88
+ 'after moving up from second link, it does not have focus' ,
89
+ ) ;
90
+ assert . ok ( component . links [ 0 ] . link . hasFocus , 'first link has focus' ) ;
91
+
92
+ // wrap-around navigation from first to last menu item
93
+ await component . links [ 0 ] . up ( ) ;
94
+ assert . notOk ( component . links [ 0 ] . link . hasFocus ) ;
95
+ assert . ok ( component . links [ 1 ] . link . hasFocus ) ;
96
+ // wrap-around navigation from last to first menu item
97
+ await component . links [ 1 ] . down ( ) ;
98
+ assert . ok ( component . links [ 0 ] . link . hasFocus ) ;
99
+ assert . notOk ( component . links [ 1 ] . link . hasFocus ) ;
100
+
101
+ // close menu on escape, left, right, and tab keys.
102
+ await component . links [ 0 ] . esc ( ) ;
103
+ assert . strictEqual ( component . links . length , 0 ) ;
104
+ await component . toggle . click ( ) ;
105
+ assert . strictEqual ( component . links . length , linkCount ) ;
106
+ assert . ok ( component . links [ 0 ] . link . hasFocus ) ;
107
+ await component . links [ 0 ] . left ( ) ;
108
+ assert . strictEqual ( component . links . length , 0 ) ;
109
+ await component . toggle . click ( ) ;
110
+ assert . strictEqual ( component . links . length , linkCount ) ;
111
+ assert . ok ( component . links [ 0 ] . link . hasFocus ) ;
112
+ await component . links [ 0 ] . right ( ) ;
113
+ assert . strictEqual ( component . links . length , 0 ) ;
60
114
await component . toggle . click ( ) ;
115
+ assert . strictEqual ( component . links . length , linkCount ) ;
116
+ assert . ok ( component . links [ 0 ] . link . hasFocus ) ;
117
+ await component . links [ 0 ] . tab ( ) ;
61
118
assert . strictEqual ( component . links . length , 0 ) ;
62
119
} ) ;
63
120
} ) ;
0 commit comments