blob: 31ca9356b6ded3757840de91fc45a61dd6a63101 [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}
120
Philipp Schrader175a93c2023-02-19 13:13:40 -0800121before(() => {
122 cy.visit('/');
123 disableAlerts();
124 cy.title().should('eq', 'FRC971 Scouting Application');
Philipp Schrader175a93c2023-02-19 13:13:40 -0800125});
126
127beforeEach(() => {
128 cy.visit('/');
129 disableAlerts();
130});
131
132describe('Scouting app tests', () => {
133 it('should: show matches in chronological order.', () => {
134 headerShouldBe('Matches');
135 cy.get('.badge').eq(0).contains('Quals Match 1');
136 cy.get('.badge').eq(1).contains('Quals Match 2');
137 cy.get('.badge').eq(2).contains('Quals Match 3');
138 cy.get('.badge').eq(9).contains('Quals Match 10');
139 cy.get('.badge').eq(72).contains('Quarter Final 1 Match 1');
140 cy.get('.badge').eq(73).contains('Quarter Final 2 Match 1');
141 cy.get('.badge').eq(74).contains('Quarter Final 3 Match 1');
142 cy.get('.badge').eq(75).contains('Quarter Final 4 Match 1');
143 cy.get('.badge').eq(76).contains('Quarter Final 1 Match 2');
144 cy.get('.badge').eq(82).contains('Semi Final 1 Match 1');
145 cy.get('.badge').eq(83).contains('Semi Final 2 Match 1');
146 cy.get('.badge').eq(84).contains('Semi Final 1 Match 2');
147 cy.get('.badge').eq(85).contains('Semi Final 2 Match 2');
148 cy.get('.badge').eq(89).contains('Final 1 Match 3');
149 });
150
Philipp Schrader8702b782023-04-15 17:33:37 -0700151 it('should: prevent users from enter invalid match information.', () => {
152 switchToTab('Entry');
153 headerShouldBe(' Team Selection ');
154
155 setInputTo('#match_number', '1');
156 setInputTo('#team_number', '5254');
157 setInputTo('#set_number', '1');
158 cy.get('#comp_level').select('Qualifications');
159
160 cy.contains('button', 'Next').should('be.disabled');
161 });
162
Philipp Schradere1498852023-04-15 18:06:45 -0700163 it('should: allow users to scout non-existent matches when pre-scouting.', () => {
164 switchToTab('Entry');
165 headerShouldBe(' Team Selection ');
166 setInputTo('#team_number', '1');
167
168 // The default team information should be invalid.
169 cy.contains('button', 'Next').should('be.disabled');
170
171 // Click the checkmark to designate this as pre-scouting.
172 // We should now be able to continue scouting.
173 cy.get('#pre_scouting').click();
174 clickButton('Next');
175 headerShouldBe('1 Init ');
176 });
177
Emily Markova8e39f452023-12-23 12:17:30 -0800178 it('should: allow users to submit pit images.', () => {
179 switchToTab('Pit');
180 headerShouldBe('Pit Scouting');
181 setInputTo('#teamNumber', '971');
182
183 cy.get('#pitImage').selectFile('test_img_1.png');
184
185 clickButton('Submit');
186 headerShouldBe('Pit Scouting');
187 setInputTo('#teamNumber', '971');
188
189 cy.get('#pitImage').selectFile('test_img_2.png');
190
191 clickButton('Submit');
192 headerShouldBe('Pit Scouting');
193
194 switchToTab('View');
195
196 cy.get('[data-bs-toggle="dropdown"]').click();
197 cy.get('[id="pit_images_source_dropdown"]').click();
198 cy.get('table.table tbody th').should('contain', '971');
199 cy.get('img')
200 .first()
201 .should('be.visible')
202 .should('have.attr', 'src')
203 .should('include', 'test_img_1.png');
204 cy.get('img')
205 .last()
206 .should('be.visible')
207 .should('have.attr', 'src')
208 .should('include', 'test_img_2.png');
209 });
210
Philipp Schrader8702b782023-04-15 17:33:37 -0700211 it('should: let users enter match information manually.', () => {
Philipp Schrader75021f52023-04-09 21:14:13 -0700212 switchToTab('Entry');
Philipp Schrader2b334272023-04-11 21:27:36 -0700213 headerShouldBe(' Team Selection ');
Philipp Schrader75021f52023-04-09 21:14:13 -0700214
215 setInputTo('#match_number', '3');
216 setInputTo('#team_number', '5254');
217 setInputTo('#set_number', '2');
Philipp Schrader8702b782023-04-15 17:33:37 -0700218 cy.get('#comp_level').select('Semi Finals');
Philipp Schrader75021f52023-04-09 21:14:13 -0700219
220 clickButton('Next');
221
222 headerShouldBe('5254 Init ');
Philipp Schrader175a93c2023-02-19 13:13:40 -0800223 });
224
Filip Kujawa2dc9aa62023-03-04 11:45:01 -0800225 //TODO(FILIP): Verify last action when the last action header gets added.
Sabina Leaver9b4eb312023-02-20 19:58:17 -0800226 it('should: be able to submit data scouting.', () => {
Filip Kujawac1ded372023-05-27 14:33:43 -0700227 submitDataScouting();
Philipp Schradere11114f2023-04-15 17:04:25 -0700228
229 // Now that the data is submitted, the button should be disabled.
230 switchToTab('Match List');
231 cy.get('button.match-item')
232 .eq(SEMI_FINAL_2_MATCH_3_TEAM_5254)
233 .should('be.disabled');
Philipp Schrader175a93c2023-02-19 13:13:40 -0800234 });
235
Filip Kujawac1ded372023-05-27 14:33:43 -0700236 it('should: be able to delete data scouting entry', () => {
237 // Submit data to delete.
238 submitDataScouting(QUALS_MATCH_2_TEAM_4481, 4481);
239
240 switchToTab('View');
241
242 cy.get('[data-bs-toggle="dropdown"]').click();
243 cy.get('[id="stats_source_dropdown"]').click();
244
245 // Check that table contains data.
246 cy.get('table.table tbody td').should('contain', '4481');
247
248 // Find and click the delete button for the row containing team 4481.
249 cy.get('table.table tbody td')
250 .contains('4481')
251 .parent()
252 .find('[id^="delete_button_"]')
253 .click();
254 cy.on('window:confirm', () => true);
255
256 // Check that deleted data is not in table.
257 cy.get('table.table tbody').should('not.contain', '4481');
258 });
259
Filip Kujawa2dc9aa62023-03-04 11:45:01 -0800260 it('should: be able to return to correct screen with undo for pick and place.', () => {
Philipp Schradere11114f2023-04-15 17:04:25 -0700261 cy.get('button.match-item').eq(QUALS_MATCH_1_TEAM_3990).click();
Philipp Schrader2b334272023-04-11 21:27:36 -0700262
Filip Kujawa2dc9aa62023-03-04 11:45:01 -0800263 // Select Starting Position.
264 cy.get('[type="radio"]').first().check();
265 clickButton('Start Match');
Philipp Schrader175a93c2023-02-19 13:13:40 -0800266
Emily Markovadcadcb62024-02-03 13:07:17 -0800267 // Pick up note.
268 clickButton('NOTE');
Philipp Schrader175a93c2023-02-19 13:13:40 -0800269
Filip Kujawa2dc9aa62023-03-04 11:45:01 -0800270 // Undo that pick up.
271 clickButton('UNDO');
Philipp Schrader175a93c2023-02-19 13:13:40 -0800272
Filip Kujawa2dc9aa62023-03-04 11:45:01 -0800273 // User should be back on pickup screen.
Philipp Schradere11114f2023-04-15 17:04:25 -0700274 headerShouldBe('3990 Pickup ');
Philipp Schrader175a93c2023-02-19 13:13:40 -0800275
Filip Kujawa2dc9aa62023-03-04 11:45:01 -0800276 // Check the same thing but for undoing place.
Emily Markovadcadcb62024-02-03 13:07:17 -0800277 clickButton('NOTE');
278 clickButton('AMP');
Filip Kujawa2dc9aa62023-03-04 11:45:01 -0800279 clickButton('UNDO');
Philipp Schradere11114f2023-04-15 17:04:25 -0700280 headerShouldBe('3990 Place ');
Philipp Schrader175a93c2023-02-19 13:13:40 -0800281 });
282
Philipp Schrader175a93c2023-02-19 13:13:40 -0800283 it('should: submit note scouting for multiple teams', () => {
284 // Navigate to Notes Page.
285 switchToTab('Notes');
286 headerShouldBe('Notes');
287
288 // Add first team.
289 setInputTo('#team_number_notes', '1234');
290 clickButton('Select');
291
292 // Add note and select keyword for first team.
293 cy.get('#team-key-1').should('have.text', '1234');
294 setInputTo('#text-input-1', 'Good Driving');
295 cy.get('#good_driving_0').click();
296
297 // Navigate to add team selection and add another team.
298 clickButton('Add team');
299 setInputTo('#team_number_notes', '1235');
300 clickButton('Select');
301
302 // Add note and select keyword for second team.
303 cy.get('#team-key-2').should('have.text', '1235');
304 setInputTo('#text-input-2', 'Bad Driving');
305 cy.get('#bad_driving_1').click();
306
307 // Submit Notes.
308 clickButton('Submit');
309 cy.get('#team_number_label').should('have.text', ' Team Number ');
310 });
311
312 it('should: switch note text boxes with keyboard shortcuts', () => {
313 // Navigate to Notes Page.
314 switchToTab('Notes');
315 headerShouldBe('Notes');
316
317 // Add first team.
318 setInputTo('#team_number_notes', '1234');
319 clickButton('Select');
320
321 // Add second team.
322 clickButton('Add team');
323 setInputTo('#team_number_notes', '1235');
324 clickButton('Select');
325
326 // Add third team.
327 clickButton('Add team');
328 setInputTo('#team_number_notes', '1236');
329 clickButton('Select');
330
331 for (let i = 1; i <= 3; i++) {
332 // Press Control + i
333 cy.get('body').type(`{ctrl}${i}`);
334
335 // Expect text input to be focused.
336 cy.focused().then(($element) => {
337 expect($element).to.have.id(`text-input-${i}`);
338 });
339 }
340 });
341
342 it('should: submit driver ranking', () => {
343 // Navigate to Driver Ranking Page.
344 switchToTab('Driver Ranking');
345 headerShouldBe('Driver Ranking');
346
347 // Input match and team numbers.
348 setInputTo('#match_number_selection', '11');
349 setInputTo('#team_input_0', '123');
350 setInputTo('#team_input_1', '456');
351 setInputTo('#team_input_2', '789');
352 clickButton('Select');
353
354 // Verify match and team key input.
355 cy.get('#match_number_heading').should('have.text', 'Match #11');
356 cy.get('#team_key_label_0').should('have.text', ' 123 ');
357 cy.get('#team_key_label_1').should('have.text', ' 456 ');
358 cy.get('#team_key_label_2').should('have.text', ' 789 ');
359
360 // Rank teams.
361 cy.get('#up_button_2').click();
362 cy.get('#down_button_0').click();
363
364 // Verify ranking change.
365 cy.get('#team_key_label_0').should('have.text', ' 789 ');
366 cy.get('#team_key_label_1').should('have.text', ' 123 ');
367 cy.get('#team_key_label_2').should('have.text', ' 456 ');
368
369 // Submit.
370 clickButton('Submit');
371 });
372});