blob: a2dfa83b0694e5eb934a30fdc468bbe38ec1b8d0 [file] [log] [blame]
Philipp Schrader175a93c2023-02-19 13:13:40 -08001/// <reference types="cypress" />
2
3function disableAlerts() {
4 cy.get('#block_alerts').check({force: true}).should('be.checked');
5}
6
7function switchToTab(tabName) {
8 cy.contains('.nav-link', tabName).click();
9}
10
11function headerShouldBe(text) {
12 cy.get('.header').should('have.text', text);
13}
14
15function clickButton(buttonName) {
16 cy.contains('button', buttonName).click();
17}
18
19function setInputTo(fieldSelector, value) {
20 cy.get(fieldSelector).type('{selectAll}' + value);
21}
22
23// Moves the nth slider left or right. A positive "adjustBy" value moves the
24// slider to the right. A negative value moves the slider to the left.
25//
26// negative/left <--- 0 ---> positive/right
27function adjustNthSliderBy(n, adjustBy) {
28 let element = cy.get('input[type=range]').eq(n);
29 element.scrollIntoView();
30 element.invoke('val').then((currentValue) => {
31 // We need to query for the slider here again because `invoke('val')` above
32 // somehow invalidates further calls to `val`.
33 cy.get('input[type=range]')
34 .eq(n)
35 .invoke('val', currentValue + adjustBy)
36 .trigger('change');
37 });
38}
39
40// Asserts that the field on the "Submit and Review" screen has a specific
41// value.
42function expectReviewFieldToBe(fieldName, expectedValue) {
43 expectNthReviewFieldToBe(fieldName, 0, expectedValue);
44}
45
46// Asserts that the n'th instance of a field on the "Submit and Review"
47// screen has a specific value.
48function expectNthReviewFieldToBe(fieldName, n, expectedValue) {
49 getNthReviewField(fieldName, n).should(
50 'have.text',
51 `${fieldName}: ${expectedValue}`
52 );
53}
54
55function getNthReviewField(fieldName, n) {
56 let element = cy.get('li').filter(`:contains("${fieldName}: ")`).eq(n);
57 element.scrollIntoView();
58 return element;
59}
60
61before(() => {
62 cy.visit('/');
63 disableAlerts();
64 cy.title().should('eq', 'FRC971 Scouting Application');
65
66 // Import the match list before running any tests. Ideally this should be
67 // run in beforeEach(), but it's not worth doing that at this time. Our
68 // tests are basic enough not to require this.
69 switchToTab('Import Match List');
70 headerShouldBe('Import Match List');
71 setInputTo('#year', '2016');
72 setInputTo('#event_code', 'nytr');
73 clickButton('Import');
74
75 cy.get('.progress_message').contains('Successfully imported match list.');
76});
77
78beforeEach(() => {
79 cy.visit('/');
80 disableAlerts();
81});
82
83describe('Scouting app tests', () => {
84 it('should: show matches in chronological order.', () => {
85 headerShouldBe('Matches');
86 cy.get('.badge').eq(0).contains('Quals Match 1');
87 cy.get('.badge').eq(1).contains('Quals Match 2');
88 cy.get('.badge').eq(2).contains('Quals Match 3');
89 cy.get('.badge').eq(9).contains('Quals Match 10');
90 cy.get('.badge').eq(72).contains('Quarter Final 1 Match 1');
91 cy.get('.badge').eq(73).contains('Quarter Final 2 Match 1');
92 cy.get('.badge').eq(74).contains('Quarter Final 3 Match 1');
93 cy.get('.badge').eq(75).contains('Quarter Final 4 Match 1');
94 cy.get('.badge').eq(76).contains('Quarter Final 1 Match 2');
95 cy.get('.badge').eq(82).contains('Semi Final 1 Match 1');
96 cy.get('.badge').eq(83).contains('Semi Final 2 Match 1');
97 cy.get('.badge').eq(84).contains('Semi Final 1 Match 2');
98 cy.get('.badge').eq(85).contains('Semi Final 2 Match 2');
99 cy.get('.badge').eq(89).contains('Final 1 Match 3');
100 });
101
102 it('should: prefill the match information.', () => {
103 headerShouldBe('Matches');
104
105 // On the 87th row of matches (index 86) click on the second team
106 // (index 1) which resolves to team 5254 in semi final 2 match 3.
107 cy.get('button.match-item')
108 .eq(86 * 6 + 1)
109 .click();
110
111 headerShouldBe('Team Selection');
112 cy.get('#match_number').should('have.value', '3');
113 cy.get('#team_number').should('have.value', '5254');
114 cy.get('#set_number').should('have.value', '2');
115 cy.get('#comp_level').should('have.value', '3: sf');
116 });
117
Filip Kujawa0ef334c2023-02-20 19:42:45 -0800118 //TODO(FILIP): Rewrite tests for the new scouting interface.
119 /*
Philipp Schrader175a93c2023-02-19 13:13:40 -0800120 it('should: error on unknown match.', () => {
121 switchToTab('Data Entry');
122 headerShouldBe('Team Selection');
123
124 // Pick a match that doesn't exist in the 2016nytr match list.
125 setInputTo('#match_number', '3');
126 setInputTo('#team_number', '971');
127
128 // Click Next until we get to the submit screen.
129 for (let i = 0; i < 5; i++) {
130 clickButton('Next');
131 }
132 headerShouldBe('Review and Submit');
133
134 // Attempt to submit and validate the error.
135 clickButton('Submit');
136 cy.get('.error_message').contains(
137 'Failed to find team 971 in match 3 in the schedule.'
138 );
139 });
140
141 // Make sure that each page on the Entry tab has both "Next" and "Back"
142 // buttons. The only screens exempted from this are the first page and the
143 // last page.
144 it('should: have forwards and backwards buttons.', () => {
145 switchToTab('Data Entry');
146
147 const expectedOrder = [
148 'Team Selection',
149 'Auto',
150 'TeleOp',
151 'Climb',
152 'Other',
153 'Review and Submit',
154 ];
155
156 // Go forward through the screens.
157 for (let i = 0; i < expectedOrder.length; i++) {
158 headerShouldBe(expectedOrder[i]);
159 if (i != expectedOrder.length - 1) {
160 clickButton('Next');
161 }
162 }
163
164 // Go backwards through the screens.
165 for (let i = 0; i < expectedOrder.length; i++) {
166 headerShouldBe(expectedOrder[expectedOrder.length - i - 1]);
167 if (i != expectedOrder.length - 1) {
168 clickButton('Back');
169 }
170 }
171 });
Filip Kujawa0ef334c2023-02-20 19:42:45 -0800172
Philipp Schrader175a93c2023-02-19 13:13:40 -0800173
174 it('should: review and submit correct data.', () => {
175 switchToTab('Data Entry');
176
177 // Submit scouting data for a random team that attended 2016nytr.
178 headerShouldBe('Team Selection');
179 setInputTo('#match_number', '2');
180 setInputTo('#team_number', '5254');
181 setInputTo('#set_number', '42');
182 cy.get('#comp_level').select('Semi Finals');
183 clickButton('Next');
184
185 headerShouldBe('Auto');
186 cy.get('#quadrant3').check();
187 clickButton('Next');
188
189 headerShouldBe('TeleOp');
190 clickButton('Next');
191
192 headerShouldBe('Climb');
193 cy.get('#high').check();
194 clickButton('Next');
195
196 headerShouldBe('Other');
197 adjustNthSliderBy(0, 3);
198 adjustNthSliderBy(1, 1);
199 cy.get('#no_show').check();
200 cy.get('#mechanically_broke').check();
201 setInputTo('#comment', 'A very useful comment here.');
202 clickButton('Next');
203
204 headerShouldBe('Review and Submit');
205 cy.get('.error_message').should('have.text', '');
206
207 // Validate Team Selection.
208 expectReviewFieldToBe('Match number', '2');
209 expectReviewFieldToBe('Team number', '5254');
210 expectReviewFieldToBe('SetNumber', '42');
211 expectReviewFieldToBe('Comp Level', 'Semi Finals');
212
213 // Validate Auto.
214 expectNthReviewFieldToBe('Upper Shots Made', 0, '0');
215 expectNthReviewFieldToBe('Lower Shots Made', 0, '0');
216 expectNthReviewFieldToBe('Missed Shots', 0, '0');
217 expectReviewFieldToBe('Quadrant', '3');
218
219 // Validate TeleOp.
220 expectNthReviewFieldToBe('Upper Shots Made', 1, '0');
221 expectNthReviewFieldToBe('Lower Shots Made', 1, '0');
222 expectNthReviewFieldToBe('Missed Shots', 1, '0');
223
224 // Validate Climb.
225 expectReviewFieldToBe('Climb Level', 'High');
226
227 // Validate Other.
228 expectReviewFieldToBe('Defense Played On Rating', '3');
229 expectReviewFieldToBe('Defense Played Rating', '1');
230 expectReviewFieldToBe('No show', 'true');
231 expectReviewFieldToBe('Never moved', 'false');
232 expectReviewFieldToBe('Battery died', 'false');
233 expectReviewFieldToBe('Broke (mechanically)', 'true');
234 expectReviewFieldToBe('Comments', 'A very useful comment here.');
235
236 clickButton('Submit');
237 headerShouldBe('Success');
238 });
239
Filip Kujawa0ef334c2023-02-20 19:42:45 -0800240 */
Philipp Schrader175a93c2023-02-19 13:13:40 -0800241
242 it('should: submit note scouting for multiple teams', () => {
243 // Navigate to Notes Page.
244 switchToTab('Notes');
245 headerShouldBe('Notes');
246
247 // Add first team.
248 setInputTo('#team_number_notes', '1234');
249 clickButton('Select');
250
251 // Add note and select keyword for first team.
252 cy.get('#team-key-1').should('have.text', '1234');
253 setInputTo('#text-input-1', 'Good Driving');
254 cy.get('#good_driving_0').click();
255
256 // Navigate to add team selection and add another team.
257 clickButton('Add team');
258 setInputTo('#team_number_notes', '1235');
259 clickButton('Select');
260
261 // Add note and select keyword for second team.
262 cy.get('#team-key-2').should('have.text', '1235');
263 setInputTo('#text-input-2', 'Bad Driving');
264 cy.get('#bad_driving_1').click();
265
266 // Submit Notes.
267 clickButton('Submit');
268 cy.get('#team_number_label').should('have.text', ' Team Number ');
269 });
270
271 it('should: switch note text boxes with keyboard shortcuts', () => {
272 // Navigate to Notes Page.
273 switchToTab('Notes');
274 headerShouldBe('Notes');
275
276 // Add first team.
277 setInputTo('#team_number_notes', '1234');
278 clickButton('Select');
279
280 // Add second team.
281 clickButton('Add team');
282 setInputTo('#team_number_notes', '1235');
283 clickButton('Select');
284
285 // Add third team.
286 clickButton('Add team');
287 setInputTo('#team_number_notes', '1236');
288 clickButton('Select');
289
290 for (let i = 1; i <= 3; i++) {
291 // Press Control + i
292 cy.get('body').type(`{ctrl}${i}`);
293
294 // Expect text input to be focused.
295 cy.focused().then(($element) => {
296 expect($element).to.have.id(`text-input-${i}`);
297 });
298 }
299 });
300
301 it('should: submit driver ranking', () => {
302 // Navigate to Driver Ranking Page.
303 switchToTab('Driver Ranking');
304 headerShouldBe('Driver Ranking');
305
306 // Input match and team numbers.
307 setInputTo('#match_number_selection', '11');
308 setInputTo('#team_input_0', '123');
309 setInputTo('#team_input_1', '456');
310 setInputTo('#team_input_2', '789');
311 clickButton('Select');
312
313 // Verify match and team key input.
314 cy.get('#match_number_heading').should('have.text', 'Match #11');
315 cy.get('#team_key_label_0').should('have.text', ' 123 ');
316 cy.get('#team_key_label_1').should('have.text', ' 456 ');
317 cy.get('#team_key_label_2').should('have.text', ' 789 ');
318
319 // Rank teams.
320 cy.get('#up_button_2').click();
321 cy.get('#down_button_0').click();
322
323 // Verify ranking change.
324 cy.get('#team_key_label_0').should('have.text', ' 789 ');
325 cy.get('#team_key_label_1').should('have.text', ' 123 ');
326 cy.get('#team_key_label_2').should('have.text', ' 456 ');
327
328 // Submit.
329 clickButton('Submit');
330 });
331});