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() { |
Philipp Schrader | cf91546 | 2022-03-16 23:42:22 -0700 | [diff] [blame^] | 6 | await disableAlerts(); |
| 7 | await browser.navigate().refresh(); |
| 8 | expect((await browser.getTitle())).toEqual('FRC971 Scouting Application'); |
Philipp Schrader | 577befe | 2022-03-15 00:00:49 -0700 | [diff] [blame] | 9 | } |
| 10 | |
Philipp Schrader | cf91546 | 2022-03-16 23:42:22 -0700 | [diff] [blame^] | 11 | // Disables alert popups. They are extremely tedious to deal with in |
| 12 | // Protractor since they're not angular elements. We achieve this by checking |
| 13 | // an invisible checkbox that's off-screen. |
| 14 | async function disableAlerts() { |
| 15 | await browser.executeAsyncScript(function (callback) { |
| 16 | const block_alerts = document.getElementById('block_alerts') as HTMLInputElement; |
| 17 | block_alerts.checked = true; |
| 18 | callback(); |
| 19 | }); |
| 20 | } |
Philipp Schrader | fa09693 | 2022-03-05 20:07:10 -0800 | [diff] [blame] | 21 | // Returns the contents of the header that displays the "Auto", "TeleOp", and |
| 22 | // "Climb" labels etc. |
| 23 | function getHeadingText() { |
| 24 | return element(by.css('.header')).getText(); |
| 25 | } |
Philipp Schrader | d999c9f | 2022-02-27 15:48:58 -0800 | [diff] [blame] | 26 | |
Philipp Schrader | fa09693 | 2022-03-05 20:07:10 -0800 | [diff] [blame] | 27 | // Returns the currently displayed error message on the screen. This only |
| 28 | // exists on screens where the web page interacts with the web server. |
| 29 | function getErrorMessage() { |
| 30 | return element(by.css('.error_message')).getText(); |
| 31 | } |
Philipp Schrader | d999c9f | 2022-02-27 15:48:58 -0800 | [diff] [blame] | 32 | |
Philipp Schrader | fa09693 | 2022-03-05 20:07:10 -0800 | [diff] [blame] | 33 | // Asserts that the field on the "Submit and Review" screen has a specific |
| 34 | // value. |
| 35 | function expectReviewFieldToBe(fieldName: string, expectedValue: string) { |
| 36 | return expectNthReviewFieldToBe(fieldName, 0, expectedValue); |
| 37 | } |
| 38 | |
| 39 | // Asserts that the n'th instance of a field on the "Submit and Review" |
| 40 | // screen has a specific value. |
| 41 | async function expectNthReviewFieldToBe(fieldName: string, n: number, expectedValue: string) { |
| 42 | expect(await element.all(by.cssContainingText('li', `${fieldName}:`)).get(n).getText()) |
| 43 | .toEqual(`${fieldName}: ${expectedValue}`); |
Philipp Schrader | d999c9f | 2022-02-27 15:48:58 -0800 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | describe('The scouting web page', () => { |
Philipp Schrader | cf91546 | 2022-03-16 23:42:22 -0700 | [diff] [blame^] | 47 | beforeAll(async () => { |
| 48 | await browser.get(browser.baseUrl); |
| 49 | expect((await browser.getTitle())).toEqual('FRC971 Scouting Application'); |
| 50 | await disableAlerts(); |
| 51 | }); |
| 52 | |
Philipp Schrader | fa09693 | 2022-03-05 20:07:10 -0800 | [diff] [blame] | 53 | it('should: review and submit correct data.', async () => { |
Philipp Schrader | 577befe | 2022-03-15 00:00:49 -0700 | [diff] [blame] | 54 | await loadPage(); |
Philipp Schrader | d999c9f | 2022-02-27 15:48:58 -0800 | [diff] [blame] | 55 | |
Philipp Schrader | fa09693 | 2022-03-05 20:07:10 -0800 | [diff] [blame] | 56 | expect(await getHeadingText()).toEqual('Team Selection'); |
| 57 | // Just sending "971" to the input fields is insufficient. We need to |
| 58 | // overwrite the text that is there. If we didn't hit CTRL-A to select all |
| 59 | // the text, we'd be appending to whatever is there already. |
| 60 | await element(by.id('team_number')).sendKeys( |
| 61 | protractor.Key.CONTROL, 'a', protractor.Key.NULL, |
| 62 | '971'); |
| 63 | await element(by.buttonText('Next')).click(); |
Philipp Schrader | d999c9f | 2022-02-27 15:48:58 -0800 | [diff] [blame] | 64 | |
Philipp Schrader | fa09693 | 2022-03-05 20:07:10 -0800 | [diff] [blame] | 65 | expect(await getHeadingText()).toEqual('Auto'); |
| 66 | await element(by.buttonText('Next')).click(); |
| 67 | |
| 68 | expect(await getHeadingText()).toEqual('TeleOp'); |
| 69 | await element(by.buttonText('Next')).click(); |
| 70 | |
| 71 | expect(await getHeadingText()).toEqual('Climb'); |
Philipp Schrader | 5990fd3 | 2022-03-15 21:49:58 -0700 | [diff] [blame] | 72 | await element(by.id('high')).click(); |
Philipp Schrader | fa09693 | 2022-03-05 20:07:10 -0800 | [diff] [blame] | 73 | await element(by.buttonText('Next')).click(); |
| 74 | |
Philipp Schrader | e279e1a | 2022-03-15 22:20:10 -0700 | [diff] [blame] | 75 | expect(await getHeadingText()).toEqual('Other'); |
| 76 | await element(by.id('no_show')).click(); |
| 77 | await element(by.id('mechanically_broke')).click(); |
Philipp Schrader | fa09693 | 2022-03-05 20:07:10 -0800 | [diff] [blame] | 78 | await element(by.buttonText('Next')).click(); |
| 79 | |
| 80 | expect(await getHeadingText()).toEqual('Review and Submit'); |
| 81 | expect(await getErrorMessage()).toEqual(''); |
| 82 | |
| 83 | // Validate Team Selection. |
| 84 | await expectReviewFieldToBe('Match number', '1'); |
| 85 | await expectReviewFieldToBe('Team number', '971'); |
| 86 | |
| 87 | // Validate Auto. |
| 88 | await expectNthReviewFieldToBe('Upper Shots Made', 0, '0'); |
| 89 | await expectNthReviewFieldToBe('Lower Shots Made', 0, '0'); |
| 90 | await expectNthReviewFieldToBe('Missed Shots', 0, '0'); |
| 91 | |
| 92 | // Validate TeleOp. |
| 93 | await expectNthReviewFieldToBe('Upper Shots Made', 1, '0'); |
| 94 | await expectNthReviewFieldToBe('Lower Shots Made', 1, '0'); |
| 95 | await expectNthReviewFieldToBe('Missed Shots', 1, '0'); |
| 96 | |
| 97 | // Validate Climb. |
Philipp Schrader | 5990fd3 | 2022-03-15 21:49:58 -0700 | [diff] [blame] | 98 | await expectReviewFieldToBe('Level', 'High'); |
Philipp Schrader | fa09693 | 2022-03-05 20:07:10 -0800 | [diff] [blame] | 99 | |
Philipp Schrader | e279e1a | 2022-03-15 22:20:10 -0700 | [diff] [blame] | 100 | // Validate Other. |
Yash Chainani | 43a8102 | 2022-03-12 16:46:47 -0800 | [diff] [blame] | 101 | await expectReviewFieldToBe('Defense Played On Rating', '0'); |
| 102 | await expectReviewFieldToBe('Defense Played Rating', '0'); |
Philipp Schrader | e279e1a | 2022-03-15 22:20:10 -0700 | [diff] [blame] | 103 | await expectReviewFieldToBe('No show', 'true'); |
| 104 | await expectReviewFieldToBe('Never moved', 'false'); |
| 105 | await expectReviewFieldToBe('Battery died', 'false'); |
| 106 | await expectReviewFieldToBe('Broke (mechanically)', 'true'); |
Philipp Schrader | fa09693 | 2022-03-05 20:07:10 -0800 | [diff] [blame] | 107 | |
| 108 | // TODO(phil): Submit data and make sure it made its way to the database |
| 109 | // correctly. Right now the /requests/submit/data_scouting endpoint is not |
| 110 | // implemented. |
Philipp Schrader | d999c9f | 2022-02-27 15:48:58 -0800 | [diff] [blame] | 111 | }); |
Philipp Schrader | 577befe | 2022-03-15 00:00:49 -0700 | [diff] [blame] | 112 | |
| 113 | it('should: load all images successfully.', async () => { |
| 114 | await loadPage(); |
| 115 | |
| 116 | // Get to the Auto display with the field pictures. |
| 117 | expect(await getHeadingText()).toEqual('Team Selection'); |
| 118 | await element(by.buttonText('Next')).click(); |
| 119 | expect(await getHeadingText()).toEqual('Auto'); |
| 120 | |
| 121 | // We expect 2 fully loaded images. |
| 122 | browser.executeAsyncScript(function (callback) { |
| 123 | let images = document.getElementsByTagName('img'); |
| 124 | let numLoaded = 0; |
| 125 | for (let i = 0; i < images.length; i += 1) { |
| 126 | if (images[i].naturalWidth > 0) { |
| 127 | numLoaded += 1; |
| 128 | } |
| 129 | } |
| 130 | callback(numLoaded); |
| 131 | }).then(function (numLoaded) { |
| 132 | expect(numLoaded).toBe(2); |
| 133 | }); |
| 134 | }); |
Philipp Schrader | d999c9f | 2022-02-27 15:48:58 -0800 | [diff] [blame] | 135 | }); |