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 | 577befe | 2022-03-15 00:00:49 -0700 | [diff] [blame^] | 3 | // Loads the page (or reloads it) and deals with the "Are you sure you want to |
| 4 | // leave this page" popup. |
| 5 | async 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 Schrader | fa09693 | 2022-03-05 20:07:10 -0800 | [diff] [blame] | 14 | // Returns the contents of the header that displays the "Auto", "TeleOp", and |
| 15 | // "Climb" labels etc. |
| 16 | function getHeadingText() { |
| 17 | return element(by.css('.header')).getText(); |
| 18 | } |
Philipp Schrader | d999c9f | 2022-02-27 15:48:58 -0800 | [diff] [blame] | 19 | |
Philipp Schrader | fa09693 | 2022-03-05 20:07:10 -0800 | [diff] [blame] | 20 | // Returns the currently displayed error message on the screen. This only |
| 21 | // exists on screens where the web page interacts with the web server. |
| 22 | function getErrorMessage() { |
| 23 | return element(by.css('.error_message')).getText(); |
| 24 | } |
Philipp Schrader | d999c9f | 2022-02-27 15:48:58 -0800 | [diff] [blame] | 25 | |
Philipp Schrader | fa09693 | 2022-03-05 20:07:10 -0800 | [diff] [blame] | 26 | // Asserts that the field on the "Submit and Review" screen has a specific |
| 27 | // value. |
| 28 | function 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. |
| 34 | async 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 Schrader | d999c9f | 2022-02-27 15:48:58 -0800 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | describe('The scouting web page', () => { |
Philipp Schrader | fa09693 | 2022-03-05 20:07:10 -0800 | [diff] [blame] | 40 | it('should: review and submit correct data.', async () => { |
Philipp Schrader | 577befe | 2022-03-15 00:00:49 -0700 | [diff] [blame^] | 41 | await loadPage(); |
Philipp Schrader | d999c9f | 2022-02-27 15:48:58 -0800 | [diff] [blame] | 42 | |
Philipp Schrader | fa09693 | 2022-03-05 20:07:10 -0800 | [diff] [blame] | 43 | 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 Schrader | d999c9f | 2022-02-27 15:48:58 -0800 | [diff] [blame] | 51 | |
Philipp Schrader | fa09693 | 2022-03-05 20:07:10 -0800 | [diff] [blame] | 52 | 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 Chainani | 43a8102 | 2022-03-12 16:46:47 -0800 | [diff] [blame] | 85 | await expectReviewFieldToBe('Defense Played On Rating', '0'); |
| 86 | await expectReviewFieldToBe('Defense Played Rating', '0'); |
Philipp Schrader | fa09693 | 2022-03-05 20:07:10 -0800 | [diff] [blame] | 87 | |
| 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 Schrader | d999c9f | 2022-02-27 15:48:58 -0800 | [diff] [blame] | 91 | }); |
Philipp Schrader | 577befe | 2022-03-15 00:00:49 -0700 | [diff] [blame^] | 92 | |
| 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 Schrader | d999c9f | 2022-02-27 15:48:58 -0800 | [diff] [blame] | 115 | }); |