| 9 | * to be hydrated before proceeding with the test. |
| 10 | */ |
| 11 | export const goto = async ( |
| 12 | page: Page, |
| 13 | url: string, |
| 14 | testInfo: TestInfo, |
| 15 | originalFn: typeof page.goto, |
| 16 | options?: E2EPageOptions |
| 17 | ) => { |
| 18 | if (options === undefined && testInfo.project.metadata.mode === undefined) { |
| 19 | throw new Error(` |
| 20 | A config must be passed to page.goto to use a generator test: |
| 21 | |
| 22 | configs().forEach(({ config, title }) => { |
| 23 | test(title('example test'), async ({ page }) => { |
| 24 | await page.goto('/src/components/button/test/basic', config); |
| 25 | }); |
| 26 | });`); |
| 27 | } |
| 28 | |
| 29 | let mode: Mode; |
| 30 | let direction: Direction; |
| 31 | let palette: Palette; |
| 32 | |
| 33 | if (options == undefined) { |
| 34 | mode = testInfo.project.metadata.mode; |
| 35 | direction = testInfo.project.metadata.rtl ? 'rtl' : 'ltr'; |
| 36 | palette = testInfo.project.metadata.palette; |
| 37 | } else { |
| 38 | mode = options.mode; |
| 39 | direction = options.direction; |
| 40 | palette = options.palette; |
| 41 | } |
| 42 | |
| 43 | const rtlString = direction === 'rtl' ? 'true' : undefined; |
| 44 | |
| 45 | const splitUrl = url.split('?'); |
| 46 | const paramsString = splitUrl[1]; |
| 47 | |
| 48 | /** |
| 49 | * This allows developers to force a |
| 50 | * certain mode or LTR/RTL config per test. |
| 51 | */ |
| 52 | const urlToParams = new URLSearchParams(paramsString); |
| 53 | const formattedMode = urlToParams.get('ionic:mode') ?? mode; |
| 54 | const formattedRtl = urlToParams.get('rtl') ?? rtlString; |
| 55 | const formattedPalette = urlToParams.get('palette') ?? palette; |
| 56 | const ionicTesting = urlToParams.get('ionic:_testing') ?? true; |
| 57 | |
| 58 | /** |
| 59 | * Pass through other custom query params |
| 60 | */ |
| 61 | urlToParams.delete('ionic:mode'); |
| 62 | urlToParams.delete('rtl'); |
| 63 | urlToParams.delete('palette'); |
| 64 | urlToParams.delete('ionic:_testing'); |
| 65 | |
| 66 | /** |
| 67 | * Convert remaining query params to a string. |
| 68 | * Be sure to call decodeURIComponent to decode |