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