Philipp Schrader | fa09693 | 2022-03-05 20:07:10 -0800 | [diff] [blame^] | 1 | import {browser, by, element, protractor} from 'protractor'; |
Philipp Schrader | d999c9f | 2022-02-27 15:48:58 -0800 | [diff] [blame] | 2 | |
Philipp Schrader | fa09693 | 2022-03-05 20:07:10 -0800 | [diff] [blame^] | 3 | // Returns the contents of the header that displays the "Auto", "TeleOp", and |
| 4 | // "Climb" labels etc. |
| 5 | function getHeadingText() { |
| 6 | return element(by.css('.header')).getText(); |
| 7 | } |
Philipp Schrader | d999c9f | 2022-02-27 15:48:58 -0800 | [diff] [blame] | 8 | |
Philipp Schrader | fa09693 | 2022-03-05 20:07:10 -0800 | [diff] [blame^] | 9 | // Returns the currently displayed error message on the screen. This only |
| 10 | // exists on screens where the web page interacts with the web server. |
| 11 | function getErrorMessage() { |
| 12 | return element(by.css('.error_message')).getText(); |
| 13 | } |
Philipp Schrader | d999c9f | 2022-02-27 15:48:58 -0800 | [diff] [blame] | 14 | |
Philipp Schrader | fa09693 | 2022-03-05 20:07:10 -0800 | [diff] [blame^] | 15 | // Asserts that the field on the "Submit and Review" screen has a specific |
| 16 | // value. |
| 17 | function 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. |
| 23 | async 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 Schrader | d999c9f | 2022-02-27 15:48:58 -0800 | [diff] [blame] | 26 | } |
| 27 | |
| 28 | describe('The scouting web page', () => { |
Philipp Schrader | fa09693 | 2022-03-05 20:07:10 -0800 | [diff] [blame^] | 29 | it('should: review and submit correct data.', async () => { |
| 30 | await browser.get(browser.baseUrl); |
Philipp Schrader | d999c9f | 2022-02-27 15:48:58 -0800 | [diff] [blame] | 31 | |
Philipp Schrader | fa09693 | 2022-03-05 20:07:10 -0800 | [diff] [blame^] | 32 | 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 Schrader | d999c9f | 2022-02-27 15:48:58 -0800 | [diff] [blame] | 40 | |
Philipp Schrader | fa09693 | 2022-03-05 20:07:10 -0800 | [diff] [blame^] | 41 | 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 Schrader | d999c9f | 2022-02-27 15:48:58 -0800 | [diff] [blame] | 80 | }); |
| 81 | }); |