blob: c3a1c6ee8ec5fe34fbab6008d69dbd5d3447664c [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 Schraderfa096932022-03-05 20:07:10 -08003// Returns the contents of the header that displays the "Auto", "TeleOp", and
4// "Climb" labels etc.
5function getHeadingText() {
6 return element(by.css('.header')).getText();
7}
Philipp Schraderd999c9f2022-02-27 15:48:58 -08008
Philipp Schraderfa096932022-03-05 20:07:10 -08009// Returns the currently displayed error message on the screen. This only
10// exists on screens where the web page interacts with the web server.
11function getErrorMessage() {
12 return element(by.css('.error_message')).getText();
13}
Philipp Schraderd999c9f2022-02-27 15:48:58 -080014
Philipp Schraderfa096932022-03-05 20:07:10 -080015// Asserts that the field on the "Submit and Review" screen has a specific
16// value.
17function expectReviewFieldToBe(fieldName: string, expectedValue: string) {
18 return expectNthReviewFieldToBe(fieldName, 0, expectedValue);
19}
20
21// Asserts that the n'th instance of a field on the "Submit and Review"
22// screen has a specific value.
23async function expectNthReviewFieldToBe(fieldName: string, n: number, expectedValue: string) {
24 expect(await element.all(by.cssContainingText('li', `${fieldName}:`)).get(n).getText())
25 .toEqual(`${fieldName}: ${expectedValue}`);
Philipp Schraderd999c9f2022-02-27 15:48:58 -080026}
27
28describe('The scouting web page', () => {
Philipp Schraderfa096932022-03-05 20:07:10 -080029 it('should: review and submit correct data.', async () => {
30 await browser.get(browser.baseUrl);
Philipp Schraderd999c9f2022-02-27 15:48:58 -080031
Philipp Schraderfa096932022-03-05 20:07:10 -080032 expect(await getHeadingText()).toEqual('Team Selection');
33 // Just sending "971" to the input fields is insufficient. We need to
34 // overwrite the text that is there. If we didn't hit CTRL-A to select all
35 // the text, we'd be appending to whatever is there already.
36 await element(by.id('team_number')).sendKeys(
37 protractor.Key.CONTROL, 'a', protractor.Key.NULL,
38 '971');
39 await element(by.buttonText('Next')).click();
Philipp Schraderd999c9f2022-02-27 15:48:58 -080040
Philipp Schraderfa096932022-03-05 20:07:10 -080041 expect(await getHeadingText()).toEqual('Auto');
42 await element(by.buttonText('Next')).click();
43
44 expect(await getHeadingText()).toEqual('TeleOp');
45 await element(by.buttonText('Next')).click();
46
47 expect(await getHeadingText()).toEqual('Climb');
48 await element(by.buttonText('Next')).click();
49
50 expect(await getHeadingText()).toEqual('Defense');
51 await element(by.buttonText('Next')).click();
52
53 expect(await getHeadingText()).toEqual('Review and Submit');
54 expect(await getErrorMessage()).toEqual('');
55
56 // Validate Team Selection.
57 await expectReviewFieldToBe('Match number', '1');
58 await expectReviewFieldToBe('Team number', '971');
59
60 // Validate Auto.
61 await expectNthReviewFieldToBe('Upper Shots Made', 0, '0');
62 await expectNthReviewFieldToBe('Lower Shots Made', 0, '0');
63 await expectNthReviewFieldToBe('Missed Shots', 0, '0');
64
65 // Validate TeleOp.
66 await expectNthReviewFieldToBe('Upper Shots Made', 1, '0');
67 await expectNthReviewFieldToBe('Lower Shots Made', 1, '0');
68 await expectNthReviewFieldToBe('Missed Shots', 1, '0');
69
70 // Validate Climb.
71 await expectReviewFieldToBe('Attempted to Climb', 'No');
72
73 // Validate Defense.
74 await expectReviewFieldToBe('Defense Played On Rating', '3');
75 await expectReviewFieldToBe('Defense Played Rating', '3');
76
77 // TODO(phil): Submit data and make sure it made its way to the database
78 // correctly. Right now the /requests/submit/data_scouting endpoint is not
79 // implemented.
Philipp Schraderd999c9f2022-02-27 15:48:58 -080080 });
81});