blob: db0c9fd7dcac605e24c1892a9d12d32e48196b91 [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() {
6 await browser.get(browser.baseUrl).catch(function () {
7 return browser.switchTo().alert().then(function (alert) {
8 alert.accept();
9 return browser.get(browser.baseUrl);
10 });
11 });
12}
13
Philipp Schraderfa096932022-03-05 20:07:10 -080014// Returns the contents of the header that displays the "Auto", "TeleOp", and
15// "Climb" labels etc.
16function getHeadingText() {
17 return element(by.css('.header')).getText();
18}
Philipp Schraderd999c9f2022-02-27 15:48:58 -080019
Philipp Schraderfa096932022-03-05 20:07:10 -080020// Returns the currently displayed error message on the screen. This only
21// exists on screens where the web page interacts with the web server.
22function getErrorMessage() {
23 return element(by.css('.error_message')).getText();
24}
Philipp Schraderd999c9f2022-02-27 15:48:58 -080025
Philipp Schraderfa096932022-03-05 20:07:10 -080026// Asserts that the field on the "Submit and Review" screen has a specific
27// value.
28function expectReviewFieldToBe(fieldName: string, expectedValue: string) {
29 return expectNthReviewFieldToBe(fieldName, 0, expectedValue);
30}
31
32// Asserts that the n'th instance of a field on the "Submit and Review"
33// screen has a specific value.
34async function expectNthReviewFieldToBe(fieldName: string, n: number, expectedValue: string) {
35 expect(await element.all(by.cssContainingText('li', `${fieldName}:`)).get(n).getText())
36 .toEqual(`${fieldName}: ${expectedValue}`);
Philipp Schraderd999c9f2022-02-27 15:48:58 -080037}
38
39describe('The scouting web page', () => {
Philipp Schraderfa096932022-03-05 20:07:10 -080040 it('should: review and submit correct data.', async () => {
Philipp Schrader577befe2022-03-15 00:00:49 -070041 await loadPage();
Philipp Schraderd999c9f2022-02-27 15:48:58 -080042
Philipp Schraderfa096932022-03-05 20:07:10 -080043 expect(await getHeadingText()).toEqual('Team Selection');
44 // Just sending "971" to the input fields is insufficient. We need to
45 // overwrite the text that is there. If we didn't hit CTRL-A to select all
46 // the text, we'd be appending to whatever is there already.
47 await element(by.id('team_number')).sendKeys(
48 protractor.Key.CONTROL, 'a', protractor.Key.NULL,
49 '971');
50 await element(by.buttonText('Next')).click();
Philipp Schraderd999c9f2022-02-27 15:48:58 -080051
Philipp Schraderfa096932022-03-05 20:07:10 -080052 expect(await getHeadingText()).toEqual('Auto');
53 await element(by.buttonText('Next')).click();
54
55 expect(await getHeadingText()).toEqual('TeleOp');
56 await element(by.buttonText('Next')).click();
57
58 expect(await getHeadingText()).toEqual('Climb');
Philipp Schrader5990fd32022-03-15 21:49:58 -070059 await element(by.id('high')).click();
Philipp Schraderfa096932022-03-05 20:07:10 -080060 await element(by.buttonText('Next')).click();
61
Philipp Schradere279e1a2022-03-15 22:20:10 -070062 expect(await getHeadingText()).toEqual('Other');
63 await element(by.id('no_show')).click();
64 await element(by.id('mechanically_broke')).click();
Philipp Schraderfa096932022-03-05 20:07:10 -080065 await element(by.buttonText('Next')).click();
66
67 expect(await getHeadingText()).toEqual('Review and Submit');
68 expect(await getErrorMessage()).toEqual('');
69
70 // Validate Team Selection.
71 await expectReviewFieldToBe('Match number', '1');
72 await expectReviewFieldToBe('Team number', '971');
73
74 // Validate Auto.
75 await expectNthReviewFieldToBe('Upper Shots Made', 0, '0');
76 await expectNthReviewFieldToBe('Lower Shots Made', 0, '0');
77 await expectNthReviewFieldToBe('Missed Shots', 0, '0');
78
79 // Validate TeleOp.
80 await expectNthReviewFieldToBe('Upper Shots Made', 1, '0');
81 await expectNthReviewFieldToBe('Lower Shots Made', 1, '0');
82 await expectNthReviewFieldToBe('Missed Shots', 1, '0');
83
84 // Validate Climb.
Philipp Schrader5990fd32022-03-15 21:49:58 -070085 await expectReviewFieldToBe('Level', 'High');
Philipp Schraderfa096932022-03-05 20:07:10 -080086
Philipp Schradere279e1a2022-03-15 22:20:10 -070087 // Validate Other.
Yash Chainani43a81022022-03-12 16:46:47 -080088 await expectReviewFieldToBe('Defense Played On Rating', '0');
89 await expectReviewFieldToBe('Defense Played Rating', '0');
Philipp Schradere279e1a2022-03-15 22:20:10 -070090 await expectReviewFieldToBe('No show', 'true');
91 await expectReviewFieldToBe('Never moved', 'false');
92 await expectReviewFieldToBe('Battery died', 'false');
93 await expectReviewFieldToBe('Broke (mechanically)', 'true');
Philipp Schraderfa096932022-03-05 20:07:10 -080094
95 // TODO(phil): Submit data and make sure it made its way to the database
96 // correctly. Right now the /requests/submit/data_scouting endpoint is not
97 // implemented.
Philipp Schraderd999c9f2022-02-27 15:48:58 -080098 });
Philipp Schrader577befe2022-03-15 00:00:49 -070099
100 it('should: load all images successfully.', async () => {
101 await loadPage();
102
103 // Get to the Auto display with the field pictures.
104 expect(await getHeadingText()).toEqual('Team Selection');
105 await element(by.buttonText('Next')).click();
106 expect(await getHeadingText()).toEqual('Auto');
107
108 // We expect 2 fully loaded images.
109 browser.executeAsyncScript(function (callback) {
110 let images = document.getElementsByTagName('img');
111 let numLoaded = 0;
112 for (let i = 0; i < images.length; i += 1) {
113 if (images[i].naturalWidth > 0) {
114 numLoaded += 1;
115 }
116 }
117 callback(numLoaded);
118 }).then(function (numLoaded) {
119 expect(numLoaded).toBe(2);
120 });
121 });
Philipp Schraderd999c9f2022-02-27 15:48:58 -0800122});