diff --git a/core/scripts/testing/scripts.js b/core/scripts/testing/scripts.js index e973ec6e0e..5ce8423cb4 100644 --- a/core/scripts/testing/scripts.js +++ b/core/scripts/testing/scripts.js @@ -14,6 +14,20 @@ document.head.appendChild(style); } + /** + * The term `palette` is used to as a param to match the + * Ionic docs, plus here is already a `ionic:theme` query being + * used for `md`, `ios`, and `ionic` themes. + */ + const palette = window.location.search.match(/palette=([a-z]+)/); + if (palette && palette[1] !== 'light') { + const linkTag = document.createElement('link'); + linkTag.setAttribute('rel', 'stylesheet'); + linkTag.setAttribute('type', 'text/css'); + linkTag.setAttribute('href', `/css/palettes/${palette[1]}.always.css`); + document.head.appendChild(linkTag); + } + window.Ionic = window.Ionic || {}; window.Ionic.config = window.Ionic.config || {}; diff --git a/core/src/utils/test/playwright/page/utils/goto.ts b/core/src/utils/test/playwright/page/utils/goto.ts index 3dcf71ac85..dbaee8b44b 100644 --- a/core/src/utils/test/playwright/page/utils/goto.ts +++ b/core/src/utils/test/playwright/page/utils/goto.ts @@ -1,5 +1,5 @@ import type { Page, TestInfo } from '@playwright/test'; -import type { E2EPageOptions, Mode, Direction } from '@utils/test/playwright'; +import type { E2EPageOptions, Mode, Direction, Palette } from '@utils/test/playwright'; /** * This is an extended version of Playwright's @@ -28,13 +28,16 @@ configs().forEach(({ config, title }) => { let mode: Mode; let direction: Direction; + let palette: Palette; if (options == undefined) { mode = testInfo.project.metadata.mode; direction = testInfo.project.metadata.rtl ? 'rtl' : 'ltr'; + palette = testInfo.project.metadata.palette; } else { mode = options.mode; direction = options.direction; + palette = options.palette; } const rtlString = direction === 'rtl' ? 'true' : undefined; @@ -49,6 +52,7 @@ configs().forEach(({ config, title }) => { const urlToParams = new URLSearchParams(paramsString); const formattedMode = urlToParams.get('ionic:mode') ?? mode; const formattedRtl = urlToParams.get('rtl') ?? rtlString; + const formattedPalette = urlToParams.get('palette') ?? palette; const ionicTesting = urlToParams.get('ionic:_testing') ?? true; /** @@ -56,6 +60,7 @@ configs().forEach(({ config, title }) => { */ urlToParams.delete('ionic:mode'); urlToParams.delete('rtl'); + urlToParams.delete('palette'); urlToParams.delete('ionic:_testing'); /** @@ -66,7 +71,7 @@ configs().forEach(({ config, title }) => { const remainingQueryParams = decodeURIComponent(urlToParams.toString()); const remainingQueryParamsString = remainingQueryParams == '' ? '' : `&${remainingQueryParams}`; - const formattedUrl = `${splitUrl[0]}?ionic:_testing=${ionicTesting}&ionic:mode=${formattedMode}&rtl=${formattedRtl}${remainingQueryParamsString}`; + const formattedUrl = `${splitUrl[0]}?ionic:_testing=${ionicTesting}&ionic:mode=${formattedMode}&rtl=${formattedRtl}&palette=${formattedPalette}${remainingQueryParamsString}`; testInfo.annotations.push({ type: 'mode', @@ -78,6 +83,11 @@ configs().forEach(({ config, title }) => { description: formattedRtl === 'true' ? 'rtl' : 'ltr', }); + testInfo.annotations.push({ + type: 'palette', + description: formattedPalette, + }); + const result = await Promise.all([ page.waitForFunction(() => (window as any).testAppLoaded === true, { timeout: 4750 }), originalFn(formattedUrl, options), diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md index c6324e90a1..0a6687d7b3 100644 --- a/docs/CONTRIBUTING.md +++ b/docs/CONTRIBUTING.md @@ -144,6 +144,7 @@ Before creating a pull request, please read our requirements that explains the m 3. From here, navigate to one of the component's tests to preview your changes. 4. If a test showing your change doesn't exist, [add a new test or update an existing one](#modifying-tests). 5. To test in RTL mode, once you are in the desired component's test, add `?rtl=true` at the end of the url; for example: `http://localhost:3333/src/components/alert/test/basic?rtl=true`. +6. To test in dark mode, once you are in the desired component's test, add `?palette=dark` at the end of the url; for example: `http://localhost:3333/src/components/alert/test/basic?palette=dark`. ##### Previewing in an external app