blob: 2ffa13681244a5ec50540329eb1a044e12cf78dd [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');
59 await element(by.buttonText('Next')).click();
60
61 expect(await getHeadingText()).toEqual('Defense');
62 await element(by.buttonText('Next')).click();
63
64 expect(await getHeadingText()).toEqual('Review and Submit');
65 expect(await getErrorMessage()).toEqual('');
66
67 // Validate Team Selection.
68 await expectReviewFieldToBe('Match number', '1');
69 await expectReviewFieldToBe('Team number', '971');
70
71 // Validate Auto.
72 await expectNthReviewFieldToBe('Upper Shots Made', 0, '0');
73 await expectNthReviewFieldToBe('Lower Shots Made', 0, '0');
74 await expectNthReviewFieldToBe('Missed Shots', 0, '0');
75
76 // Validate TeleOp.
77 await expectNthReviewFieldToBe('Upper Shots Made', 1, '0');
78 await expectNthReviewFieldToBe('Lower Shots Made', 1, '0');
79 await expectNthReviewFieldToBe('Missed Shots', 1, '0');
80
81 // Validate Climb.
82 await expectReviewFieldToBe('Attempted to Climb', 'No');
83
84 // Validate Defense.
Yash Chainani43a81022022-03-12 16:46:47 -080085 await expectReviewFieldToBe('Defense Played On Rating', '0');
86 await expectReviewFieldToBe('Defense Played Rating', '0');
Philipp Schraderfa096932022-03-05 20:07:10 -080087
88 // TODO(phil): Submit data and make sure it made its way to the database
89 // correctly. Right now the /requests/submit/data_scouting endpoint is not
90 // implemented.
Philipp Schraderd999c9f2022-02-27 15:48:58 -080091 });
Philipp Schrader577befe2022-03-15 00:00:49 -070092
93 it('should: load all images successfully.', async () => {
94 await loadPage();
95
96 // Get to the Auto display with the field pictures.
97 expect(await getHeadingText()).toEqual('Team Selection');
98 await element(by.buttonText('Next')).click();
99 expect(await getHeadingText()).toEqual('Auto');
100
101 // We expect 2 fully loaded images.
102 browser.executeAsyncScript(function (callback) {
103 let images = document.getElementsByTagName('img');
104 let numLoaded = 0;
105 for (let i = 0; i < images.length; i += 1) {
106 if (images[i].naturalWidth > 0) {
107 numLoaded += 1;
108 }
109 }
110 callback(numLoaded);
111 }).then(function (numLoaded) {
112 expect(numLoaded).toBe(2);
113 });
114 });
Philipp Schraderd999c9f2022-02-27 15:48:58 -0800115});