blob: c63251ba98f3bbbb34f0a75c0f969350c559ffbb [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 Schrader577befe2022-03-15 00:00:49 -07003// Loads the page (or reloads it) and deals with the "Are you sure you want to
4// leave this page" popup.
5async function loadPage() {
Philipp Schradercf915462022-03-16 23:42:22 -07006 await disableAlerts();
7 await browser.navigate().refresh();
8 expect((await browser.getTitle())).toEqual('FRC971 Scouting Application');
Philipp Schrader577befe2022-03-15 00:00:49 -07009}
10
Philipp Schradercf915462022-03-16 23:42:22 -070011// Disables alert popups. They are extremely tedious to deal with in
12// Protractor since they're not angular elements. We achieve this by checking
13// an invisible checkbox that's off-screen.
14async function disableAlerts() {
15 await browser.executeAsyncScript(function (callback) {
16 const block_alerts = document.getElementById('block_alerts') as HTMLInputElement;
17 block_alerts.checked = true;
18 callback();
19 });
20}
Philipp Schraderfa096932022-03-05 20:07:10 -080021// Returns the contents of the header that displays the "Auto", "TeleOp", and
22// "Climb" labels etc.
23function getHeadingText() {
24 return element(by.css('.header')).getText();
25}
Philipp Schraderd999c9f2022-02-27 15:48:58 -080026
Philipp Schraderfa096932022-03-05 20:07:10 -080027// Returns the currently displayed error message on the screen. This only
28// exists on screens where the web page interacts with the web server.
29function getErrorMessage() {
30 return element(by.css('.error_message')).getText();
31}
Philipp Schraderd999c9f2022-02-27 15:48:58 -080032
Philipp Schraderfa096932022-03-05 20:07:10 -080033// Asserts that the field on the "Submit and Review" screen has a specific
34// value.
35function expectReviewFieldToBe(fieldName: string, expectedValue: string) {
36 return expectNthReviewFieldToBe(fieldName, 0, expectedValue);
37}
38
39// Asserts that the n'th instance of a field on the "Submit and Review"
40// screen has a specific value.
41async function expectNthReviewFieldToBe(fieldName: string, n: number, expectedValue: string) {
42 expect(await element.all(by.cssContainingText('li', `${fieldName}:`)).get(n).getText())
43 .toEqual(`${fieldName}: ${expectedValue}`);
Philipp Schraderd999c9f2022-02-27 15:48:58 -080044}
45
46describe('The scouting web page', () => {
Philipp Schradercf915462022-03-16 23:42:22 -070047 beforeAll(async () => {
48 await browser.get(browser.baseUrl);
49 expect((await browser.getTitle())).toEqual('FRC971 Scouting Application');
50 await disableAlerts();
51 });
52
Philipp Schraderfa096932022-03-05 20:07:10 -080053 it('should: review and submit correct data.', async () => {
Philipp Schrader577befe2022-03-15 00:00:49 -070054 await loadPage();
Philipp Schraderd999c9f2022-02-27 15:48:58 -080055
Philipp Schraderfa096932022-03-05 20:07:10 -080056 expect(await getHeadingText()).toEqual('Team Selection');
57 // Just sending "971" to the input fields is insufficient. We need to
58 // overwrite the text that is there. If we didn't hit CTRL-A to select all
59 // the text, we'd be appending to whatever is there already.
60 await element(by.id('team_number')).sendKeys(
61 protractor.Key.CONTROL, 'a', protractor.Key.NULL,
62 '971');
63 await element(by.buttonText('Next')).click();
Philipp Schraderd999c9f2022-02-27 15:48:58 -080064
Philipp Schraderfa096932022-03-05 20:07:10 -080065 expect(await getHeadingText()).toEqual('Auto');
66 await element(by.buttonText('Next')).click();
67
68 expect(await getHeadingText()).toEqual('TeleOp');
69 await element(by.buttonText('Next')).click();
70
71 expect(await getHeadingText()).toEqual('Climb');
Philipp Schrader5990fd32022-03-15 21:49:58 -070072 await element(by.id('high')).click();
Philipp Schraderfa096932022-03-05 20:07:10 -080073 await element(by.buttonText('Next')).click();
74
Philipp Schradere279e1a2022-03-15 22:20:10 -070075 expect(await getHeadingText()).toEqual('Other');
76 await element(by.id('no_show')).click();
77 await element(by.id('mechanically_broke')).click();
Philipp Schraderfa096932022-03-05 20:07:10 -080078 await element(by.buttonText('Next')).click();
79
80 expect(await getHeadingText()).toEqual('Review and Submit');
81 expect(await getErrorMessage()).toEqual('');
82
83 // Validate Team Selection.
84 await expectReviewFieldToBe('Match number', '1');
85 await expectReviewFieldToBe('Team number', '971');
86
87 // Validate Auto.
88 await expectNthReviewFieldToBe('Upper Shots Made', 0, '0');
89 await expectNthReviewFieldToBe('Lower Shots Made', 0, '0');
90 await expectNthReviewFieldToBe('Missed Shots', 0, '0');
91
92 // Validate TeleOp.
93 await expectNthReviewFieldToBe('Upper Shots Made', 1, '0');
94 await expectNthReviewFieldToBe('Lower Shots Made', 1, '0');
95 await expectNthReviewFieldToBe('Missed Shots', 1, '0');
96
97 // Validate Climb.
Philipp Schrader5990fd32022-03-15 21:49:58 -070098 await expectReviewFieldToBe('Level', 'High');
Philipp Schraderfa096932022-03-05 20:07:10 -080099
Philipp Schradere279e1a2022-03-15 22:20:10 -0700100 // Validate Other.
Yash Chainani43a81022022-03-12 16:46:47 -0800101 await expectReviewFieldToBe('Defense Played On Rating', '0');
102 await expectReviewFieldToBe('Defense Played Rating', '0');
Philipp Schradere279e1a2022-03-15 22:20:10 -0700103 await expectReviewFieldToBe('No show', 'true');
104 await expectReviewFieldToBe('Never moved', 'false');
105 await expectReviewFieldToBe('Battery died', 'false');
106 await expectReviewFieldToBe('Broke (mechanically)', 'true');
Philipp Schraderfa096932022-03-05 20:07:10 -0800107
108 // TODO(phil): Submit data and make sure it made its way to the database
109 // correctly. Right now the /requests/submit/data_scouting endpoint is not
110 // implemented.
Philipp Schraderd999c9f2022-02-27 15:48:58 -0800111 });
Philipp Schrader577befe2022-03-15 00:00:49 -0700112
113 it('should: load all images successfully.', async () => {
114 await loadPage();
115
116 // Get to the Auto display with the field pictures.
117 expect(await getHeadingText()).toEqual('Team Selection');
118 await element(by.buttonText('Next')).click();
119 expect(await getHeadingText()).toEqual('Auto');
120
121 // We expect 2 fully loaded images.
122 browser.executeAsyncScript(function (callback) {
123 let images = document.getElementsByTagName('img');
124 let numLoaded = 0;
125 for (let i = 0; i < images.length; i += 1) {
126 if (images[i].naturalWidth > 0) {
127 numLoaded += 1;
128 }
129 }
130 callback(numLoaded);
131 }).then(function (numLoaded) {
132 expect(numLoaded).toBe(2);
133 });
134 });
Philipp Schraderd999c9f2022-02-27 15:48:58 -0800135});