blob: 1d7620ab87ad260c31e40437e5bc58056acf23a7 [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
Philipp Schrader2b334272023-04-11 21:27:36 -070023// Click on a random team in the Match list. The exact details here are not
24// important, but we need to know what they are. This could as well be any
25// other team from any other match.
26function clickSemiFinal2Match3Team5254() {
27 // On the 87th row of matches (index 86) click on the second team
28 // (index 1) which resolves to team 5254 in semi final 2 match 3.
29 cy.get('button.match-item')
30 .eq(86 * 6 + 1)
31 .click();
32}
33
Philipp Schrader175a93c2023-02-19 13:13:40 -080034// Moves the nth slider left or right. A positive "adjustBy" value moves the
35// slider to the right. A negative value moves the slider to the left.
36//
37// negative/left <--- 0 ---> positive/right
38function adjustNthSliderBy(n, adjustBy) {
39 let element = cy.get('input[type=range]').eq(n);
40 element.scrollIntoView();
41 element.invoke('val').then((currentValue) => {
42 // We need to query for the slider here again because `invoke('val')` above
43 // somehow invalidates further calls to `val`.
44 cy.get('input[type=range]')
45 .eq(n)
46 .invoke('val', currentValue + adjustBy)
47 .trigger('change');
48 });
49}
50
51// Asserts that the field on the "Submit and Review" screen has a specific
52// value.
53function expectReviewFieldToBe(fieldName, expectedValue) {
54 expectNthReviewFieldToBe(fieldName, 0, expectedValue);
55}
56
57// Asserts that the n'th instance of a field on the "Submit and Review"
58// screen has a specific value.
59function expectNthReviewFieldToBe(fieldName, n, expectedValue) {
60 getNthReviewField(fieldName, n).should(
61 'have.text',
62 `${fieldName}: ${expectedValue}`
63 );
64}
65
66function getNthReviewField(fieldName, n) {
67 let element = cy.get('li').filter(`:contains("${fieldName}: ")`).eq(n);
68 element.scrollIntoView();
69 return element;
70}
71
72before(() => {
73 cy.visit('/');
74 disableAlerts();
75 cy.title().should('eq', 'FRC971 Scouting Application');
Philipp Schrader175a93c2023-02-19 13:13:40 -080076});
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
Philipp Schrader75021f52023-04-09 21:14:13 -0700102 it('should: be let users enter match information manually.', () => {
103 switchToTab('Entry');
Philipp Schrader2b334272023-04-11 21:27:36 -0700104 headerShouldBe(' Team Selection ');
Philipp Schrader75021f52023-04-09 21:14:13 -0700105
106 setInputTo('#match_number', '3');
107 setInputTo('#team_number', '5254');
108 setInputTo('#set_number', '2');
109 setInputTo('#comp_level', '3: sf');
110
111 clickButton('Next');
112
113 headerShouldBe('5254 Init ');
Philipp Schrader175a93c2023-02-19 13:13:40 -0800114 });
115
Filip Kujawa2dc9aa62023-03-04 11:45:01 -0800116 //TODO(FILIP): Verify last action when the last action header gets added.
Sabina Leaver9b4eb312023-02-20 19:58:17 -0800117 it('should: be able to submit data scouting.', () => {
Philipp Schrader2b334272023-04-11 21:27:36 -0700118 clickSemiFinal2Match3Team5254();
119
Filip Kujawa2dc9aa62023-03-04 11:45:01 -0800120 // Select Starting Position.
Philipp Schrader2b334272023-04-11 21:27:36 -0700121 headerShouldBe('5254 Init ');
Filip Kujawa2dc9aa62023-03-04 11:45:01 -0800122 cy.get('[type="radio"]').first().check();
123 clickButton('Start Match');
Philipp Schrader175a93c2023-02-19 13:13:40 -0800124
Filip Kujawa2dc9aa62023-03-04 11:45:01 -0800125 // Pick and Place Cone in Auto.
126 clickButton('CONE');
127 clickButton('HIGH');
128
129 // Pick and Place Cube in Teleop.
130 clickButton('Start Teleop');
131 clickButton('CUBE');
132 clickButton('LOW');
133
134 // Robot dead and revive.
135 clickButton('DEAD');
136 clickButton('Revive');
137
138 // Engame.
139 clickButton('Endgame');
140 cy.get('[type="checkbox"]').check();
141
Filip Kujawa2dc9aa62023-03-04 11:45:01 -0800142 clickButton('End Match');
Philipp Schrader2b334272023-04-11 21:27:36 -0700143 headerShouldBe('5254 Review and Submit ');
Sabina Leaver9b4eb312023-02-20 19:58:17 -0800144
145 clickButton('Submit');
Philipp Schrader2b334272023-04-11 21:27:36 -0700146 headerShouldBe('5254 Success ');
Philipp Schrader175a93c2023-02-19 13:13:40 -0800147 });
148
Filip Kujawa2dc9aa62023-03-04 11:45:01 -0800149 it('should: be able to return to correct screen with undo for pick and place.', () => {
Philipp Schrader2b334272023-04-11 21:27:36 -0700150 clickSemiFinal2Match3Team5254();
151
Filip Kujawa2dc9aa62023-03-04 11:45:01 -0800152 // Select Starting Position.
153 cy.get('[type="radio"]').first().check();
154 clickButton('Start Match');
Philipp Schrader175a93c2023-02-19 13:13:40 -0800155
Filip Kujawa2dc9aa62023-03-04 11:45:01 -0800156 // Pick up cone.
157 clickButton('CONE');
Philipp Schrader175a93c2023-02-19 13:13:40 -0800158
Filip Kujawa2dc9aa62023-03-04 11:45:01 -0800159 // Undo that pick up.
160 clickButton('UNDO');
Philipp Schrader175a93c2023-02-19 13:13:40 -0800161
Filip Kujawa2dc9aa62023-03-04 11:45:01 -0800162 // User should be back on pickup screen.
Philipp Schrader2b334272023-04-11 21:27:36 -0700163 headerShouldBe('5254 Pickup ');
Philipp Schrader175a93c2023-02-19 13:13:40 -0800164
Filip Kujawa2dc9aa62023-03-04 11:45:01 -0800165 // Check the same thing but for undoing place.
166 clickButton('CUBE');
167 clickButton('MID');
168 clickButton('UNDO');
Philipp Schrader2b334272023-04-11 21:27:36 -0700169 headerShouldBe('5254 Place ');
Philipp Schrader175a93c2023-02-19 13:13:40 -0800170 });
171
Philipp Schrader175a93c2023-02-19 13:13:40 -0800172 it('should: submit note scouting for multiple teams', () => {
173 // Navigate to Notes Page.
174 switchToTab('Notes');
175 headerShouldBe('Notes');
176
177 // Add first team.
178 setInputTo('#team_number_notes', '1234');
179 clickButton('Select');
180
181 // Add note and select keyword for first team.
182 cy.get('#team-key-1').should('have.text', '1234');
183 setInputTo('#text-input-1', 'Good Driving');
184 cy.get('#good_driving_0').click();
185
186 // Navigate to add team selection and add another team.
187 clickButton('Add team');
188 setInputTo('#team_number_notes', '1235');
189 clickButton('Select');
190
191 // Add note and select keyword for second team.
192 cy.get('#team-key-2').should('have.text', '1235');
193 setInputTo('#text-input-2', 'Bad Driving');
194 cy.get('#bad_driving_1').click();
195
196 // Submit Notes.
197 clickButton('Submit');
198 cy.get('#team_number_label').should('have.text', ' Team Number ');
199 });
200
201 it('should: switch note text boxes with keyboard shortcuts', () => {
202 // Navigate to Notes Page.
203 switchToTab('Notes');
204 headerShouldBe('Notes');
205
206 // Add first team.
207 setInputTo('#team_number_notes', '1234');
208 clickButton('Select');
209
210 // Add second team.
211 clickButton('Add team');
212 setInputTo('#team_number_notes', '1235');
213 clickButton('Select');
214
215 // Add third team.
216 clickButton('Add team');
217 setInputTo('#team_number_notes', '1236');
218 clickButton('Select');
219
220 for (let i = 1; i <= 3; i++) {
221 // Press Control + i
222 cy.get('body').type(`{ctrl}${i}`);
223
224 // Expect text input to be focused.
225 cy.focused().then(($element) => {
226 expect($element).to.have.id(`text-input-${i}`);
227 });
228 }
229 });
230
231 it('should: submit driver ranking', () => {
232 // Navigate to Driver Ranking Page.
233 switchToTab('Driver Ranking');
234 headerShouldBe('Driver Ranking');
235
236 // Input match and team numbers.
237 setInputTo('#match_number_selection', '11');
238 setInputTo('#team_input_0', '123');
239 setInputTo('#team_input_1', '456');
240 setInputTo('#team_input_2', '789');
241 clickButton('Select');
242
243 // Verify match and team key input.
244 cy.get('#match_number_heading').should('have.text', 'Match #11');
245 cy.get('#team_key_label_0').should('have.text', ' 123 ');
246 cy.get('#team_key_label_1').should('have.text', ' 456 ');
247 cy.get('#team_key_label_2').should('have.text', ' 789 ');
248
249 // Rank teams.
250 cy.get('#up_button_2').click();
251 cy.get('#down_button_0').click();
252
253 // Verify ranking change.
254 cy.get('#team_key_label_0').should('have.text', ' 789 ');
255 cy.get('#team_key_label_1').should('have.text', ' 123 ');
256 cy.get('#team_key_label_2').should('have.text', ' 456 ');
257
258 // Submit.
259 clickButton('Submit');
260 });
261});