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 | 5f19001 | 2022-03-15 23:29:09 -0700 | [diff] [blame] | 3 | const EC = protractor.ExpectedConditions; |
| 4 | |
Philipp Schrader | 577befe | 2022-03-15 00:00:49 -0700 | [diff] [blame] | 5 | // Loads the page (or reloads it) and deals with the "Are you sure you want to |
| 6 | // leave this page" popup. |
| 7 | async function loadPage() { |
Philipp Schrader | cf91546 | 2022-03-16 23:42:22 -0700 | [diff] [blame] | 8 | await disableAlerts(); |
| 9 | await browser.navigate().refresh(); |
| 10 | expect((await browser.getTitle())).toEqual('FRC971 Scouting Application'); |
Philipp Schrader | 5f19001 | 2022-03-15 23:29:09 -0700 | [diff] [blame] | 11 | await disableAlerts(); |
Philipp Schrader | 577befe | 2022-03-15 00:00:49 -0700 | [diff] [blame] | 12 | } |
| 13 | |
Philipp Schrader | cf91546 | 2022-03-16 23:42:22 -0700 | [diff] [blame] | 14 | // Disables alert popups. They are extremely tedious to deal with in |
| 15 | // Protractor since they're not angular elements. We achieve this by checking |
| 16 | // an invisible checkbox that's off-screen. |
| 17 | async function disableAlerts() { |
Ravago Jones | 2813c03 | 2022-03-16 23:44:11 -0700 | [diff] [blame] | 18 | await browser.executeAsyncScript(function(callback) { |
| 19 | let block_alerts = |
| 20 | document.getElementById('block_alerts') as HTMLInputElement; |
Philipp Schrader | cf91546 | 2022-03-16 23:42:22 -0700 | [diff] [blame] | 21 | block_alerts.checked = true; |
| 22 | callback(); |
| 23 | }); |
| 24 | } |
Philipp Schrader | fa09693 | 2022-03-05 20:07:10 -0800 | [diff] [blame] | 25 | // Returns the contents of the header that displays the "Auto", "TeleOp", and |
| 26 | // "Climb" labels etc. |
| 27 | function getHeadingText() { |
| 28 | return element(by.css('.header')).getText(); |
| 29 | } |
Philipp Schrader | d999c9f | 2022-02-27 15:48:58 -0800 | [diff] [blame] | 30 | |
Philipp Schrader | 5f19001 | 2022-03-15 23:29:09 -0700 | [diff] [blame] | 31 | // Returns the currently displayed progress message on the screen. This only |
| 32 | // exists on screens where the web page interacts with the web server. |
| 33 | function getProgressMessage() { |
| 34 | return element(by.css('.progress_message')).getText(); |
| 35 | } |
| 36 | |
Philipp Schrader | fa09693 | 2022-03-05 20:07:10 -0800 | [diff] [blame] | 37 | // Returns the currently displayed error message on the screen. This only |
| 38 | // exists on screens where the web page interacts with the web server. |
| 39 | function getErrorMessage() { |
| 40 | return element(by.css('.error_message')).getText(); |
| 41 | } |
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 | // Asserts that the field on the "Submit and Review" screen has a specific |
| 44 | // value. |
| 45 | function expectReviewFieldToBe(fieldName: string, expectedValue: string) { |
| 46 | return expectNthReviewFieldToBe(fieldName, 0, expectedValue); |
| 47 | } |
| 48 | |
| 49 | // Asserts that the n'th instance of a field on the "Submit and Review" |
| 50 | // screen has a specific value. |
Ravago Jones | 2813c03 | 2022-03-16 23:44:11 -0700 | [diff] [blame] | 51 | async function expectNthReviewFieldToBe( |
| 52 | fieldName: string, n: number, expectedValue: string) { |
| 53 | expect(await element.all(by.cssContainingText('li', `${fieldName}:`)) |
| 54 | .get(n) |
| 55 | .getText()) |
Philipp Schrader | fa09693 | 2022-03-05 20:07:10 -0800 | [diff] [blame] | 56 | .toEqual(`${fieldName}: ${expectedValue}`); |
Philipp Schrader | d999c9f | 2022-02-27 15:48:58 -0800 | [diff] [blame] | 57 | } |
| 58 | |
Philipp Schrader | 5f19001 | 2022-03-15 23:29:09 -0700 | [diff] [blame] | 59 | // Sets a text field to the specified value. |
| 60 | function setTextboxByIdTo(id: string, value: string) { |
| 61 | // Just sending "value" to the input fields is insufficient. We need to |
| 62 | // overwrite the text that is there. If we didn't hit CTRL-A to select all |
| 63 | // the text, we'd be appending to whatever is there already. |
| 64 | return element(by.id(id)).sendKeys( |
Ravago Jones | 2813c03 | 2022-03-16 23:44:11 -0700 | [diff] [blame] | 65 | protractor.Key.CONTROL, 'a', protractor.Key.NULL, value); |
Philipp Schrader | 5f19001 | 2022-03-15 23:29:09 -0700 | [diff] [blame] | 66 | } |
| 67 | |
Philipp Schrader | fa45d74 | 2022-03-18 19:29:05 -0700 | [diff] [blame] | 68 | // Moves the nth slider left or right. A positive "adjustBy" value moves the |
| 69 | // slider to the right. A negative value moves the slider to the left. |
| 70 | // |
| 71 | // negative/left <--- 0 ---> positive/right |
| 72 | async function adjustNthSliderBy(n: number, adjustBy: number) { |
| 73 | const slider = element.all(by.css('input[type=range]')).get(n); |
| 74 | const key = adjustBy > 0 ? protractor.Key.ARROW_RIGHT : protractor.Key.ARROW_LEFT; |
| 75 | for (let i = 0; i < Math.abs(adjustBy); i++) { |
| 76 | await slider.sendKeys(key); |
| 77 | } |
| 78 | } |
| 79 | |
Philipp Schrader | b99a8cc | 2022-03-18 21:00:02 -0700 | [diff] [blame^] | 80 | function getNthMatchLabel(n: number) { |
| 81 | return element.all(by.css('.badge')).get(n).getText(); |
| 82 | } |
| 83 | |
Philipp Schrader | d999c9f | 2022-02-27 15:48:58 -0800 | [diff] [blame] | 84 | describe('The scouting web page', () => { |
Philipp Schrader | cf91546 | 2022-03-16 23:42:22 -0700 | [diff] [blame] | 85 | beforeAll(async () => { |
| 86 | await browser.get(browser.baseUrl); |
| 87 | expect((await browser.getTitle())).toEqual('FRC971 Scouting Application'); |
| 88 | await disableAlerts(); |
Philipp Schrader | 5f19001 | 2022-03-15 23:29:09 -0700 | [diff] [blame] | 89 | |
| 90 | // Import the match list before running any tests. Ideally this should be |
| 91 | // run in beforeEach(), but it's not worth doing that at this time. Our |
| 92 | // tests are basic enough not to require this. |
Ravago Jones | 2813c03 | 2022-03-16 23:44:11 -0700 | [diff] [blame] | 93 | await element(by.cssContainingText('.nav-link', 'Import Match List')) |
| 94 | .click(); |
Philipp Schrader | 5f19001 | 2022-03-15 23:29:09 -0700 | [diff] [blame] | 95 | expect(await getHeadingText()).toEqual('Import Match List'); |
| 96 | await setTextboxByIdTo('year', '2016'); |
| 97 | await setTextboxByIdTo('event_code', 'nytr'); |
| 98 | await element(by.buttonText('Import')).click(); |
| 99 | |
| 100 | await browser.wait(EC.textToBePresentInElement( |
Ravago Jones | 2813c03 | 2022-03-16 23:44:11 -0700 | [diff] [blame] | 101 | element(by.css('.progress_message')), |
| 102 | 'Successfully imported match list.')); |
Philipp Schrader | cf91546 | 2022-03-16 23:42:22 -0700 | [diff] [blame] | 103 | }); |
| 104 | |
Philipp Schrader | b99a8cc | 2022-03-18 21:00:02 -0700 | [diff] [blame^] | 105 | it('should: show matches in chronological order.', async () => { |
| 106 | await loadPage(); |
| 107 | |
| 108 | expect(await getNthMatchLabel(0)).toEqual("Quals 1"); |
| 109 | expect(await getNthMatchLabel(1)).toEqual("Quals 2"); |
| 110 | expect(await getNthMatchLabel(2)).toEqual("Quals 3"); |
| 111 | expect(await getNthMatchLabel(9)).toEqual("Quals 10"); |
| 112 | // TODO(phil): Validate quarter finals and friends. Right now we don't |
| 113 | // distinguish between "sets". I.e. we display 4 "Quarter Final 1" matches |
| 114 | // without being able to distinguish between them. |
| 115 | expect(await getNthMatchLabel(87)).toEqual("Final 1"); |
| 116 | }); |
| 117 | |
Philipp Schrader | 5f19001 | 2022-03-15 23:29:09 -0700 | [diff] [blame] | 118 | it('should: error on unknown match.', async () => { |
| 119 | await loadPage(); |
| 120 | |
Ravago Jones | 2813c03 | 2022-03-16 23:44:11 -0700 | [diff] [blame] | 121 | await element(by.cssContainingText('.nav-link', 'Data Entry')).click(); |
| 122 | |
Philipp Schrader | 5f19001 | 2022-03-15 23:29:09 -0700 | [diff] [blame] | 123 | // Pick a match that doesn't exist in the 2016nytr match list. |
| 124 | await setTextboxByIdTo('match_number', '3'); |
| 125 | await setTextboxByIdTo('team_number', '971'); |
| 126 | |
| 127 | // Click Next until we get to the submit screen. |
| 128 | for (let i = 0; i < 5; i++) { |
| 129 | await element(by.buttonText('Next')).click(); |
| 130 | } |
| 131 | expect(await getHeadingText()).toEqual('Review and Submit'); |
| 132 | |
| 133 | // Attempt to submit and validate the error. |
| 134 | await element(by.buttonText('Submit')).click(); |
Ravago Jones | 2813c03 | 2022-03-16 23:44:11 -0700 | [diff] [blame] | 135 | expect(await getErrorMessage()) |
| 136 | .toContain('Failed to find team 971 in match 3 in the schedule.'); |
Philipp Schrader | 5f19001 | 2022-03-15 23:29:09 -0700 | [diff] [blame] | 137 | }); |
| 138 | |
| 139 | |
Philipp Schrader | fa09693 | 2022-03-05 20:07:10 -0800 | [diff] [blame] | 140 | it('should: review and submit correct data.', async () => { |
Philipp Schrader | 577befe | 2022-03-15 00:00:49 -0700 | [diff] [blame] | 141 | await loadPage(); |
Philipp Schrader | d999c9f | 2022-02-27 15:48:58 -0800 | [diff] [blame] | 142 | |
Ravago Jones | 2813c03 | 2022-03-16 23:44:11 -0700 | [diff] [blame] | 143 | await element(by.cssContainingText('.nav-link', 'Data Entry')).click(); |
| 144 | |
Philipp Schrader | 5f19001 | 2022-03-15 23:29:09 -0700 | [diff] [blame] | 145 | // Submit scouting data for a random team that attended 2016nytr. |
Philipp Schrader | fa09693 | 2022-03-05 20:07:10 -0800 | [diff] [blame] | 146 | expect(await getHeadingText()).toEqual('Team Selection'); |
Philipp Schrader | 5f19001 | 2022-03-15 23:29:09 -0700 | [diff] [blame] | 147 | await setTextboxByIdTo('match_number', '2'); |
| 148 | await setTextboxByIdTo('team_number', '5254'); |
Philipp Schrader | fa09693 | 2022-03-05 20:07:10 -0800 | [diff] [blame] | 149 | await element(by.buttonText('Next')).click(); |
Philipp Schrader | d999c9f | 2022-02-27 15:48:58 -0800 | [diff] [blame] | 150 | |
Philipp Schrader | fa09693 | 2022-03-05 20:07:10 -0800 | [diff] [blame] | 151 | expect(await getHeadingText()).toEqual('Auto'); |
Philipp Schrader | e7c252d | 2022-03-17 21:13:47 -0700 | [diff] [blame] | 152 | await element(by.id('quadrant3')).click(); |
Philipp Schrader | fa09693 | 2022-03-05 20:07:10 -0800 | [diff] [blame] | 153 | await element(by.buttonText('Next')).click(); |
| 154 | |
| 155 | expect(await getHeadingText()).toEqual('TeleOp'); |
| 156 | await element(by.buttonText('Next')).click(); |
| 157 | |
| 158 | expect(await getHeadingText()).toEqual('Climb'); |
Philipp Schrader | 5990fd3 | 2022-03-15 21:49:58 -0700 | [diff] [blame] | 159 | await element(by.id('high')).click(); |
Philipp Schrader | fa45d74 | 2022-03-18 19:29:05 -0700 | [diff] [blame] | 160 | await setTextboxByIdTo("comment", "A very useful comment here."); |
Philipp Schrader | fa09693 | 2022-03-05 20:07:10 -0800 | [diff] [blame] | 161 | await element(by.buttonText('Next')).click(); |
| 162 | |
Philipp Schrader | e279e1a | 2022-03-15 22:20:10 -0700 | [diff] [blame] | 163 | expect(await getHeadingText()).toEqual('Other'); |
Philipp Schrader | fa45d74 | 2022-03-18 19:29:05 -0700 | [diff] [blame] | 164 | await adjustNthSliderBy(0, 3); |
| 165 | await adjustNthSliderBy(1, 1); |
Philipp Schrader | e279e1a | 2022-03-15 22:20:10 -0700 | [diff] [blame] | 166 | await element(by.id('no_show')).click(); |
| 167 | await element(by.id('mechanically_broke')).click(); |
Philipp Schrader | fa09693 | 2022-03-05 20:07:10 -0800 | [diff] [blame] | 168 | await element(by.buttonText('Next')).click(); |
| 169 | |
| 170 | expect(await getHeadingText()).toEqual('Review and Submit'); |
| 171 | expect(await getErrorMessage()).toEqual(''); |
| 172 | |
| 173 | // Validate Team Selection. |
Philipp Schrader | 5f19001 | 2022-03-15 23:29:09 -0700 | [diff] [blame] | 174 | await expectReviewFieldToBe('Match number', '2'); |
| 175 | await expectReviewFieldToBe('Team number', '5254'); |
Philipp Schrader | fa09693 | 2022-03-05 20:07:10 -0800 | [diff] [blame] | 176 | |
| 177 | // Validate Auto. |
| 178 | await expectNthReviewFieldToBe('Upper Shots Made', 0, '0'); |
| 179 | await expectNthReviewFieldToBe('Lower Shots Made', 0, '0'); |
| 180 | await expectNthReviewFieldToBe('Missed Shots', 0, '0'); |
Philipp Schrader | e7c252d | 2022-03-17 21:13:47 -0700 | [diff] [blame] | 181 | await expectReviewFieldToBe('Quadrant', '3'); |
Philipp Schrader | fa09693 | 2022-03-05 20:07:10 -0800 | [diff] [blame] | 182 | |
| 183 | // Validate TeleOp. |
| 184 | await expectNthReviewFieldToBe('Upper Shots Made', 1, '0'); |
| 185 | await expectNthReviewFieldToBe('Lower Shots Made', 1, '0'); |
| 186 | await expectNthReviewFieldToBe('Missed Shots', 1, '0'); |
| 187 | |
| 188 | // Validate Climb. |
Philipp Schrader | 5990fd3 | 2022-03-15 21:49:58 -0700 | [diff] [blame] | 189 | await expectReviewFieldToBe('Level', 'High'); |
Philipp Schrader | fa45d74 | 2022-03-18 19:29:05 -0700 | [diff] [blame] | 190 | await expectReviewFieldToBe('Comments', 'A very useful comment here.'); |
Philipp Schrader | fa09693 | 2022-03-05 20:07:10 -0800 | [diff] [blame] | 191 | |
Philipp Schrader | e279e1a | 2022-03-15 22:20:10 -0700 | [diff] [blame] | 192 | // Validate Other. |
Philipp Schrader | fa45d74 | 2022-03-18 19:29:05 -0700 | [diff] [blame] | 193 | await expectReviewFieldToBe('Defense Played On Rating', '3'); |
| 194 | await expectReviewFieldToBe('Defense Played Rating', '1'); |
Philipp Schrader | e279e1a | 2022-03-15 22:20:10 -0700 | [diff] [blame] | 195 | await expectReviewFieldToBe('No show', 'true'); |
| 196 | await expectReviewFieldToBe('Never moved', 'false'); |
| 197 | await expectReviewFieldToBe('Battery died', 'false'); |
| 198 | await expectReviewFieldToBe('Broke (mechanically)', 'true'); |
Philipp Schrader | fa09693 | 2022-03-05 20:07:10 -0800 | [diff] [blame] | 199 | |
Philipp Schrader | 5f19001 | 2022-03-15 23:29:09 -0700 | [diff] [blame] | 200 | await element(by.buttonText('Submit')).click(); |
Ravago Jones | 2813c03 | 2022-03-16 23:44:11 -0700 | [diff] [blame] | 201 | await browser.wait( |
| 202 | EC.textToBePresentInElement(element(by.css('.header')), 'Success')); |
Philipp Schrader | 5f19001 | 2022-03-15 23:29:09 -0700 | [diff] [blame] | 203 | |
| 204 | // TODO(phil): Make sure the data made its way to the database correctly. |
Philipp Schrader | d999c9f | 2022-02-27 15:48:58 -0800 | [diff] [blame] | 205 | }); |
Philipp Schrader | 577befe | 2022-03-15 00:00:49 -0700 | [diff] [blame] | 206 | |
| 207 | it('should: load all images successfully.', async () => { |
| 208 | await loadPage(); |
| 209 | |
Ravago Jones | 2813c03 | 2022-03-16 23:44:11 -0700 | [diff] [blame] | 210 | await element(by.cssContainingText('.nav-link', 'Data Entry')).click(); |
| 211 | |
Philipp Schrader | 577befe | 2022-03-15 00:00:49 -0700 | [diff] [blame] | 212 | // Get to the Auto display with the field pictures. |
| 213 | expect(await getHeadingText()).toEqual('Team Selection'); |
| 214 | await element(by.buttonText('Next')).click(); |
| 215 | expect(await getHeadingText()).toEqual('Auto'); |
| 216 | |
| 217 | // We expect 2 fully loaded images. |
Ravago Jones | 2813c03 | 2022-03-16 23:44:11 -0700 | [diff] [blame] | 218 | browser |
| 219 | .executeAsyncScript(function(callback) { |
| 220 | let images = document.getElementsByTagName('img'); |
| 221 | let numLoaded = 0; |
| 222 | for (let i = 0; i < images.length; i += 1) { |
| 223 | if (images[i].naturalWidth > 0) { |
| 224 | numLoaded += 1; |
| 225 | } |
| 226 | } |
| 227 | callback(numLoaded); |
| 228 | }) |
| 229 | .then(function(numLoaded) { |
| 230 | expect(numLoaded).toBe(2); |
| 231 | }); |
Philipp Schrader | 577befe | 2022-03-15 00:00:49 -0700 | [diff] [blame] | 232 | }); |
Philipp Schrader | d999c9f | 2022-02-27 15:48:58 -0800 | [diff] [blame] | 233 | }); |