blob: 5740cc8490f37fdfe9fcea60144594f6c43aeb68 [file] [log] [blame]
Philipp Schraderfa096932022-03-05 20:07:10 -08001import {browser, by, element, protractor} from 'protractor';
Philipp Schraderd999c9f2022-02-27 15:48:58 -08002
Philipp Schrader5f190012022-03-15 23:29:09 -07003const EC = protractor.ExpectedConditions;
4
Philipp Schrader577befe2022-03-15 00:00:49 -07005// Loads the page (or reloads it) and deals with the "Are you sure you want to
6// leave this page" popup.
7async function loadPage() {
Philipp Schradercf915462022-03-16 23:42:22 -07008 await disableAlerts();
9 await browser.navigate().refresh();
Philipp Schrader817cce32022-03-26 15:00:00 -070010 expect(await browser.getTitle()).toEqual('FRC971 Scouting Application');
Philipp Schrader5f190012022-03-15 23:29:09 -070011 await disableAlerts();
Philipp Schrader577befe2022-03-15 00:00:49 -070012}
13
Philipp Schradercf915462022-03-16 23:42:22 -070014// Disables alert popups. They are extremely tedious to deal with in
15// Protractor since they're not angular elements. We achieve this by checking
16// an invisible checkbox that's off-screen.
17async function disableAlerts() {
Philipp Schrader817cce32022-03-26 15:00:00 -070018 await browser.executeAsyncScript(function (callback) {
19 let block_alerts = document.getElementById(
20 'block_alerts'
21 ) as HTMLInputElement;
Philipp Schradercf915462022-03-16 23:42:22 -070022 block_alerts.checked = true;
23 callback();
24 });
25}
Philipp Schraderfa096932022-03-05 20:07:10 -080026// Returns the contents of the header that displays the "Auto", "TeleOp", and
27// "Climb" labels etc.
28function getHeadingText() {
29 return element(by.css('.header')).getText();
30}
Philipp Schraderd999c9f2022-02-27 15:48:58 -080031
Philipp Schrader5f190012022-03-15 23:29:09 -070032// Returns the currently displayed progress message on the screen. This only
33// exists on screens where the web page interacts with the web server.
34function getProgressMessage() {
35 return element(by.css('.progress_message')).getText();
36}
37
Philipp Schraderfa096932022-03-05 20:07:10 -080038// Returns the currently displayed error message on the screen. This only
39// exists on screens where the web page interacts with the web server.
40function getErrorMessage() {
41 return element(by.css('.error_message')).getText();
42}
Philipp Schraderd999c9f2022-02-27 15:48:58 -080043
Philipp Schrader8aeb14f2022-04-08 21:23:18 -070044// Returns the currently displayed error message on the screen. This only
45// exists on screens where the web page interacts with the web server.
46function getValueOfInputById(id: string) {
47 return element(by.id(id)).getAttribute('value');
48}
49
Philipp Schraderfa096932022-03-05 20:07:10 -080050// Asserts that the field on the "Submit and Review" screen has a specific
51// value.
52function expectReviewFieldToBe(fieldName: string, expectedValue: string) {
53 return expectNthReviewFieldToBe(fieldName, 0, expectedValue);
54}
55
56// Asserts that the n'th instance of a field on the "Submit and Review"
57// screen has a specific value.
Ravago Jones2813c032022-03-16 23:44:11 -070058async function expectNthReviewFieldToBe(
Philipp Schrader817cce32022-03-26 15:00:00 -070059 fieldName: string,
60 n: number,
61 expectedValue: string
62) {
63 expect(
64 await element
65 .all(by.cssContainingText('li', `${fieldName}:`))
66 .get(n)
67 .getText()
68 ).toEqual(`${fieldName}: ${expectedValue}`);
Philipp Schraderd999c9f2022-02-27 15:48:58 -080069}
70
Philipp Schrader5f190012022-03-15 23:29:09 -070071// Sets a text field to the specified value.
72function setTextboxByIdTo(id: string, value: string) {
73 // Just sending "value" to the input fields is insufficient. We need to
74 // overwrite the text that is there. If we didn't hit CTRL-A to select all
75 // the text, we'd be appending to whatever is there already.
76 return element(by.id(id)).sendKeys(
Philipp Schrader817cce32022-03-26 15:00:00 -070077 protractor.Key.CONTROL,
78 'a',
79 protractor.Key.NULL,
80 value
81 );
Philipp Schrader5f190012022-03-15 23:29:09 -070082}
83
Philipp Schraderfa45d742022-03-18 19:29:05 -070084// Moves the nth slider left or right. A positive "adjustBy" value moves the
85// slider to the right. A negative value moves the slider to the left.
86//
87// negative/left <--- 0 ---> positive/right
88async function adjustNthSliderBy(n: number, adjustBy: number) {
Philipp Schrader5079fa12022-03-19 15:40:12 -070089 const slider = element.all(by.css('input[type=range]')).get(n);
90 const key =
Philipp Schrader817cce32022-03-26 15:00:00 -070091 adjustBy > 0 ? protractor.Key.ARROW_RIGHT : protractor.Key.ARROW_LEFT;
Philipp Schraderfa45d742022-03-18 19:29:05 -070092 for (let i = 0; i < Math.abs(adjustBy); i++) {
93 await slider.sendKeys(key);
94 }
95}
96
Philipp Schraderb99a8cc2022-03-18 21:00:02 -070097function getNthMatchLabel(n: number) {
98 return element.all(by.css('.badge')).get(n).getText();
99}
100
Philipp Schraderd999c9f2022-02-27 15:48:58 -0800101describe('The scouting web page', () => {
Philipp Schradercf915462022-03-16 23:42:22 -0700102 beforeAll(async () => {
103 await browser.get(browser.baseUrl);
Philipp Schrader817cce32022-03-26 15:00:00 -0700104 expect(await browser.getTitle()).toEqual('FRC971 Scouting Application');
Philipp Schradercf915462022-03-16 23:42:22 -0700105 await disableAlerts();
Philipp Schrader5f190012022-03-15 23:29:09 -0700106
107 // Import the match list before running any tests. Ideally this should be
108 // run in beforeEach(), but it's not worth doing that at this time. Our
109 // tests are basic enough not to require this.
Philipp Schrader817cce32022-03-26 15:00:00 -0700110 await element(
111 by.cssContainingText('.nav-link', 'Import Match List')
112 ).click();
Philipp Schrader5f190012022-03-15 23:29:09 -0700113 expect(await getHeadingText()).toEqual('Import Match List');
114 await setTextboxByIdTo('year', '2016');
115 await setTextboxByIdTo('event_code', 'nytr');
116 await element(by.buttonText('Import')).click();
117
Philipp Schrader817cce32022-03-26 15:00:00 -0700118 await browser.wait(
119 EC.textToBePresentInElement(
Ravago Jones2813c032022-03-16 23:44:11 -0700120 element(by.css('.progress_message')),
Philipp Schrader817cce32022-03-26 15:00:00 -0700121 'Successfully imported match list.'
122 )
123 );
Philipp Schradercf915462022-03-16 23:42:22 -0700124 });
125
Philipp Schraderb99a8cc2022-03-18 21:00:02 -0700126 it('should: show matches in chronological order.', async () => {
127 await loadPage();
128
Philipp Schrader8aeb14f2022-04-08 21:23:18 -0700129 expect(await getNthMatchLabel(0)).toEqual('Quals Match 1');
130 expect(await getNthMatchLabel(1)).toEqual('Quals Match 2');
131 expect(await getNthMatchLabel(2)).toEqual('Quals Match 3');
132 expect(await getNthMatchLabel(9)).toEqual('Quals Match 10');
133 expect(await getNthMatchLabel(72)).toEqual('Quarter Final 1 Match 1');
134 expect(await getNthMatchLabel(73)).toEqual('Quarter Final 2 Match 1');
135 expect(await getNthMatchLabel(74)).toEqual('Quarter Final 3 Match 1');
136 expect(await getNthMatchLabel(75)).toEqual('Quarter Final 4 Match 1');
137 expect(await getNthMatchLabel(76)).toEqual('Quarter Final 1 Match 2');
138 expect(await getNthMatchLabel(82)).toEqual('Semi Final 1 Match 1');
139 expect(await getNthMatchLabel(83)).toEqual('Semi Final 2 Match 1');
140 expect(await getNthMatchLabel(84)).toEqual('Semi Final 1 Match 2');
141 expect(await getNthMatchLabel(85)).toEqual('Semi Final 2 Match 2');
142 expect(await getNthMatchLabel(89)).toEqual('Final 1 Match 3');
143 });
144
145 it('should: prefill the match information.', async () => {
146 await loadPage();
147
148 expect(await getHeadingText()).toEqual('Matches');
149
150 // On the 87th row of matches (index 86) click on the second team
151 // (index 1) which resolves to team 5254 in semi final 2 match 3.
152 await element
153 .all(by.css('button.match-item'))
154 .get(86 * 6 + 1)
155 .click();
156
157 expect(await getHeadingText()).toEqual('Team Selection');
158 expect(await getValueOfInputById('match_number')).toEqual('3');
159 expect(await getValueOfInputById('team_number')).toEqual('5254');
160 expect(await getValueOfInputById('round')).toEqual('2');
161 expect(await getValueOfInputById('comp_level')).toEqual('3: sf');
Philipp Schraderb99a8cc2022-03-18 21:00:02 -0700162 });
163
Philipp Schrader5f190012022-03-15 23:29:09 -0700164 it('should: error on unknown match.', async () => {
165 await loadPage();
166
Ravago Jones2813c032022-03-16 23:44:11 -0700167 await element(by.cssContainingText('.nav-link', 'Data Entry')).click();
168
Philipp Schrader5f190012022-03-15 23:29:09 -0700169 // Pick a match that doesn't exist in the 2016nytr match list.
170 await setTextboxByIdTo('match_number', '3');
171 await setTextboxByIdTo('team_number', '971');
172
173 // Click Next until we get to the submit screen.
174 for (let i = 0; i < 5; i++) {
175 await element(by.buttonText('Next')).click();
176 }
177 expect(await getHeadingText()).toEqual('Review and Submit');
178
179 // Attempt to submit and validate the error.
180 await element(by.buttonText('Submit')).click();
Philipp Schrader817cce32022-03-26 15:00:00 -0700181 expect(await getErrorMessage()).toContain(
182 'Failed to find team 971 in match 3 in the schedule.'
183 );
Philipp Schrader5f190012022-03-15 23:29:09 -0700184 });
185
Philipp Schrader5079fa12022-03-19 15:40:12 -0700186 // Make sure that each page on the Entry tab has both "Next" and "Back"
187 // buttons. The only screens exempted from this are the first page and the
188 // last page.
189 it('should: have forwards and backwards buttons.', async () => {
190 await loadPage();
191
192 await element(by.cssContainingText('.nav-link', 'Data Entry')).click();
193
194 const expectedOrder = [
195 'Team Selection',
196 'Auto',
197 'TeleOp',
198 'Climb',
199 'Other',
200 'Review and Submit',
201 ];
202
203 // Go forward through the screens.
204 for (let i = 0; i < expectedOrder.length; i++) {
205 expect(await getHeadingText()).toEqual(expectedOrder[i]);
206 if (i != expectedOrder.length - 1) {
207 await element(by.buttonText('Next')).click();
208 }
209 }
210
211 // Go backwards through the screens.
212 for (let i = 0; i < expectedOrder.length; i++) {
Philipp Schrader817cce32022-03-26 15:00:00 -0700213 expect(await getHeadingText()).toEqual(
214 expectedOrder[expectedOrder.length - i - 1]
215 );
Philipp Schrader5079fa12022-03-19 15:40:12 -0700216 if (i != expectedOrder.length - 1) {
217 await element(by.buttonText('Back')).click();
218 }
219 }
220 });
Philipp Schrader5f190012022-03-15 23:29:09 -0700221
Philipp Schraderfa096932022-03-05 20:07:10 -0800222 it('should: review and submit correct data.', async () => {
Philipp Schrader577befe2022-03-15 00:00:49 -0700223 await loadPage();
Philipp Schraderd999c9f2022-02-27 15:48:58 -0800224
Ravago Jones2813c032022-03-16 23:44:11 -0700225 await element(by.cssContainingText('.nav-link', 'Data Entry')).click();
226
Philipp Schrader5f190012022-03-15 23:29:09 -0700227 // Submit scouting data for a random team that attended 2016nytr.
Philipp Schraderfa096932022-03-05 20:07:10 -0800228 expect(await getHeadingText()).toEqual('Team Selection');
Philipp Schrader5f190012022-03-15 23:29:09 -0700229 await setTextboxByIdTo('match_number', '2');
230 await setTextboxByIdTo('team_number', '5254');
Philipp Schrader8aeb14f2022-04-08 21:23:18 -0700231 await setTextboxByIdTo('round', '42');
232 await element(by.cssContainingText('option', 'Semi Finals')).click();
Philipp Schraderfa096932022-03-05 20:07:10 -0800233 await element(by.buttonText('Next')).click();
Philipp Schraderd999c9f2022-02-27 15:48:58 -0800234
Philipp Schraderfa096932022-03-05 20:07:10 -0800235 expect(await getHeadingText()).toEqual('Auto');
Philipp Schradere7c252d2022-03-17 21:13:47 -0700236 await element(by.id('quadrant3')).click();
Philipp Schraderfa096932022-03-05 20:07:10 -0800237 await element(by.buttonText('Next')).click();
238
239 expect(await getHeadingText()).toEqual('TeleOp');
240 await element(by.buttonText('Next')).click();
241
242 expect(await getHeadingText()).toEqual('Climb');
Philipp Schrader5990fd32022-03-15 21:49:58 -0700243 await element(by.id('high')).click();
Philipp Schrader5079fa12022-03-19 15:40:12 -0700244 await setTextboxByIdTo('comment', 'A very useful comment here.');
Philipp Schraderfa096932022-03-05 20:07:10 -0800245 await element(by.buttonText('Next')).click();
246
Philipp Schradere279e1a2022-03-15 22:20:10 -0700247 expect(await getHeadingText()).toEqual('Other');
Philipp Schraderfa45d742022-03-18 19:29:05 -0700248 await adjustNthSliderBy(0, 3);
249 await adjustNthSliderBy(1, 1);
Philipp Schradere279e1a2022-03-15 22:20:10 -0700250 await element(by.id('no_show')).click();
251 await element(by.id('mechanically_broke')).click();
Philipp Schraderfa096932022-03-05 20:07:10 -0800252 await element(by.buttonText('Next')).click();
253
254 expect(await getHeadingText()).toEqual('Review and Submit');
255 expect(await getErrorMessage()).toEqual('');
256
257 // Validate Team Selection.
Philipp Schrader5f190012022-03-15 23:29:09 -0700258 await expectReviewFieldToBe('Match number', '2');
259 await expectReviewFieldToBe('Team number', '5254');
Philipp Schrader8aeb14f2022-04-08 21:23:18 -0700260 await expectReviewFieldToBe('Round', '42');
261 await expectReviewFieldToBe('Comp Level', 'Semi Finals');
Philipp Schraderfa096932022-03-05 20:07:10 -0800262
263 // Validate Auto.
264 await expectNthReviewFieldToBe('Upper Shots Made', 0, '0');
265 await expectNthReviewFieldToBe('Lower Shots Made', 0, '0');
266 await expectNthReviewFieldToBe('Missed Shots', 0, '0');
Philipp Schradere7c252d2022-03-17 21:13:47 -0700267 await expectReviewFieldToBe('Quadrant', '3');
Philipp Schraderfa096932022-03-05 20:07:10 -0800268
269 // Validate TeleOp.
270 await expectNthReviewFieldToBe('Upper Shots Made', 1, '0');
271 await expectNthReviewFieldToBe('Lower Shots Made', 1, '0');
272 await expectNthReviewFieldToBe('Missed Shots', 1, '0');
273
274 // Validate Climb.
Philipp Schrader8aeb14f2022-04-08 21:23:18 -0700275 await expectReviewFieldToBe('Climb Level', 'High');
Philipp Schraderfa45d742022-03-18 19:29:05 -0700276 await expectReviewFieldToBe('Comments', 'A very useful comment here.');
Philipp Schraderfa096932022-03-05 20:07:10 -0800277
Philipp Schradere279e1a2022-03-15 22:20:10 -0700278 // Validate Other.
Philipp Schraderfa45d742022-03-18 19:29:05 -0700279 await expectReviewFieldToBe('Defense Played On Rating', '3');
280 await expectReviewFieldToBe('Defense Played Rating', '1');
Philipp Schradere279e1a2022-03-15 22:20:10 -0700281 await expectReviewFieldToBe('No show', 'true');
282 await expectReviewFieldToBe('Never moved', 'false');
283 await expectReviewFieldToBe('Battery died', 'false');
284 await expectReviewFieldToBe('Broke (mechanically)', 'true');
Philipp Schraderfa096932022-03-05 20:07:10 -0800285
Philipp Schrader5f190012022-03-15 23:29:09 -0700286 await element(by.buttonText('Submit')).click();
Ravago Jones2813c032022-03-16 23:44:11 -0700287 await browser.wait(
Philipp Schrader817cce32022-03-26 15:00:00 -0700288 EC.textToBePresentInElement(element(by.css('.header')), 'Success')
289 );
Philipp Schrader5f190012022-03-15 23:29:09 -0700290
291 // TODO(phil): Make sure the data made its way to the database correctly.
Philipp Schraderd999c9f2022-02-27 15:48:58 -0800292 });
Philipp Schrader577befe2022-03-15 00:00:49 -0700293
294 it('should: load all images successfully.', async () => {
295 await loadPage();
296
Ravago Jones2813c032022-03-16 23:44:11 -0700297 await element(by.cssContainingText('.nav-link', 'Data Entry')).click();
298
Philipp Schrader577befe2022-03-15 00:00:49 -0700299 // Get to the Auto display with the field pictures.
300 expect(await getHeadingText()).toEqual('Team Selection');
301 await element(by.buttonText('Next')).click();
302 expect(await getHeadingText()).toEqual('Auto');
303
304 // We expect 2 fully loaded images.
Ravago Jones2813c032022-03-16 23:44:11 -0700305 browser
Philipp Schrader817cce32022-03-26 15:00:00 -0700306 .executeAsyncScript(function (callback) {
307 let images = document.getElementsByTagName('img');
308 let numLoaded = 0;
309 for (let i = 0; i < images.length; i += 1) {
310 if (images[i].naturalWidth > 0) {
311 numLoaded += 1;
Ravago Jones2813c032022-03-16 23:44:11 -0700312 }
Philipp Schrader817cce32022-03-26 15:00:00 -0700313 }
314 callback(numLoaded);
315 })
316 .then(function (numLoaded) {
317 expect(numLoaded).toBe(2);
318 });
Philipp Schrader577befe2022-03-15 00:00:49 -0700319 });
Philipp Schraderd999c9f2022-02-27 15:48:58 -0800320});