forked from honestbleeps/Reddit-Enhancement-Suite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeyboardNav.js
148 lines (140 loc) · 5.71 KB
/
keyboardNav.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
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
module.exports = {
'basic navigation': browser => {
if (browser.options.desiredCapabilities.browserName === 'firefox') {
// geckodriver doesn't support elementSendKeys https://github.com/mozilla/geckodriver/issues/159
browser.end();
return;
}
const post = '#thing_t3_5pxfg2';
const commentA = '#thing_t1_dcuk08v';
const commentAA = '#thing_t1_dcuk140';
const commentAB = '#thing_t1_dcuk1bk';
const commentB = '#thing_t1_dcuk0d6';
const commentBA = '#thing_t1_dcuk1gl';
const commentBB = '#thing_t1_dcuk1oc';
const activeThing = 'RES-keyNav-activeThing';
browser
.url('https://en.reddit.com/r/RESIntegrationTests/comments/5pxfg2/keyboard_nav/?sort=old')
.waitForElementVisible(`${post}.${activeThing}`)
.keys(['j'])
.assert.not.cssClassPresent(post, activeThing, 'move down normally (post -> comments)')
.assert.cssClassPresent(commentA, activeThing)
.keys(['j'])
.assert.not.cssClassPresent(commentA, activeThing, 'move down normally (comment -> comment)')
.assert.cssClassPresent(commentAA, activeThing)
.keys(['p'])
.assert.not.cssClassPresent(commentAA, activeThing, 'move to parent')
.assert.cssClassPresent(commentA, activeThing)
.keys(['J'])
.assert.not.cssClassPresent(commentA, activeThing, 'move to next sibling')
.assert.cssClassPresent(commentB, activeThing)
.keys(['k'])
.assert.not.cssClassPresent(commentB, activeThing, 'move up normally')
.assert.cssClassPresent(commentAB, activeThing)
.keys(['J'])
.assert.not.cssClassPresent(commentAB, activeThing, 'move to next sibling, no siblings left')
.assert.cssClassPresent(commentB, activeThing)
.keys(['j'])
.assert.not.cssClassPresent(commentB, activeThing, 'move down normally')
.assert.cssClassPresent(commentBA, activeThing)
.keys(['j'])
.assert.not.cssClassPresent(commentBA, activeThing, 'move down normally')
.assert.cssClassPresent(commentBB, activeThing)
.keys([browser.Keys.ALT, 'K'])
.assert.not.cssClassPresent(commentBB, activeThing, 'move to parent\'s previous sibling')
.assert.cssClassPresent(commentA, activeThing)
.end();
},
'rapid subsequent keypresses': browser => {
if (browser.options.desiredCapabilities.browserName === 'firefox') {
// geckodriver doesn't support elementSendKeys https://github.com/mozilla/geckodriver/issues/159
browser.end();
return;
}
const post = '#thing_t3_5pxfg2';
const firstComment = '#thing_t1_dcuk08v';
const activeThing = 'RES-keyNav-activeThing';
browser
.url('https://en.reddit.com/r/RESIntegrationTests/comments/5pxfg2/keyboard_nav/?sort=old')
.waitForElementVisible(`${post}.${activeThing}`)
.keys(['j', 'k'])
.assert.cssClassPresent(post, activeThing)
.assert.not.cssClassPresent(firstComment, activeThing)
.end();
},
'go mode': browser => {
if (browser.options.desiredCapabilities.browserName === 'firefox') {
// geckodriver doesn't support elementSendKeys https://github.com/mozilla/geckodriver/issues/159
browser.end();
return;
}
browser
// go to subreddit frontpage
.url('https://en.reddit.com/r/RESIntegrationTests/comments/5n61yd/go_mode/')
.waitForElementVisible('#RESSettingsButton')
.keys(['g', 'F'])
.assert.urlContains('https://en.reddit.com/r/RESIntegrationTests/')
// go to frontpage
.waitForElementVisible('#RESSettingsButton')
.keys(['g', 'f'])
.assert.urlContains('https://en.reddit.com/')
.end();
},
'blurs target': browser => {
if (browser.options.desiredCapabilities.browserName === 'firefox') {
// geckodriver doesn't support elementSendKeys https://github.com/mozilla/geckodriver/issues/159
browser.end();
return;
}
browser
.url('https://en.reddit.com/r/RESIntegrationTests/comments/5pxfg2/keyboard_nav/?sort=old')
.waitForElementVisible('#thing_t1_dcuk08v > .entry .toggleChildren')
.click('#thing_t1_dcuk08v > .entry .toggleChildren')
// moving down should blur "hide child comments"
.keys(['J'])
.keys([browser.Keys.ENTER])
.assert.cssClassPresent('#thing_t1_dcuk0d6', 'collapsed')
.waitForElementNotVisible('#thing_t1_dcuk08v .child .entry', 'child comment should not be revealed')
.end();
},
'key help': browser => {
if (browser.options.desiredCapabilities.browserName === 'firefox') {
// geckodriver doesn't support elementSendKeys https://github.com/mozilla/geckodriver/issues/159
browser.end();
return;
}
browser
.url('https://en.reddit.com/r/RESIntegrationTests/comments/5pxfg2/keyboard_nav/')
.waitForElementVisible('#RESSettingsButton')
.keys(['?'])
.assert.visible('#keyHelp')
.assert.containsText('#keyHelp', 'shift-/')
.assert.containsText('#keyHelp', 'Show help for keyboard shortcuts.')
.end();
},
'link number annotations': browser => {
if (browser.options.desiredCapabilities.browserName === 'firefox') {
// geckodriver doesn't support elementSendKeys https://github.com/mozilla/geckodriver/issues/159
browser.end();
return;
}
browser
.url('https://en.reddit.com/r/RESIntegrationTests/comments/633x7q/link_number_annotations/')
.waitForElementVisible('.thing.link')
.click('.thing.link .md strong')
.assert.visible('.thing.link .keyNavAnnotation')
.assert.attributeEquals('.thing.link .keyNavAnnotation', 'data-text', '[1]')
.assert.not.elementPresent('.thing.comment .keyNavAnnotation')
.click('.thing.comment .md strong')
.assert.visible('.thing.comment .keyNavAnnotation')
.assert.attributeEquals('.thing.comment .keyNavAnnotation', 'data-text', '[1]')
.assert.not.elementPresent('.thing.link .keyNavAnnotation')
.keys(['1'])
// switch to newly opened background tab
.windowHandles(result => {
browser.switchWindow(result.value[1]);
})
.assert.urlContains('https://www.reddit.com/r/RESIntegrationTests')
.end();
},
};