blob: d15cdfc2981dafc0bf457fefd79f3114939fbef9 [file] [log] [blame]
Philipp Schrader175a93c2023-02-19 13:13:40 -08001/// <reference types="cypress" />
2
Philipp Schradere11114f2023-04-15 17:04:25 -07003// On the 87th row of matches (index 86) click on the second team
4// (index 1) which resolves to team 5254 in semi final 2 match 3.
5const SEMI_FINAL_2_MATCH_3_TEAM_5254 = 86 * 6 + 1;
6
7// On the 1st row of matches (index 0) click on the fourth team
8// (index 3) which resolves to team 3990 in quals match 1.
9const QUALS_MATCH_1_TEAM_3990 = 0 * 6 + 3;
10
Filip Kujawac1ded372023-05-27 14:33:43 -070011// On the 2st row of matches (index 1) click on the fourth team
12// (index 3) which resolves to team 4481 in quals match 1.
13const QUALS_MATCH_2_TEAM_4481 = 1 * 6 + 3;
14
Philipp Schrader175a93c2023-02-19 13:13:40 -080015function disableAlerts() {
16 cy.get('#block_alerts').check({force: true}).should('be.checked');
17}
18
19function switchToTab(tabName) {
20 cy.contains('.nav-link', tabName).click();
21}
22
23function headerShouldBe(text) {
24 cy.get('.header').should('have.text', text);
25}
26
27function clickButton(buttonName) {
28 cy.contains('button', buttonName).click();
29}
30
31function setInputTo(fieldSelector, value) {
32 cy.get(fieldSelector).type('{selectAll}' + value);
33}
34
35// Moves the nth slider left or right. A positive "adjustBy" value moves the
36// slider to the right. A negative value moves the slider to the left.
37//
38// negative/left <--- 0 ---> positive/right
39function adjustNthSliderBy(n, adjustBy) {
40 let element = cy.get('input[type=range]').eq(n);
41 element.scrollIntoView();
42 element.invoke('val').then((currentValue) => {
43 // We need to query for the slider here again because `invoke('val')` above
44 // somehow invalidates further calls to `val`.
45 cy.get('input[type=range]')
46 .eq(n)
47 .invoke('val', currentValue + adjustBy)
48 .trigger('change');
49 });
50}
51
52// Asserts that the field on the "Submit and Review" screen has a specific
53// value.
54function expectReviewFieldToBe(fieldName, expectedValue) {
55 expectNthReviewFieldToBe(fieldName, 0, expectedValue);
56}
57
58// Asserts that the n'th instance of a field on the "Submit and Review"
59// screen has a specific value.
60function expectNthReviewFieldToBe(fieldName, n, expectedValue) {
61 getNthReviewField(fieldName, n).should(
62 'have.text',
63 `${fieldName}: ${expectedValue}`
64 );
65}
66
67function getNthReviewField(fieldName, n) {
68 let element = cy.get('li').filter(`:contains("${fieldName}: ")`).eq(n);
69 element.scrollIntoView();
70 return element;
71}
72
Filip Kujawac1ded372023-05-27 14:33:43 -070073function submitDataScouting(
74 matchButtonKey = SEMI_FINAL_2_MATCH_3_TEAM_5254,
75 teamNumber = 5254
76) {
77 // Click on a random team in the Match list. The exact details here are not
78 // important, but we need to know what they are. This could as well be any
79 // other team from any other match.
80 cy.get('button.match-item').eq(matchButtonKey).click();
81
82 // Select Starting Position.
83 headerShouldBe(teamNumber + ' Init ');
84 cy.get('[type="radio"]').first().check();
85 clickButton('Start Match');
86
Emily Markovadcadcb62024-02-03 13:07:17 -080087 // Pick and Place Note in Auto.
88 clickButton('NOTE');
89 clickButton('AMP');
Filip Kujawac1ded372023-05-27 14:33:43 -070090
91 // Pick and Place Cube in Teleop.
92 clickButton('Start Teleop');
Emily Markovadcadcb62024-02-03 13:07:17 -080093 clickButton('NOTE');
94 clickButton('AMP AMPLIFIED');
Filip Kujawac1ded372023-05-27 14:33:43 -070095
96 // Robot dead and revive.
97 clickButton('DEAD');
98 clickButton('Revive');
99
100 // Endgame.
101 clickButton('Endgame');
Emily Markovadcadcb62024-02-03 13:07:17 -0800102 cy.contains(/Harmony/).click();
Filip Kujawac1ded372023-05-27 14:33:43 -0700103
104 clickButton('End Match');
105 headerShouldBe(teamNumber + ' Review and Submit ');
106 cy.get('#review_data li')
107 .eq(0)
108 .should('have.text', ' Started match at position 1 ');
Emily Markovadcadcb62024-02-03 13:07:17 -0800109 cy.get('#review_data li').eq(1).should('have.text', 'Picked up Note');
Filip Kujawac1ded372023-05-27 14:33:43 -0700110 cy.get('#review_data li')
111 .last()
112 .should(
113 'have.text',
Emily Markova6079e2f2024-02-17 13:17:24 -0800114 ' Ended Match; stageType: kHARMONY, trapNote: false, spotlight: false '
Filip Kujawac1ded372023-05-27 14:33:43 -0700115 );
116
117 clickButton('Submit');
118 headerShouldBe(teamNumber + ' Success ');
119}
Emily Markova7b786402024-01-24 20:05:24 -0800120function visit(path) {
121 cy.visit(path, {
122 onBeforeLoad(win) {
123 // The service worker seems to interfere with Cypress somehow. There
124 // doesn't seem to be a proper fix for this issue. Work around it with
125 // this hack that disables the service worker.
126 // https://github.com/cypress-io/cypress/issues/16192#issuecomment-870421667
127 // https://github.com/cypress-io/cypress/issues/702#issuecomment-587127275
128 delete win.navigator.__proto__.serviceWorker;
129 },
130 });
131}
Filip Kujawac1ded372023-05-27 14:33:43 -0700132
Philipp Schrader175a93c2023-02-19 13:13:40 -0800133before(() => {
Emily Markova7b786402024-01-24 20:05:24 -0800134 visit('/');
Philipp Schrader175a93c2023-02-19 13:13:40 -0800135 disableAlerts();
136 cy.title().should('eq', 'FRC971 Scouting Application');
Philipp Schrader175a93c2023-02-19 13:13:40 -0800137});
138
139beforeEach(() => {
Emily Markova7b786402024-01-24 20:05:24 -0800140 visit('/');
Philipp Schrader175a93c2023-02-19 13:13:40 -0800141 disableAlerts();
142});
143
144describe('Scouting app tests', () => {
145 it('should: show matches in chronological order.', () => {
146 headerShouldBe('Matches');
147 cy.get('.badge').eq(0).contains('Quals Match 1');
148 cy.get('.badge').eq(1).contains('Quals Match 2');
149 cy.get('.badge').eq(2).contains('Quals Match 3');
150 cy.get('.badge').eq(9).contains('Quals Match 10');
151 cy.get('.badge').eq(72).contains('Quarter Final 1 Match 1');
152 cy.get('.badge').eq(73).contains('Quarter Final 2 Match 1');
153 cy.get('.badge').eq(74).contains('Quarter Final 3 Match 1');
154 cy.get('.badge').eq(75).contains('Quarter Final 4 Match 1');
155 cy.get('.badge').eq(76).contains('Quarter Final 1 Match 2');
156 cy.get('.badge').eq(82).contains('Semi Final 1 Match 1');
157 cy.get('.badge').eq(83).contains('Semi Final 2 Match 1');
158 cy.get('.badge').eq(84).contains('Semi Final 1 Match 2');
159 cy.get('.badge').eq(85).contains('Semi Final 2 Match 2');
160 cy.get('.badge').eq(89).contains('Final 1 Match 3');
161 });
162
Philipp Schrader8702b782023-04-15 17:33:37 -0700163 it('should: prevent users from enter invalid match information.', () => {
164 switchToTab('Entry');
165 headerShouldBe(' Team Selection ');
166
167 setInputTo('#match_number', '1');
168 setInputTo('#team_number', '5254');
169 setInputTo('#set_number', '1');
170 cy.get('#comp_level').select('Qualifications');
171
172 cy.contains('button', 'Next').should('be.disabled');
173 });
174
Philipp Schradere1498852023-04-15 18:06:45 -0700175 it('should: allow users to scout non-existent matches when pre-scouting.', () => {
176 switchToTab('Entry');
177 headerShouldBe(' Team Selection ');
178 setInputTo('#team_number', '1');
179
180 // The default team information should be invalid.
181 cy.contains('button', 'Next').should('be.disabled');
182
183 // Click the checkmark to designate this as pre-scouting.
184 // We should now be able to continue scouting.
185 cy.get('#pre_scouting').click();
186 clickButton('Next');
187 headerShouldBe('1 Init ');
188 });
189
Emily Markova8e39f452023-12-23 12:17:30 -0800190 it('should: allow users to submit pit images.', () => {
191 switchToTab('Pit');
192 headerShouldBe('Pit Scouting');
193 setInputTo('#teamNumber', '971');
194
195 cy.get('#pitImage').selectFile('test_img_1.png');
196
197 clickButton('Submit');
198 headerShouldBe('Pit Scouting');
199 setInputTo('#teamNumber', '971');
200
201 cy.get('#pitImage').selectFile('test_img_2.png');
202
203 clickButton('Submit');
204 headerShouldBe('Pit Scouting');
205
206 switchToTab('View');
207
208 cy.get('[data-bs-toggle="dropdown"]').click();
209 cy.get('[id="pit_images_source_dropdown"]').click();
210 cy.get('table.table tbody th').should('contain', '971');
211 cy.get('img')
212 .first()
213 .should('be.visible')
214 .should('have.attr', 'src')
215 .should('include', 'test_img_1.png');
216 cy.get('img')
217 .last()
218 .should('be.visible')
219 .should('have.attr', 'src')
220 .should('include', 'test_img_2.png');
221 });
222
Philipp Schrader8702b782023-04-15 17:33:37 -0700223 it('should: let users enter match information manually.', () => {
Philipp Schrader75021f52023-04-09 21:14:13 -0700224 switchToTab('Entry');
Philipp Schrader2b334272023-04-11 21:27:36 -0700225 headerShouldBe(' Team Selection ');
Philipp Schrader75021f52023-04-09 21:14:13 -0700226
227 setInputTo('#match_number', '3');
228 setInputTo('#team_number', '5254');
229 setInputTo('#set_number', '2');
Philipp Schrader8702b782023-04-15 17:33:37 -0700230 cy.get('#comp_level').select('Semi Finals');
Philipp Schrader75021f52023-04-09 21:14:13 -0700231
232 clickButton('Next');
233
234 headerShouldBe('5254 Init ');
Philipp Schrader175a93c2023-02-19 13:13:40 -0800235 });
236
Filip Kujawa2dc9aa62023-03-04 11:45:01 -0800237 //TODO(FILIP): Verify last action when the last action header gets added.
Sabina Leaver9b4eb312023-02-20 19:58:17 -0800238 it('should: be able to submit data scouting.', () => {
Filip Kujawac1ded372023-05-27 14:33:43 -0700239 submitDataScouting();
Philipp Schradere11114f2023-04-15 17:04:25 -0700240
241 // Now that the data is submitted, the button should be disabled.
242 switchToTab('Match List');
243 cy.get('button.match-item')
244 .eq(SEMI_FINAL_2_MATCH_3_TEAM_5254)
245 .should('be.disabled');
Philipp Schrader175a93c2023-02-19 13:13:40 -0800246 });
247
Filip Kujawac1ded372023-05-27 14:33:43 -0700248 it('should: be able to delete data scouting entry', () => {
249 // Submit data to delete.
250 submitDataScouting(QUALS_MATCH_2_TEAM_4481, 4481);
251
252 switchToTab('View');
253
254 cy.get('[data-bs-toggle="dropdown"]').click();
255 cy.get('[id="stats_source_dropdown"]').click();
256
257 // Check that table contains data.
258 cy.get('table.table tbody td').should('contain', '4481');
259
260 // Find and click the delete button for the row containing team 4481.
261 cy.get('table.table tbody td')
262 .contains('4481')
263 .parent()
264 .find('[id^="delete_button_"]')
265 .click();
266 cy.on('window:confirm', () => true);
267
268 // Check that deleted data is not in table.
269 cy.get('table.table tbody').should('not.contain', '4481');
270 });
271
Filip Kujawa2dc9aa62023-03-04 11:45:01 -0800272 it('should: be able to return to correct screen with undo for pick and place.', () => {
Philipp Schradere11114f2023-04-15 17:04:25 -0700273 cy.get('button.match-item').eq(QUALS_MATCH_1_TEAM_3990).click();
Philipp Schrader2b334272023-04-11 21:27:36 -0700274
Filip Kujawa2dc9aa62023-03-04 11:45:01 -0800275 // Select Starting Position.
276 cy.get('[type="radio"]').first().check();
277 clickButton('Start Match');
Philipp Schrader175a93c2023-02-19 13:13:40 -0800278
Emily Markovadcadcb62024-02-03 13:07:17 -0800279 // Pick up note.
280 clickButton('NOTE');
Philipp Schrader175a93c2023-02-19 13:13:40 -0800281
Filip Kujawa2dc9aa62023-03-04 11:45:01 -0800282 // Undo that pick up.
283 clickButton('UNDO');
Philipp Schrader175a93c2023-02-19 13:13:40 -0800284
Filip Kujawa2dc9aa62023-03-04 11:45:01 -0800285 // User should be back on pickup screen.
Philipp Schradere11114f2023-04-15 17:04:25 -0700286 headerShouldBe('3990 Pickup ');
Philipp Schrader175a93c2023-02-19 13:13:40 -0800287
Filip Kujawa2dc9aa62023-03-04 11:45:01 -0800288 // Check the same thing but for undoing place.
Emily Markovadcadcb62024-02-03 13:07:17 -0800289 clickButton('NOTE');
290 clickButton('AMP');
Filip Kujawa2dc9aa62023-03-04 11:45:01 -0800291 clickButton('UNDO');
Philipp Schradere11114f2023-04-15 17:04:25 -0700292 headerShouldBe('3990 Place ');
Philipp Schrader175a93c2023-02-19 13:13:40 -0800293 });
294
Philipp Schrader175a93c2023-02-19 13:13:40 -0800295 it('should: submit note scouting for multiple teams', () => {
296 // Navigate to Notes Page.
297 switchToTab('Notes');
298 headerShouldBe('Notes');
299
300 // Add first team.
301 setInputTo('#team_number_notes', '1234');
302 clickButton('Select');
303
304 // Add note and select keyword for first team.
305 cy.get('#team-key-1').should('have.text', '1234');
306 setInputTo('#text-input-1', 'Good Driving');
307 cy.get('#good_driving_0').click();
308
309 // Navigate to add team selection and add another team.
310 clickButton('Add team');
311 setInputTo('#team_number_notes', '1235');
312 clickButton('Select');
313
314 // Add note and select keyword for second team.
315 cy.get('#team-key-2').should('have.text', '1235');
316 setInputTo('#text-input-2', 'Bad Driving');
317 cy.get('#bad_driving_1').click();
318
319 // Submit Notes.
320 clickButton('Submit');
321 cy.get('#team_number_label').should('have.text', ' Team Number ');
322 });
323
324 it('should: switch note text boxes with keyboard shortcuts', () => {
325 // Navigate to Notes Page.
326 switchToTab('Notes');
327 headerShouldBe('Notes');
328
329 // Add first team.
330 setInputTo('#team_number_notes', '1234');
331 clickButton('Select');
332
333 // Add second team.
334 clickButton('Add team');
335 setInputTo('#team_number_notes', '1235');
336 clickButton('Select');
337
338 // Add third team.
339 clickButton('Add team');
340 setInputTo('#team_number_notes', '1236');
341 clickButton('Select');
342
343 for (let i = 1; i <= 3; i++) {
344 // Press Control + i
345 cy.get('body').type(`{ctrl}${i}`);
346
347 // Expect text input to be focused.
348 cy.focused().then(($element) => {
349 expect($element).to.have.id(`text-input-${i}`);
350 });
351 }
352 });
353
354 it('should: submit driver ranking', () => {
355 // Navigate to Driver Ranking Page.
356 switchToTab('Driver Ranking');
357 headerShouldBe('Driver Ranking');
358
359 // Input match and team numbers.
360 setInputTo('#match_number_selection', '11');
361 setInputTo('#team_input_0', '123');
362 setInputTo('#team_input_1', '456');
363 setInputTo('#team_input_2', '789');
364 clickButton('Select');
365
366 // Verify match and team key input.
367 cy.get('#match_number_heading').should('have.text', 'Match #11');
368 cy.get('#team_key_label_0').should('have.text', ' 123 ');
369 cy.get('#team_key_label_1').should('have.text', ' 456 ');
370 cy.get('#team_key_label_2').should('have.text', ' 789 ');
371
372 // Rank teams.
373 cy.get('#up_button_2').click();
374 cy.get('#down_button_0').click();
375
376 // Verify ranking change.
377 cy.get('#team_key_label_0').should('have.text', ' 789 ');
378 cy.get('#team_key_label_1').should('have.text', ' 123 ');
379 cy.get('#team_key_label_2').should('have.text', ' 456 ');
380
381 // Submit.
382 clickButton('Submit');
383 });
384});