blob: 84824ffec1d37c0379d66d5dfbcb0e87575f8f70 [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();
10 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() {
Ravago Jones2813c032022-03-16 23:44:11 -070018 await browser.executeAsyncScript(function(callback) {
19 let block_alerts =
20 document.getElementById('block_alerts') as HTMLInputElement;
Philipp Schradercf915462022-03-16 23:42:22 -070021 block_alerts.checked = true;
22 callback();
23 });
24}
Philipp Schraderfa096932022-03-05 20:07:10 -080025// Returns the contents of the header that displays the "Auto", "TeleOp", and
26// "Climb" labels etc.
27function getHeadingText() {
28 return element(by.css('.header')).getText();
29}
Philipp Schraderd999c9f2022-02-27 15:48:58 -080030
Philipp Schrader5f190012022-03-15 23:29:09 -070031// Returns the currently displayed progress message on the screen. This only
32// exists on screens where the web page interacts with the web server.
33function getProgressMessage() {
34 return element(by.css('.progress_message')).getText();
35}
36
Philipp Schraderfa096932022-03-05 20:07:10 -080037// Returns the currently displayed error message on the screen. This only
38// exists on screens where the web page interacts with the web server.
39function getErrorMessage() {
40 return element(by.css('.error_message')).getText();
41}
Philipp Schraderd999c9f2022-02-27 15:48:58 -080042
Philipp Schraderfa096932022-03-05 20:07:10 -080043// Asserts that the field on the "Submit and Review" screen has a specific
44// value.
45function expectReviewFieldToBe(fieldName: string, expectedValue: string) {
46 return expectNthReviewFieldToBe(fieldName, 0, expectedValue);
47}
48
49// Asserts that the n'th instance of a field on the "Submit and Review"
50// screen has a specific value.
Ravago Jones2813c032022-03-16 23:44:11 -070051async function expectNthReviewFieldToBe(
52 fieldName: string, n: number, expectedValue: string) {
53 expect(await element.all(by.cssContainingText('li', `${fieldName}:`))
54 .get(n)
55 .getText())
Philipp Schraderfa096932022-03-05 20:07:10 -080056 .toEqual(`${fieldName}: ${expectedValue}`);
Philipp Schraderd999c9f2022-02-27 15:48:58 -080057}
58
Philipp Schrader5f190012022-03-15 23:29:09 -070059// Sets a text field to the specified value.
60function setTextboxByIdTo(id: string, value: string) {
61 // Just sending "value" to the input fields is insufficient. We need to
62 // overwrite the text that is there. If we didn't hit CTRL-A to select all
63 // the text, we'd be appending to whatever is there already.
64 return element(by.id(id)).sendKeys(
Ravago Jones2813c032022-03-16 23:44:11 -070065 protractor.Key.CONTROL, 'a', protractor.Key.NULL, value);
Philipp Schrader5f190012022-03-15 23:29:09 -070066}
67
Philipp Schraderd999c9f2022-02-27 15:48:58 -080068describe('The scouting web page', () => {
Philipp Schradercf915462022-03-16 23:42:22 -070069 beforeAll(async () => {
70 await browser.get(browser.baseUrl);
71 expect((await browser.getTitle())).toEqual('FRC971 Scouting Application');
72 await disableAlerts();
Philipp Schrader5f190012022-03-15 23:29:09 -070073
74 // Import the match list before running any tests. Ideally this should be
75 // run in beforeEach(), but it's not worth doing that at this time. Our
76 // tests are basic enough not to require this.
Ravago Jones2813c032022-03-16 23:44:11 -070077 await element(by.cssContainingText('.nav-link', 'Import Match List'))
78 .click();
Philipp Schrader5f190012022-03-15 23:29:09 -070079 expect(await getHeadingText()).toEqual('Import Match List');
80 await setTextboxByIdTo('year', '2016');
81 await setTextboxByIdTo('event_code', 'nytr');
82 await element(by.buttonText('Import')).click();
83
84 await browser.wait(EC.textToBePresentInElement(
Ravago Jones2813c032022-03-16 23:44:11 -070085 element(by.css('.progress_message')),
86 'Successfully imported match list.'));
Philipp Schradercf915462022-03-16 23:42:22 -070087 });
88
Philipp Schrader5f190012022-03-15 23:29:09 -070089 it('should: error on unknown match.', async () => {
90 await loadPage();
91
Ravago Jones2813c032022-03-16 23:44:11 -070092 await element(by.cssContainingText('.nav-link', 'Data Entry')).click();
93
Philipp Schrader5f190012022-03-15 23:29:09 -070094 // Pick a match that doesn't exist in the 2016nytr match list.
95 await setTextboxByIdTo('match_number', '3');
96 await setTextboxByIdTo('team_number', '971');
97
98 // Click Next until we get to the submit screen.
99 for (let i = 0; i < 5; i++) {
100 await element(by.buttonText('Next')).click();
101 }
102 expect(await getHeadingText()).toEqual('Review and Submit');
103
104 // Attempt to submit and validate the error.
105 await element(by.buttonText('Submit')).click();
Ravago Jones2813c032022-03-16 23:44:11 -0700106 expect(await getErrorMessage())
107 .toContain('Failed to find team 971 in match 3 in the schedule.');
Philipp Schrader5f190012022-03-15 23:29:09 -0700108 });
109
110
Philipp Schraderfa096932022-03-05 20:07:10 -0800111 it('should: review and submit correct data.', async () => {
Philipp Schrader577befe2022-03-15 00:00:49 -0700112 await loadPage();
Philipp Schraderd999c9f2022-02-27 15:48:58 -0800113
Ravago Jones2813c032022-03-16 23:44:11 -0700114 await element(by.cssContainingText('.nav-link', 'Data Entry')).click();
115
Philipp Schrader5f190012022-03-15 23:29:09 -0700116 // Submit scouting data for a random team that attended 2016nytr.
Philipp Schraderfa096932022-03-05 20:07:10 -0800117 expect(await getHeadingText()).toEqual('Team Selection');
Philipp Schrader5f190012022-03-15 23:29:09 -0700118 await setTextboxByIdTo('match_number', '2');
119 await setTextboxByIdTo('team_number', '5254');
Philipp Schraderfa096932022-03-05 20:07:10 -0800120 await element(by.buttonText('Next')).click();
Philipp Schraderd999c9f2022-02-27 15:48:58 -0800121
Philipp Schraderfa096932022-03-05 20:07:10 -0800122 expect(await getHeadingText()).toEqual('Auto');
Philipp Schradere7c252d2022-03-17 21:13:47 -0700123 await element(by.id('quadrant3')).click();
Philipp Schraderfa096932022-03-05 20:07:10 -0800124 await element(by.buttonText('Next')).click();
125
126 expect(await getHeadingText()).toEqual('TeleOp');
127 await element(by.buttonText('Next')).click();
128
129 expect(await getHeadingText()).toEqual('Climb');
Philipp Schrader5990fd32022-03-15 21:49:58 -0700130 await element(by.id('high')).click();
Philipp Schraderfa096932022-03-05 20:07:10 -0800131 await element(by.buttonText('Next')).click();
132
Philipp Schradere279e1a2022-03-15 22:20:10 -0700133 expect(await getHeadingText()).toEqual('Other');
134 await element(by.id('no_show')).click();
135 await element(by.id('mechanically_broke')).click();
Philipp Schraderfa096932022-03-05 20:07:10 -0800136 await element(by.buttonText('Next')).click();
137
138 expect(await getHeadingText()).toEqual('Review and Submit');
139 expect(await getErrorMessage()).toEqual('');
140
141 // Validate Team Selection.
Philipp Schrader5f190012022-03-15 23:29:09 -0700142 await expectReviewFieldToBe('Match number', '2');
143 await expectReviewFieldToBe('Team number', '5254');
Philipp Schraderfa096932022-03-05 20:07:10 -0800144
145 // Validate Auto.
146 await expectNthReviewFieldToBe('Upper Shots Made', 0, '0');
147 await expectNthReviewFieldToBe('Lower Shots Made', 0, '0');
148 await expectNthReviewFieldToBe('Missed Shots', 0, '0');
Philipp Schradere7c252d2022-03-17 21:13:47 -0700149 await expectReviewFieldToBe('Quadrant', '3');
Philipp Schraderfa096932022-03-05 20:07:10 -0800150
151 // Validate TeleOp.
152 await expectNthReviewFieldToBe('Upper Shots Made', 1, '0');
153 await expectNthReviewFieldToBe('Lower Shots Made', 1, '0');
154 await expectNthReviewFieldToBe('Missed Shots', 1, '0');
155
156 // Validate Climb.
Philipp Schrader5990fd32022-03-15 21:49:58 -0700157 await expectReviewFieldToBe('Level', 'High');
Philipp Schraderfa096932022-03-05 20:07:10 -0800158
Philipp Schradere279e1a2022-03-15 22:20:10 -0700159 // Validate Other.
Yash Chainani43a81022022-03-12 16:46:47 -0800160 await expectReviewFieldToBe('Defense Played On Rating', '0');
161 await expectReviewFieldToBe('Defense Played Rating', '0');
Philipp Schradere279e1a2022-03-15 22:20:10 -0700162 await expectReviewFieldToBe('No show', 'true');
163 await expectReviewFieldToBe('Never moved', 'false');
164 await expectReviewFieldToBe('Battery died', 'false');
165 await expectReviewFieldToBe('Broke (mechanically)', 'true');
Philipp Schraderfa096932022-03-05 20:07:10 -0800166
Philipp Schrader5f190012022-03-15 23:29:09 -0700167 await element(by.buttonText('Submit')).click();
Ravago Jones2813c032022-03-16 23:44:11 -0700168 await browser.wait(
169 EC.textToBePresentInElement(element(by.css('.header')), 'Success'));
Philipp Schrader5f190012022-03-15 23:29:09 -0700170
171 // TODO(phil): Make sure the data made its way to the database correctly.
Philipp Schraderd999c9f2022-02-27 15:48:58 -0800172 });
Philipp Schrader577befe2022-03-15 00:00:49 -0700173
174 it('should: load all images successfully.', async () => {
175 await loadPage();
176
Ravago Jones2813c032022-03-16 23:44:11 -0700177 await element(by.cssContainingText('.nav-link', 'Data Entry')).click();
178
Philipp Schrader577befe2022-03-15 00:00:49 -0700179 // Get to the Auto display with the field pictures.
180 expect(await getHeadingText()).toEqual('Team Selection');
181 await element(by.buttonText('Next')).click();
182 expect(await getHeadingText()).toEqual('Auto');
183
184 // We expect 2 fully loaded images.
Ravago Jones2813c032022-03-16 23:44:11 -0700185 browser
186 .executeAsyncScript(function(callback) {
187 let images = document.getElementsByTagName('img');
188 let numLoaded = 0;
189 for (let i = 0; i < images.length; i += 1) {
190 if (images[i].naturalWidth > 0) {
191 numLoaded += 1;
192 }
193 }
194 callback(numLoaded);
195 })
196 .then(function(numLoaded) {
197 expect(numLoaded).toBe(2);
198 });
Philipp Schrader577befe2022-03-15 00:00:49 -0700199 });
Philipp Schraderd999c9f2022-02-27 15:48:58 -0800200});