@canonical/summon-application 0.48.0 → 0.49.0-experimental.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -26
- package/dist/esm/application/react/index.js +28 -1
- package/dist/esm/application/react/index.js.map +1 -1
- package/dist/esm/application/react/templates/README.md.ejs +5 -0
- package/dist/esm/application/react/templates/src/domains/catalog/ProductCard.tsx.ejs +2 -2
- package/dist/esm/application/react/templates/src/domains/dashboard/InstancesPage.tsx.ejs +1 -1
- package/dist/esm/application/react/templates/src/domains/dashboard/OverviewPage.tsx.ejs +6 -6
- package/dist/esm/application/react/templates/src/i18n/ar.ts.ejs +1 -0
- package/dist/esm/application/react/templates/src/i18n/config.ts +2 -2
- package/dist/esm/application/react/templates/src/i18n/en.ts.ejs +1 -0
- package/dist/esm/application/react/templates/src/i18n/fr.ts.ejs +1 -0
- package/dist/esm/application/react/templates/src/i18n/negotiation.test.ts +5 -5
- package/dist/esm/application/react/templates/src/lib/LocaleSelector/LocaleSelector.test.tsx +10 -0
- package/dist/esm/application/react/templates/src/lib/LocaleSelector/LocaleSelector.tsx.ejs +35 -21
- package/dist/esm/application/react/templates/src/lib/ThemeSelector/ServerThemeContext.ts +13 -0
- package/dist/esm/application/react/templates/src/lib/ThemeSelector/ThemeSelector.ssr.test.tsx.ejs +45 -0
- package/dist/esm/application/react/templates/src/lib/ThemeSelector/ThemeSelector.test.tsx.ejs +67 -0
- package/dist/esm/application/react/templates/src/lib/ThemeSelector/ThemeSelector.tsx.ejs +60 -26
- package/dist/esm/application/react/templates/src/lib/ThemeSelector/index.ts.ejs +4 -0
- package/dist/esm/application/react/templates/src/lib/TopBar/TopBar.test.tsx.ejs +7 -10
- package/dist/esm/application/react/templates/src/lib/TopBar/styles.css +8 -3
- package/dist/esm/application/react/templates/src/server/entry.tsx.ejs +23 -14
- package/dist/esm/application/react/templates/src/server/handlePreferenceForm.test.ts.ejs +63 -0
- package/dist/esm/application/react/templates/src/server/handlePreferenceForm.ts.ejs +158 -0
- package/dist/esm/application/react/templates/src/server/preferenceFormMiddleware.ts +42 -0
- package/dist/esm/application/react/templates/src/server/preview.bun.ts +5 -0
- package/dist/esm/application/react/templates/src/server/preview.express.ts +4 -0
- package/dist/esm/application/react/templates/src/server/resolveReturnTo.ts +18 -0
- package/dist/esm/application/react/templates/src/server/server.bun.ts.ejs +5 -0
- package/dist/esm/application/react/templates/src/server/server.express.ts.ejs +4 -0
- package/dist/esm/application/react/templates/test/e2e/servers.e2e.ts.ejs +56 -0
- package/dist/esm/application/react/templates/vitest.config.ts +4 -0
- package/dist/esm/application/svelte/index.js +226 -80
- package/dist/esm/application/svelte/index.js.map +1 -1
- package/dist/esm/application/svelte/templates/.storybook/{main.ts.ejs → main.ts} +1 -0
- package/dist/esm/application/svelte/templates/.storybook/preview.ts.ejs +20 -2
- package/dist/esm/application/svelte/templates/README.md.ejs +163 -40
- package/dist/esm/application/svelte/templates/biome.json.ejs +12 -0
- package/dist/esm/application/svelte/templates/gitignore.ejs +3 -4
- package/dist/esm/application/svelte/templates/package.json.ejs +54 -18
- package/dist/esm/application/svelte/templates/scripts/copy-icons.js +10 -0
- package/dist/esm/application/svelte/templates/src/app.d.ts.ejs +10 -2
- package/dist/esm/application/svelte/templates/src/app.html.ejs +9 -1
- package/dist/esm/application/svelte/templates/src/domains/account/AccountPage.svelte.ejs +18 -0
- package/dist/esm/application/svelte/templates/src/domains/account/LoginPage.svelte.ejs +32 -0
- package/dist/esm/application/svelte/templates/src/domains/account/getAuthRedirect.test.ts +18 -0
- package/dist/esm/application/svelte/templates/src/domains/account/getAuthRedirect.ts +18 -0
- package/dist/esm/application/svelte/templates/src/domains/account/guardAccount.ts +15 -0
- package/dist/esm/application/svelte/templates/src/domains/catalog/CatalogPage.svelte.ejs +35 -0
- package/dist/esm/application/svelte/templates/src/domains/catalog/ProductCard.svelte.ejs +51 -0
- package/dist/esm/application/svelte/templates/src/domains/catalog/ProductList.stories.svelte.ejs +110 -0
- package/dist/esm/application/svelte/templates/src/domains/catalog/ProductList.svelte.ejs +41 -0
- package/dist/esm/application/svelte/templates/src/domains/catalog/constants.ts +2 -0
- package/dist/esm/application/svelte/templates/src/domains/catalog/data.test.ts +19 -0
- package/dist/esm/application/svelte/templates/src/domains/catalog/data.ts +75 -0
- package/dist/esm/application/svelte/templates/src/domains/catalog/loadCatalog.ts +7 -0
- package/dist/esm/application/svelte/templates/src/domains/catalog/types.ts +25 -0
- package/dist/esm/application/svelte/templates/src/domains/contact/ContactPage.svelte.ejs +86 -0
- package/dist/esm/application/svelte/templates/src/domains/contact/types.ts.ejs +19 -0
- package/dist/esm/application/svelte/templates/src/domains/contact/validateContact.test.ts.ejs +31 -0
- package/dist/esm/application/svelte/templates/src/domains/contact/validateContact.ts.ejs +28 -0
- package/dist/esm/application/svelte/templates/src/domains/dashboard/DashboardBreadcrumbs.svelte.ejs +29 -0
- package/dist/esm/application/svelte/templates/src/domains/dashboard/DashboardLayout.svelte.ejs +35 -0
- package/dist/esm/application/svelte/templates/src/domains/dashboard/InstancesPage.svelte.ejs +245 -0
- package/dist/esm/application/svelte/templates/src/domains/dashboard/OverviewPage.svelte.ejs +180 -0
- package/dist/esm/application/svelte/templates/src/domains/dashboard/SettingsPage.svelte.ejs +103 -0
- package/dist/esm/application/svelte/templates/src/domains/dashboard/constants.ts.ejs +253 -0
- package/dist/esm/application/svelte/templates/src/domains/dashboard/createDashboardNavigation.ts.ejs +103 -0
- package/dist/esm/application/svelte/templates/src/domains/dashboard/createInstance.test.ts +22 -0
- package/dist/esm/application/svelte/templates/src/domains/dashboard/createInstance.ts +28 -0
- package/dist/esm/application/svelte/templates/src/domains/dashboard/projectBreadcrumbs.test.ts +78 -0
- package/dist/esm/application/svelte/templates/src/domains/dashboard/projectBreadcrumbs.ts +47 -0
- package/dist/esm/application/svelte/templates/src/domains/dashboard/selectRelativeTime.test.ts +19 -0
- package/dist/esm/application/svelte/templates/src/domains/dashboard/selectRelativeTime.ts +24 -0
- package/dist/esm/application/svelte/templates/src/domains/dashboard/styles.css +98 -0
- package/dist/esm/application/svelte/templates/src/domains/dashboard/types.ts.ejs +61 -0
- package/dist/esm/application/svelte/templates/src/domains/marketing/GuidePage.svelte.ejs +29 -0
- package/dist/esm/application/svelte/templates/src/domains/marketing/HomePage.svelte.ejs +47 -0
- package/dist/esm/application/svelte/templates/src/domains/marketing/isGuideSlug.ts +8 -0
- package/dist/esm/application/svelte/templates/src/formatDocumentTitle.ts.ejs +9 -0
- package/dist/esm/application/svelte/templates/src/hooks.server.ts.ejs +47 -9
- package/dist/esm/application/svelte/templates/src/i18n/ar.ts.ejs +174 -0
- package/dist/esm/application/svelte/templates/src/i18n/catalogs.ts +14 -0
- package/dist/esm/application/svelte/templates/src/i18n/config.ts +19 -0
- package/dist/esm/application/svelte/templates/src/i18n/en.ts.ejs +173 -0
- package/dist/esm/application/svelte/templates/src/i18n/fr.ts.ejs +171 -0
- package/dist/esm/application/svelte/templates/src/i18n/index.ts +45 -0
- package/dist/esm/application/svelte/templates/src/i18n/negotiation.test.ts +92 -0
- package/dist/esm/application/svelte/templates/src/layouts/ErrorPage.svelte.ejs +40 -0
- package/dist/esm/application/svelte/templates/src/layouts/PublicLayout.svelte +18 -0
- package/dist/esm/application/svelte/templates/src/layouts/RootLayout.svelte.ejs +43 -0
- package/dist/esm/application/svelte/templates/src/layouts/TopBarLayout.svelte +28 -0
- package/dist/esm/application/svelte/templates/src/lib/ApplicationShell/ApplicationShell.stories.svelte +87 -0
- package/dist/esm/application/svelte/templates/src/lib/ApplicationShell/ApplicationShell.svelte.ejs +60 -0
- package/dist/esm/application/svelte/templates/src/lib/ApplicationShell/index.ts +2 -0
- package/dist/esm/application/svelte/templates/src/lib/ApplicationShell/styles.css +43 -0
- package/dist/esm/application/svelte/templates/src/lib/ApplicationShell/types.ts +23 -0
- package/dist/esm/application/svelte/templates/src/lib/CanonicalLogo/CanonicalLogo.svelte.ejs +27 -0
- package/dist/esm/application/svelte/templates/src/lib/CanonicalLogo/index.ts +2 -0
- package/dist/esm/application/svelte/templates/src/lib/CanonicalLogo/styles.css +31 -0
- package/dist/esm/application/svelte/templates/src/lib/CanonicalLogo/types.ts +15 -0
- package/dist/esm/application/svelte/templates/src/lib/CodeMessage/CodeMessage.svelte +18 -0
- package/dist/esm/application/svelte/templates/src/lib/CodeMessage/index.ts +2 -0
- package/dist/esm/application/svelte/templates/src/lib/CodeMessage/types.ts +14 -0
- package/dist/esm/application/svelte/templates/src/lib/ExampleComponent/ExampleComponent.stories.svelte +15 -0
- package/dist/esm/application/svelte/templates/src/lib/ExampleComponent/ExampleComponent.svelte +17 -0
- package/dist/esm/application/svelte/templates/src/lib/ExampleComponent/index.ts +2 -0
- package/dist/esm/application/svelte/templates/src/lib/ExampleComponent/styles.css +17 -0
- package/dist/esm/application/svelte/templates/src/lib/ExampleComponent/types.ts +10 -0
- package/dist/esm/application/svelte/templates/src/lib/Icon/Icon.svelte +16 -0
- package/dist/esm/application/svelte/templates/src/lib/Icon/index.ts +2 -0
- package/dist/esm/application/svelte/templates/src/lib/Icon/types.ts +10 -0
- package/dist/esm/application/svelte/templates/src/lib/LazyComponent/LazyComponent.stories.svelte +19 -0
- package/dist/esm/application/svelte/templates/src/lib/LazyComponent/LazyComponent.svelte.ejs +29 -0
- package/dist/esm/application/svelte/templates/src/lib/LazyComponent/createDelayedData.ts.ejs +24 -0
- package/dist/esm/application/svelte/templates/src/lib/LazyComponent/index.ts +2 -0
- package/dist/esm/application/svelte/templates/src/lib/LazyComponent/types.ts.ejs +19 -0
- package/dist/esm/application/svelte/templates/src/lib/LocaleSelector/LocaleSelector.svelte.ejs +50 -0
- package/dist/esm/application/svelte/templates/src/lib/LocaleSelector/index.ts +2 -0
- package/dist/esm/application/svelte/templates/src/lib/LocaleSelector/types.ts +7 -0
- package/dist/esm/application/svelte/templates/src/lib/Navigation/Navigation.svelte.ejs +42 -0
- package/dist/esm/application/svelte/templates/src/lib/Navigation/index.ts +2 -0
- package/dist/esm/application/svelte/templates/src/lib/Navigation/types.ts +14 -0
- package/dist/esm/application/svelte/templates/src/lib/ThemeSelector/ThemeSelector.svelte.ejs +38 -0
- package/dist/esm/application/svelte/templates/src/lib/ThemeSelector/constants.ts +8 -0
- package/dist/esm/application/svelte/templates/src/lib/ThemeSelector/index.ts +5 -0
- package/dist/esm/application/svelte/templates/src/lib/ThemeSelector/readTheme.test.ts +13 -0
- package/dist/esm/application/svelte/templates/src/lib/ThemeSelector/readTheme.ts +15 -0
- package/dist/esm/application/svelte/templates/src/lib/ThemeSelector/setTheme.ts +27 -0
- package/dist/esm/application/svelte/templates/src/lib/ThemeSelector/types.ts +18 -0
- package/dist/esm/application/svelte/templates/src/lib/TopBar/TopBar.stories.svelte.ejs +24 -0
- package/dist/esm/application/svelte/templates/src/lib/TopBar/TopBar.svelte.ejs +32 -0
- package/dist/esm/application/svelte/templates/src/lib/TopBar/index.ts +2 -0
- package/dist/esm/application/svelte/templates/src/lib/TopBar/styles.css +54 -0
- package/dist/esm/application/svelte/templates/src/lib/TopBar/types.ts +15 -0
- package/dist/esm/application/svelte/templates/src/lib/index.ts.ejs +16 -0
- package/dist/esm/application/svelte/templates/src/params/guide.ts +5 -0
- package/dist/esm/application/svelte/templates/src/resolveReturnTo.test.ts +27 -0
- package/dist/esm/application/svelte/templates/src/resolveReturnTo.ts +13 -0
- package/dist/esm/application/svelte/templates/src/routes/(top-bar)/(public)/+layout.svelte +8 -0
- package/dist/esm/application/svelte/templates/src/routes/(top-bar)/(public)/+page.server.ts +6 -0
- package/dist/esm/application/svelte/templates/src/routes/(top-bar)/(public)/+page.svelte +8 -0
- package/dist/esm/application/svelte/templates/src/routes/(top-bar)/(public)/+page.ts +6 -0
- package/dist/esm/application/svelte/templates/src/routes/(top-bar)/(public)/account/+page.svelte +5 -0
- package/dist/esm/application/svelte/templates/src/routes/(top-bar)/(public)/account/+page.ts +4 -0
- package/dist/esm/application/svelte/templates/src/routes/(top-bar)/(public)/catalog/+page.svelte +8 -0
- package/dist/esm/application/svelte/templates/src/routes/(top-bar)/(public)/catalog/+page.ts +4 -0
- package/dist/esm/application/svelte/templates/src/routes/(top-bar)/(public)/contact/+page.server.ts +25 -0
- package/dist/esm/application/svelte/templates/src/routes/(top-bar)/(public)/contact/+page.svelte.ejs +30 -0
- package/dist/esm/application/svelte/templates/src/routes/(top-bar)/(public)/guides/[slug=guide]/+page.svelte +6 -0
- package/dist/esm/application/svelte/templates/src/routes/(top-bar)/(public)/login/+page.svelte +6 -0
- package/dist/esm/application/svelte/templates/src/routes/(top-bar)/+layout.svelte +9 -0
- package/dist/esm/application/svelte/templates/src/routes/(top-bar)/dashboard/+layout.svelte +9 -0
- package/dist/esm/application/svelte/templates/src/routes/(top-bar)/dashboard/+page.svelte +5 -0
- package/dist/esm/application/svelte/templates/src/routes/(top-bar)/dashboard/instances/+page.server.ts.ejs +28 -0
- package/dist/esm/application/svelte/templates/src/routes/(top-bar)/dashboard/instances/+page.svelte.ejs +19 -0
- package/dist/esm/application/svelte/templates/src/routes/(top-bar)/dashboard/settings/+page.server.ts +9 -0
- package/dist/esm/application/svelte/templates/src/routes/(top-bar)/dashboard/settings/+page.svelte +5 -0
- package/dist/esm/application/svelte/templates/src/routes/+error.svelte +6 -0
- package/dist/esm/application/svelte/templates/src/routes/+layout.server.ts.ejs +7 -1
- package/dist/esm/application/svelte/templates/src/routes/+layout.svelte.ejs +18 -82
- package/dist/esm/application/svelte/templates/src/routes/+layout.ts.ejs +29 -0
- package/dist/esm/application/svelte/templates/src/routes/home/+page.ts +4 -0
- package/dist/esm/application/svelte/templates/src/routes/home/{+server.ts.ejs → +server.ts} +1 -0
- package/dist/esm/application/svelte/templates/src/routes/icons/[icon]/+server.ts +37 -0
- package/dist/esm/application/svelte/templates/src/routes/language/+server.ts +30 -0
- package/dist/esm/application/svelte/templates/src/routes/preferences/+server.ts +32 -0
- package/dist/esm/application/svelte/templates/src/routes/sitemap.xml/+server.ts.ejs +44 -4
- package/dist/esm/application/svelte/templates/src/storybook/I18nDecorator.svelte +28 -0
- package/dist/esm/application/svelte/templates/src/storybook/decorators.ts +12 -0
- package/dist/esm/application/svelte/templates/src/styles/app.css +38 -0
- package/dist/esm/application/svelte/templates/src/styles/index.css.ejs +25 -0
- package/dist/esm/application/svelte/templates/src/styles/standins/Card.css +198 -0
- package/dist/esm/application/svelte/templates/src/styles/standins/Icon.css +32 -0
- package/dist/esm/application/svelte/templates/src/styles/standins/InlineCode.css +30 -0
- package/dist/esm/application/svelte/templates/src/styles/standins/SidePanel.css +462 -0
- package/dist/esm/application/svelte/templates/src/styles/standins/Tile.css +108 -0
- package/dist/esm/application/svelte/templates/src/styles/standins/Timeline.css +171 -0
- package/dist/esm/application/svelte/templates/src/styles/standins.css.ejs +17 -0
- package/dist/esm/application/svelte/templates/svelte.config.js.ejs +12 -2
- package/dist/esm/application/svelte/templates/test/app.test.js.ejs +739 -123
- package/dist/esm/application/svelte/templates/test/spa.test.js.ejs +224 -0
- package/dist/esm/application/svelte/templates/{tsconfig.json.ejs → tsconfig.json} +2 -2
- package/dist/esm/application/svelte/templates/{vite.config.ts.ejs → vite.config.ts} +1 -1
- package/dist/esm/application/svelte/templates/vitest.config.ts +10 -0
- package/dist/esm/application/svelte/textHelpers.js +20 -0
- package/dist/esm/application/svelte/textHelpers.js.map +1 -0
- package/dist/esm/shared/versions.js +10 -8
- package/dist/esm/shared/versions.js.map +1 -1
- package/dist/types/application/react/index.d.ts.map +1 -1
- package/dist/types/application/svelte/index.d.ts.map +1 -1
- package/dist/types/application/svelte/textHelpers.d.ts +21 -0
- package/dist/types/application/svelte/textHelpers.d.ts.map +1 -0
- package/dist/types/shared/versions.d.ts +11 -9
- package/dist/types/shared/versions.d.ts.map +1 -1
- package/package.json +6 -6
- package/dist/esm/application/react/templates/src/lib/ThemeSelector/index.ts +0 -1
- package/dist/esm/application/svelte/templates/scripts/copy-icons.js.ejs +0 -9
- package/dist/esm/application/svelte/templates/src/lib/ContactExample.stories.svelte.ejs +0 -11
- package/dist/esm/application/svelte/templates/src/lib/ContactExample.svelte.ejs +0 -19
- package/dist/esm/application/svelte/templates/src/lib/DashboardNavigation.svelte.ejs +0 -17
- package/dist/esm/application/svelte/templates/src/lib/ProjectDanger.svelte.ejs +0 -18
- package/dist/esm/application/svelte/templates/src/lib/Welcome.stories.svelte.ejs +0 -5
- package/dist/esm/application/svelte/templates/src/lib/catalog.ts.ejs +0 -5
- package/dist/esm/application/svelte/templates/src/lib/contact.ts.ejs +0 -19
- package/dist/esm/application/svelte/templates/src/lib/i18n.ts.ejs +0 -351
- package/dist/esm/application/svelte/templates/src/lib/instances.ts.ejs +0 -16
- package/dist/esm/application/svelte/templates/src/lib/resolveReturnTo.ts.ejs +0 -11
- package/dist/esm/application/svelte/templates/src/lib/settings.ts.ejs +0 -28
- package/dist/esm/application/svelte/templates/src/routes/+error.svelte.ejs +0 -9
- package/dist/esm/application/svelte/templates/src/routes/+page.svelte.ejs +0 -9
- package/dist/esm/application/svelte/templates/src/routes/account/+page.server.ts.ejs +0 -13
- package/dist/esm/application/svelte/templates/src/routes/account/+page.svelte.ejs +0 -20
- package/dist/esm/application/svelte/templates/src/routes/catalog/+page.svelte.ejs +0 -12
- package/dist/esm/application/svelte/templates/src/routes/catalog/[id]/+page.server.ts.ejs +0 -8
- package/dist/esm/application/svelte/templates/src/routes/catalog/[id]/+page.svelte.ejs +0 -13
- package/dist/esm/application/svelte/templates/src/routes/catalog/[id]/+page.ts.ejs +0 -8
- package/dist/esm/application/svelte/templates/src/routes/contact/+page.server.ts.ejs +0 -11
- package/dist/esm/application/svelte/templates/src/routes/contact/+page.svelte.ejs +0 -85
- package/dist/esm/application/svelte/templates/src/routes/dashboard/+layout.svelte.ejs +0 -15
- package/dist/esm/application/svelte/templates/src/routes/dashboard/+page.server.ts.ejs +0 -5
- package/dist/esm/application/svelte/templates/src/routes/dashboard/+page.svelte.ejs +0 -33
- package/dist/esm/application/svelte/templates/src/routes/dashboard/instances/+page.server.ts.ejs +0 -23
- package/dist/esm/application/svelte/templates/src/routes/dashboard/instances/+page.svelte.ejs +0 -101
- package/dist/esm/application/svelte/templates/src/routes/dashboard/instances/remove/+page.server.ts.ejs +0 -19
- package/dist/esm/application/svelte/templates/src/routes/dashboard/instances/remove/+page.svelte.ejs +0 -11
- package/dist/esm/application/svelte/templates/src/routes/dashboard/settings/+page.server.ts.ejs +0 -13
- package/dist/esm/application/svelte/templates/src/routes/dashboard/settings/+page.svelte.ejs +0 -52
- package/dist/esm/application/svelte/templates/src/routes/dashboard/settings/confirm/+page.server.ts.ejs +0 -2
- package/dist/esm/application/svelte/templates/src/routes/dashboard/settings/confirm/+page.svelte.ejs +0 -13
- package/dist/esm/application/svelte/templates/src/routes/language/+server.ts.ejs +0 -12
- package/dist/esm/application/svelte/templates/src/routes/login/+page.server.ts.ejs +0 -8
- package/dist/esm/application/svelte/templates/src/routes/login/+page.svelte.ejs +0 -11
- package/dist/esm/application/svelte/templates/src/routes/preferences/+server.ts.ejs +0 -10
- package/dist/esm/application/svelte/templates/src/styles.css.ejs +0 -28
- package/dist/esm/application/svelte/templates/test/contact.browser.test.js.ejs +0 -279
|
@@ -1,142 +1,758 @@
|
|
|
1
1
|
import assert from "node:assert/strict";
|
|
2
2
|
import { spawn } from "node:child_process";
|
|
3
3
|
import { createServer } from "node:net";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { after, before, describe, test } from "node:test";
|
|
5
|
+
import { chromium } from "playwright";
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
/*
|
|
8
|
+
* The built SSR server (adapter-node), exercised over HTTP for its responses
|
|
9
|
+
* and the forms' no-JavaScript paths, and in Chromium for the pages' live
|
|
10
|
+
* behaviour.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
let server;
|
|
8
14
|
let base;
|
|
15
|
+
let browser;
|
|
16
|
+
|
|
17
|
+
const form = "application/x-www-form-urlencoded";
|
|
18
|
+
const APP_NAME = "<%= name %>";
|
|
19
|
+
|
|
9
20
|
before(async () => {
|
|
10
21
|
const socket = createServer();
|
|
11
22
|
await new Promise((resolve) => socket.listen(0, "127.0.0.1", resolve));
|
|
12
23
|
const { port } = socket.address();
|
|
13
|
-
await new Promise((resolve, reject) =>
|
|
24
|
+
await new Promise((resolve, reject) =>
|
|
25
|
+
socket.close((error) => (error ? reject(error) : resolve())),
|
|
26
|
+
);
|
|
14
27
|
base = `http://127.0.0.1:${port}`;
|
|
15
|
-
server = spawn(process.env.SERVER_RUNTIME
|
|
28
|
+
server = spawn(process.env.SERVER_RUNTIME || "node", ["build/index.js"], {
|
|
29
|
+
env: {
|
|
30
|
+
...process.env,
|
|
31
|
+
HOST: "127.0.0.1",
|
|
32
|
+
PORT: String(port),
|
|
33
|
+
ORIGIN: base,
|
|
34
|
+
},
|
|
35
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
36
|
+
});
|
|
37
|
+
let output = "";
|
|
38
|
+
server.stdout.on("data", (data) => {
|
|
39
|
+
output += data;
|
|
40
|
+
});
|
|
41
|
+
server.stderr.on("data", (data) => {
|
|
42
|
+
output += data;
|
|
43
|
+
});
|
|
16
44
|
for (let attempt = 0; attempt < 100; attempt++) {
|
|
17
|
-
if (server.exitCode !== null) throw new Error(
|
|
18
|
-
try {
|
|
45
|
+
if (server.exitCode !== null) throw new Error(`Server exited: ${output}`);
|
|
46
|
+
try {
|
|
47
|
+
if ((await fetch(base)).ok) return;
|
|
48
|
+
} catch {
|
|
49
|
+
/* Await startup. */
|
|
50
|
+
}
|
|
19
51
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
20
52
|
}
|
|
21
|
-
throw new Error(
|
|
53
|
+
throw new Error(`Server did not start: ${output}`);
|
|
22
54
|
});
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const dark = await request("/", { headers: { cookie: "theme=dark" } });
|
|
28
|
-
assert.match(await dark.text(), /class="app comfortable dark"/);
|
|
29
|
-
assert.equal(dark.headers.get("cache-control"), "private, no-store");
|
|
30
|
-
assert.equal((await request("/home")).status, 301);
|
|
31
|
-
assert.equal((await request("/missing")).status, 404);
|
|
32
|
-
assert.equal((await request("/catalog/missing")).status, 404);
|
|
33
|
-
assert.equal((await request("/icons/information.svg")).status, 200);
|
|
34
|
-
const product = await (await request("/catalog/compute")).text();
|
|
35
|
-
assert.match(product, /class="ds breadcrumbs"/);
|
|
36
|
-
assert.match(await (await request("/sitemap.xml")).text(), /\/catalog\/compute/);
|
|
37
|
-
const [alice, bob] = await Promise.all(["Alice", "Bob"].map((visitor) => request("/catalog/compute", { headers: { cookie: `visitor=${visitor}` } }).then((response) => response.text())));
|
|
38
|
-
assert.match(alice, /Viewing as Alice/); assert.doesNotMatch(alice, /Viewing as Bob/); assert.match(bob, /Viewing as Bob/);
|
|
39
|
-
<% if (intl) { %> assert.match(await (await request("/", { headers: { cookie: "locale=ar" } })).text(), /lang="ar" dir="rtl"/);
|
|
40
|
-
assert.match(await (await request("/catalog", { headers: { cookie: "locale=ar" } })).text(), /منتجان/);
|
|
41
|
-
assert.match(await (await request("/catalog", { headers: { cookie: "locale=fr" } })).text(), /2 produits/);
|
|
42
|
-
<% } %>});
|
|
43
|
-
|
|
44
|
-
test("preference redirects remain same-origin for hostile referrers", async () => {
|
|
45
|
-
const endpoints = ["preferences"<% if (intl) { %>, "language"<% } %>];
|
|
46
|
-
const referrers = [
|
|
47
|
-
[`${base}/catalog/compute?view=detail`, "/catalog/compute?view=detail"],
|
|
48
|
-
[`${base}//evil.test/path`, "//evil.test/path"],
|
|
49
|
-
[`${base}/\\evil.test/path`, "//evil.test/path"],
|
|
50
|
-
[`${base}/%2f%2fevil.test/path`, "/%2f%2fevil.test/path"],
|
|
51
|
-
[`${base}/%5cevil.test/path`, "/%5cevil.test/path"],
|
|
52
|
-
["https://evil.test/path", "/"],
|
|
53
|
-
["//evil.test/path", "/"],
|
|
54
|
-
["http://[invalid", "/"],
|
|
55
|
-
["", "/"],
|
|
56
|
-
];
|
|
57
|
-
for (const endpoint of endpoints) {
|
|
58
|
-
for (const [referer, expected] of referrers) {
|
|
59
|
-
const response = await fetch(`${base}/${endpoint}`, {
|
|
60
|
-
method: "POST", redirect: "manual",
|
|
61
|
-
headers: { origin: base, referer, "content-type": "application/x-www-form-urlencoded" },
|
|
62
|
-
body: endpoint === "language" ? "locale=fr" : "theme=dark",
|
|
63
|
-
});
|
|
64
|
-
assert.equal(response.status, 303, `${endpoint} ${referer}`);
|
|
65
|
-
const location = response.headers.get("location");
|
|
66
|
-
const resolved = new URL(location, base);
|
|
67
|
-
assert.equal(resolved.origin, base, `${endpoint} ${referer}: ${location}`);
|
|
68
|
-
assert.equal(resolved.pathname + resolved.search, expected, `${endpoint} ${referer}`);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
55
|
+
|
|
56
|
+
after(async () => {
|
|
57
|
+
await browser?.close();
|
|
58
|
+
server?.kill();
|
|
71
59
|
});
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
60
|
+
|
|
61
|
+
const request = (path, options = {}) =>
|
|
62
|
+
fetch(new URL(path, base), { redirect: "manual", ...options });
|
|
63
|
+
|
|
64
|
+
/** A page's HTML without Svelte's hydration comments. */
|
|
65
|
+
const strip = (text) => text.replaceAll(/<!--[^>]*-->/g, "");
|
|
66
|
+
|
|
67
|
+
const post = (path, body, headers = {}) =>
|
|
68
|
+
request(path, {
|
|
69
|
+
method: "POST",
|
|
70
|
+
headers: { origin: base, "content-type": form, ...headers },
|
|
71
|
+
body,
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
/** Opens a browser context; `javaScriptEnabled: false` exercises the no-JS paths. */
|
|
75
|
+
async function withPage(options, run) {
|
|
76
|
+
browser ??= await chromium.launch({
|
|
77
|
+
executablePath: process.env.CHROMIUM_PATH || undefined,
|
|
78
|
+
headless: true,
|
|
79
|
+
});
|
|
80
|
+
const context = await browser.newContext(options);
|
|
81
|
+
try {
|
|
82
|
+
await run(await context.newPage(), context);
|
|
83
|
+
} finally {
|
|
84
|
+
await context.close();
|
|
85
85
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** Opens `path` once the client has hydrated. */
|
|
89
|
+
async function open(page, path) {
|
|
90
|
+
await page.goto(new URL(path, base).href);
|
|
91
|
+
await page.waitForLoadState("networkidle");
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const htmlClass = (page) => page.locator("html").getAttribute("class");
|
|
95
|
+
|
|
96
|
+
describe("the server", () => {
|
|
97
|
+
test("answers every route with its status and title", async () => {
|
|
98
|
+
for (const [path, status, title] of [
|
|
99
|
+
["/", 200, `Home — ${APP_NAME}`],
|
|
100
|
+
["/guides/router-core", 200, `router-core — ${APP_NAME}`],
|
|
101
|
+
["/catalog", 200, `Catalog — ${APP_NAME}`],
|
|
102
|
+
<% if (forms) { -%>
|
|
103
|
+
["/contact", 200, `Contact — ${APP_NAME}`],
|
|
104
|
+
<% } -%>
|
|
105
|
+
<% if (appShell) { -%>
|
|
106
|
+
["/dashboard", 200, `Dashboard — ${APP_NAME}`],
|
|
107
|
+
["/dashboard/instances", 200, `Instances — ${APP_NAME}`],
|
|
108
|
+
["/dashboard/settings", 200, `Settings — ${APP_NAME}`],
|
|
109
|
+
<% } -%>
|
|
110
|
+
["/account?auth=1", 200, `Account — ${APP_NAME}`],
|
|
111
|
+
["/login?from=%2Faccount", 200, `Login — ${APP_NAME}`],
|
|
112
|
+
["/missing", 404, `Page not found — ${APP_NAME}`],
|
|
113
|
+
["/guides/Not_Kebab", 404, `Page not found — ${APP_NAME}`],
|
|
114
|
+
]) {
|
|
115
|
+
const response = await request(path);
|
|
116
|
+
assert.equal(response.status, status, path);
|
|
117
|
+
assert.match(
|
|
118
|
+
await response.text().then(strip),
|
|
119
|
+
new RegExp(`<title>${title}</title>`),
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
test("redirects the legacy home and the unauthenticated account", async () => {
|
|
125
|
+
const legacy = await request("/home");
|
|
126
|
+
assert.equal(legacy.status, 301);
|
|
127
|
+
assert.equal(legacy.headers.get("location"), "/");
|
|
128
|
+
const account = await request("/account");
|
|
129
|
+
assert.equal(account.status, 302);
|
|
130
|
+
assert.equal(account.headers.get("location"), "/login?from=%2Faccount");
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
test("renders the 404 page outside the top bar", async () => {
|
|
134
|
+
const html = await (await request("/missing")).text().then(strip);
|
|
135
|
+
assert.match(html, /<h1>Page not found<\/h1>/);
|
|
136
|
+
assert.doesNotMatch(html, /top-bar/);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
test("serves the sitemap, the icons and the stylesheet", async () => {
|
|
140
|
+
const sitemap = await (await request("/sitemap.xml")).text().then(strip);
|
|
141
|
+
assert.equal(sitemap.match(/<url>/g).length, <%= 5 + (forms ? 1 : 0) + (appShell ? 3 : 0) %>);
|
|
142
|
+
assert.match(sitemap, /<loc>[^<]*\/guides\/router-core<\/loc>/);
|
|
143
|
+
assert.match(sitemap, /<priority>0.3<\/priority>/);
|
|
144
|
+
const icon = await request("/icons/plus.svg");
|
|
145
|
+
assert.equal(icon.status, 200);
|
|
146
|
+
assert.match(icon.headers.get("content-type"), /image\/svg\+xml/);
|
|
147
|
+
assert.equal((await request("/icons/..%2Fpackage.json")).status, 404);
|
|
148
|
+
assert.equal((await request("/icons/not-an-icon.svg")).status, 404);
|
|
149
|
+
const html = await (await request("/")).text().then(strip);
|
|
150
|
+
const css = html.match(/href="([^"]+\.css)"/);
|
|
151
|
+
assert.ok(css);
|
|
152
|
+
assert.equal((await request(css[1])).status, 200);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
test("renders the theme cookie's class on <html>", async () => {
|
|
156
|
+
const page = (cookie) =>
|
|
157
|
+
request("/", { headers: { cookie } }).then((response) =>
|
|
158
|
+
response.text().then(strip),
|
|
159
|
+
);
|
|
160
|
+
const [dark, light, invalid, none] = await Promise.all([
|
|
161
|
+
page("theme=dark"),
|
|
162
|
+
page("theme=light"),
|
|
163
|
+
page("theme=sepia"),
|
|
164
|
+
page(""),
|
|
165
|
+
]);
|
|
166
|
+
assert.match(dark, /class="app comfortable dark"/);
|
|
167
|
+
assert.match(light, /class="app comfortable light"/);
|
|
168
|
+
assert.match(invalid, /class="app comfortable"/);
|
|
169
|
+
assert.match(none, /class="app comfortable"/);
|
|
170
|
+
assert.match(dark, /<option value="dark" selected/);
|
|
171
|
+
});
|
|
172
|
+
<% if (intl) { -%>
|
|
173
|
+
|
|
174
|
+
test("negotiates the locale per request, with lang and dir", async () => {
|
|
175
|
+
const [fr, ar] = await Promise.all([
|
|
176
|
+
request("/", { headers: { "accept-language": "fr-CA,fr;q=0.9" } }).then(
|
|
177
|
+
(response) => response.text().then(strip),
|
|
178
|
+
),
|
|
179
|
+
request("/", {
|
|
180
|
+
headers: { cookie: "locale=ar", "accept-language": "fr" },
|
|
181
|
+
}).then((response) => response.text().then(strip)),
|
|
182
|
+
]);
|
|
183
|
+
assert.match(fr, /lang="fr" dir="ltr"/);
|
|
184
|
+
assert.match(fr, /<a aria-current="page" href="\/">Accueil<\/a>/);
|
|
185
|
+
assert.match(ar, /lang="ar" dir="rtl"/);
|
|
186
|
+
assert.doesNotMatch(ar, /Accueil/);
|
|
187
|
+
});
|
|
188
|
+
<% } -%>
|
|
189
|
+
|
|
190
|
+
test("marks the current page in the top bar", async () => {
|
|
191
|
+
const html = await (await request("/catalog")).text().then(strip);
|
|
192
|
+
assert.match(html, /<a aria-current="page" href="\/catalog">Catalog<\/a>/);
|
|
193
|
+
assert.match(html, /<a href="\/account\?auth=1">Demo sign-in<\/a>/);
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
test("server-renders the catalog's first page", async () => {
|
|
197
|
+
const html = await (await request("/catalog")).text().then(strip);
|
|
198
|
+
assert.match(html, /Signed in as <strong>Ada Lovelace<\/strong>/);
|
|
199
|
+
assert.match(html, /showing 4 of 6 products/);
|
|
200
|
+
assert.equal(html.match(/<article /g).length, 4);
|
|
201
|
+
assert.match(html, /\$1,899.00/);
|
|
202
|
+
assert.match(html, /More products are available./);
|
|
203
|
+
<% if (intl) { -%>
|
|
204
|
+
const french = await (
|
|
205
|
+
await request("/catalog", { headers: { cookie: "locale=fr" } })
|
|
206
|
+
)
|
|
207
|
+
.text()
|
|
208
|
+
.then(strip);
|
|
209
|
+
assert.match(french, /1\s899,00\s\$US/);
|
|
210
|
+
assert.match(french, /noté 4,7/);
|
|
211
|
+
<% } -%>
|
|
212
|
+
});
|
|
213
|
+
<% if (appShell) { -%>
|
|
214
|
+
|
|
215
|
+
test("renders the dashboard in the application shell", async () => {
|
|
216
|
+
const html = await (await request("/dashboard")).text().then(strip);
|
|
217
|
+
assert.match(html, /class="ds application-shell surface"/);
|
|
218
|
+
assert.match(html, /<main class="main" id="main-content">/);
|
|
219
|
+
assert.match(html, /href="#main-content">Skip to main content</);
|
|
220
|
+
assert.match(html, /class="ds side-navigation"/);
|
|
221
|
+
assert.match(
|
|
222
|
+
html,
|
|
223
|
+
/<a[^>]*(aria-current="page"[^>]*href="\/dashboard"|href="\/dashboard"[^>]*aria-current="page")[^>]*>\s*<span class="start">/,
|
|
224
|
+
);
|
|
225
|
+
assert.match(
|
|
226
|
+
html,
|
|
227
|
+
/<span class="link" aria-current="page">Overview<\/span>/,
|
|
228
|
+
);
|
|
229
|
+
assert.match(html, /2 minutes ago/);
|
|
230
|
+
assert.match(html, /2.4 TB/);
|
|
231
|
+
<% if (intl) { -%>
|
|
232
|
+
const french = await (
|
|
233
|
+
await request("/dashboard", { headers: { cookie: "locale=fr" } })
|
|
234
|
+
)
|
|
235
|
+
.text()
|
|
236
|
+
.then(strip);
|
|
237
|
+
assert.match(french, /il y a 2 minutes/);
|
|
238
|
+
assert.match(french, /hier/);
|
|
239
|
+
<% } -%>
|
|
240
|
+
});
|
|
241
|
+
<% } -%>
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
describe("the theme<% if (intl) { %> and language<% } %> without JavaScript", () => {
|
|
245
|
+
test("/preferences stores the theme cookie and the next render has its class", async () => {
|
|
246
|
+
const response = await post("/preferences", "theme=dark", {
|
|
247
|
+
referer: `${base}/catalog`,
|
|
248
|
+
});
|
|
249
|
+
assert.equal(response.status, 303);
|
|
250
|
+
assert.equal(response.headers.get("location"), `${base}/catalog`);
|
|
251
|
+
const cookie = response.headers.get("set-cookie");
|
|
252
|
+
assert.match(cookie, /^theme=dark; /);
|
|
253
|
+
assert.match(cookie, /Path=\//);
|
|
254
|
+
assert.match(cookie, /Max-Age=31536000/);
|
|
255
|
+
assert.match(cookie, /SameSite=Lax/);
|
|
256
|
+
assert.doesNotMatch(cookie, /HttpOnly/i);
|
|
257
|
+
const next = await (
|
|
258
|
+
await request("/catalog", { headers: { cookie: "theme=dark" } })
|
|
259
|
+
)
|
|
260
|
+
.text()
|
|
261
|
+
.then(strip);
|
|
262
|
+
assert.match(next, /class="app comfortable dark"/);
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
test("/preferences clears the cookie for system", async () => {
|
|
266
|
+
const response = await post("/preferences", "theme=system");
|
|
267
|
+
assert.equal(response.status, 303);
|
|
268
|
+
assert.match(response.headers.get("set-cookie"), /^theme=; .*Max-Age=0/);
|
|
269
|
+
});
|
|
270
|
+
<% if (intl) { -%>
|
|
271
|
+
|
|
272
|
+
test("/language stores the locale cookie and the next render has lang and dir", async () => {
|
|
273
|
+
const response = await post("/language", "locale=ar", {
|
|
274
|
+
referer: `${base}/`,
|
|
275
|
+
});
|
|
276
|
+
assert.equal(response.status, 303);
|
|
277
|
+
const cookie = response.headers.get("set-cookie");
|
|
278
|
+
assert.match(cookie, /^locale=ar; /);
|
|
279
|
+
assert.match(cookie, /Max-Age=31536000/);
|
|
280
|
+
assert.match(cookie, /SameSite=Lax/);
|
|
281
|
+
assert.doesNotMatch(cookie, /HttpOnly/i);
|
|
282
|
+
const next = await (
|
|
283
|
+
await request("/", { headers: { cookie: "locale=ar" } })
|
|
284
|
+
)
|
|
285
|
+
.text()
|
|
286
|
+
.then(strip);
|
|
287
|
+
assert.match(next, /lang="ar" dir="rtl"/);
|
|
288
|
+
assert.equal(
|
|
289
|
+
(await post("/language", "locale=pt")).headers.get("set-cookie"),
|
|
290
|
+
null,
|
|
291
|
+
);
|
|
292
|
+
});
|
|
293
|
+
<% } -%>
|
|
294
|
+
|
|
295
|
+
test("<%= intl ? "both return" : "it returns" %> only to this origin", async () => {
|
|
296
|
+
<% if (intl) { -%>
|
|
297
|
+
for (const [endpoint, body] of [
|
|
298
|
+
["/preferences", "theme=dark"],
|
|
299
|
+
["/language", "locale=fr"],
|
|
300
|
+
]) {
|
|
301
|
+
<% } else { -%>
|
|
302
|
+
for (const [endpoint, body] of [["/preferences", "theme=dark"]]) {
|
|
303
|
+
<% } -%>
|
|
304
|
+
for (const [referer, expected] of [
|
|
305
|
+
[`${base}/catalog?x=1`, `${base}/catalog?x=1`],
|
|
306
|
+
["https://evil.example/", "/"],
|
|
307
|
+
["not a URL", "/"],
|
|
308
|
+
]) {
|
|
309
|
+
const response = await post(endpoint, body, { referer });
|
|
310
|
+
assert.equal(response.status, 303);
|
|
311
|
+
assert.equal(response.headers.get("location"), expected);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
test("the Apply button<%= intl ? "s post the forms" : " posts the form" %> in a browser without JavaScript", async () => {
|
|
317
|
+
await withPage({ javaScriptEnabled: false }, async (page) => {
|
|
318
|
+
await page.goto(`${base}/catalog`);
|
|
319
|
+
const apply = page.getByRole("button", { name: "Apply" });
|
|
320
|
+
assert.equal(await apply.count(), <%= intl ? 2 : 1 %>);
|
|
321
|
+
await page.getByLabel("Color theme").selectOption("dark");
|
|
322
|
+
await apply.first().click();
|
|
323
|
+
await page.waitForURL(`${base}/catalog`);
|
|
324
|
+
assert.equal(await htmlClass(page), "app comfortable dark");
|
|
325
|
+
<% if (intl) { -%>
|
|
326
|
+
await page.getByLabel("Language").selectOption("ar");
|
|
327
|
+
await page.getByRole("button", { name: "Apply" }).last().click();
|
|
328
|
+
await page.waitForURL(`${base}/catalog`);
|
|
329
|
+
assert.equal(await page.locator("html").getAttribute("lang"), "ar");
|
|
330
|
+
assert.equal(await page.locator("html").getAttribute("dir"), "rtl");
|
|
331
|
+
assert.equal(await htmlClass(page), "app comfortable dark");
|
|
332
|
+
<% } -%>
|
|
333
|
+
});
|
|
334
|
+
});
|
|
90
335
|
});
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
336
|
+
|
|
337
|
+
describe("the theme<% if (intl) { %> and language<% } %> with JavaScript", () => {
|
|
338
|
+
test("a theme applies on select, writes the cookie and shows no Apply", async () => {
|
|
339
|
+
await withPage({}, async (page, context) => {
|
|
340
|
+
await open(page, "/");
|
|
341
|
+
assert.equal(
|
|
342
|
+
await page.getByRole("button", { name: "Apply" }).count(),
|
|
343
|
+
0,
|
|
344
|
+
);
|
|
345
|
+
await page.getByLabel("Color theme").selectOption("dark");
|
|
346
|
+
assert.equal(await htmlClass(page), "app comfortable dark");
|
|
347
|
+
const cookie = (await context.cookies()).find(
|
|
348
|
+
(entry) => entry.name === "theme",
|
|
349
|
+
);
|
|
350
|
+
assert.equal(cookie?.value, "dark");
|
|
351
|
+
assert.equal(cookie?.httpOnly, false);
|
|
352
|
+
await page.reload();
|
|
353
|
+
assert.equal(await htmlClass(page), "app comfortable dark");
|
|
354
|
+
assert.equal(await page.getByLabel("Color theme").inputValue(), "dark");
|
|
355
|
+
await page.getByLabel("Color theme").selectOption("system");
|
|
356
|
+
assert.equal(await htmlClass(page), "app comfortable");
|
|
357
|
+
assert.equal(
|
|
358
|
+
(await context.cookies()).some((entry) => entry.name === "theme"),
|
|
359
|
+
false,
|
|
360
|
+
);
|
|
361
|
+
});
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
test("a theme cookie the server set can be overwritten by the page", async () => {
|
|
365
|
+
await withPage({}, async (page) => {
|
|
366
|
+
await page.request.post(`${base}/preferences`, {
|
|
367
|
+
form: { theme: "dark" },
|
|
368
|
+
headers: { origin: base },
|
|
369
|
+
maxRedirects: 0,
|
|
370
|
+
});
|
|
371
|
+
await open(page, "/");
|
|
372
|
+
assert.equal(await htmlClass(page), "app comfortable dark");
|
|
373
|
+
await page.getByLabel("Color theme").selectOption("light");
|
|
374
|
+
await page.reload();
|
|
375
|
+
assert.equal(await htmlClass(page), "app comfortable light");
|
|
376
|
+
});
|
|
377
|
+
});
|
|
378
|
+
<% if (intl) { -%>
|
|
379
|
+
|
|
380
|
+
test("a language applies on select: every string, lang, dir and the cookie", async () => {
|
|
381
|
+
await withPage({}, async (page, context) => {
|
|
382
|
+
await open(page, "/");
|
|
383
|
+
await page.getByLabel("Language").selectOption("fr");
|
|
384
|
+
await page.getByRole("link", { name: "Accueil" }).first().waitFor();
|
|
385
|
+
assert.equal(await page.locator("html").getAttribute("lang"), "fr");
|
|
386
|
+
await page.getByLabel("Langue").selectOption("ar");
|
|
387
|
+
await page.waitForFunction(() => document.documentElement.dir === "rtl");
|
|
388
|
+
assert.equal(
|
|
389
|
+
(await context.cookies()).find((entry) => entry.name === "locale")
|
|
390
|
+
?.value,
|
|
391
|
+
"ar",
|
|
392
|
+
);
|
|
393
|
+
assert.equal(
|
|
394
|
+
await page.getByRole("button", { name: /Apply|تطبيق/ }).count(),
|
|
395
|
+
0,
|
|
396
|
+
);
|
|
397
|
+
await page.reload();
|
|
398
|
+
assert.equal(await page.locator("html").getAttribute("lang"), "ar");
|
|
399
|
+
});
|
|
400
|
+
});
|
|
401
|
+
<% } -%>
|
|
402
|
+
<% if (intl) { -%>
|
|
403
|
+
|
|
404
|
+
test("the language selector lists each language by its endonym", async () => {
|
|
405
|
+
await withPage({}, async (page) => {
|
|
406
|
+
await open(page, "/");
|
|
407
|
+
const options = page.getByLabel("Language").locator("option");
|
|
408
|
+
assert.deepEqual(await options.allTextContents(), [
|
|
409
|
+
"English",
|
|
410
|
+
"français",
|
|
411
|
+
"العربية",
|
|
412
|
+
]);
|
|
413
|
+
assert.deepEqual(
|
|
414
|
+
await options.evaluateAll((elements) =>
|
|
415
|
+
elements.map((element) => element.lang),
|
|
416
|
+
),
|
|
417
|
+
["en", "fr", "ar"],
|
|
418
|
+
);
|
|
419
|
+
});
|
|
420
|
+
});
|
|
421
|
+
<% } -%>
|
|
137
422
|
});
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
423
|
+
|
|
424
|
+
describe("the pages", () => {
|
|
425
|
+
test("the home page streams its delayed content in", async () => {
|
|
426
|
+
await withPage({}, async (page) => {
|
|
427
|
+
await page.goto(base);
|
|
428
|
+
await page.getByText("Streamed in after a delay").waitFor();
|
|
429
|
+
assert.equal(
|
|
430
|
+
await page.locator("code.ds.inline-code").first().textContent(),
|
|
431
|
+
"ExampleComponent.stories.svelte",
|
|
432
|
+
);
|
|
433
|
+
});
|
|
434
|
+
});
|
|
435
|
+
|
|
436
|
+
test("client navigation to the account page respects the demo guard", async () => {
|
|
437
|
+
await withPage({}, async (page) => {
|
|
438
|
+
await open(page, "/");
|
|
439
|
+
await page.evaluate(() => {
|
|
440
|
+
const link = document.createElement("a");
|
|
441
|
+
link.href = "/account";
|
|
442
|
+
link.textContent = "Protected";
|
|
443
|
+
document.querySelector("main")?.append(link);
|
|
444
|
+
});
|
|
445
|
+
await page.getByRole("link", { name: "Protected" }).click();
|
|
446
|
+
await page.waitForURL("**/login?from=%2Faccount");
|
|
447
|
+
await page.getByText("You will be redirected to /account").waitFor();
|
|
448
|
+
await page.getByRole("link", { name: "Demo sign-in" }).click();
|
|
449
|
+
await page.getByRole("heading", { name: "Account" }).waitFor();
|
|
450
|
+
});
|
|
451
|
+
});
|
|
452
|
+
<% if (forms) { -%>
|
|
453
|
+
|
|
454
|
+
test("the contact form checks the email before it posts, then posts to the action", async () => {
|
|
455
|
+
await withPage({}, async (page) => {
|
|
456
|
+
const posts = [];
|
|
457
|
+
page.on("request", (request) => {
|
|
458
|
+
if (request.method() === "POST") posts.push(request.url());
|
|
459
|
+
});
|
|
460
|
+
const logged = [];
|
|
461
|
+
page.on("console", async (message) => {
|
|
462
|
+
if (message.text().startsWith("Form submitted:"))
|
|
463
|
+
logged.push(await message.args()[1].jsonValue());
|
|
464
|
+
});
|
|
465
|
+
await open(page, "/contact");
|
|
466
|
+
await page.getByLabel("Full name").fill("Ada");
|
|
467
|
+
await page.getByLabel("Email address").fill(" ");
|
|
468
|
+
await page.getByLabel("Message").fill("Hello");
|
|
469
|
+
await page.getByRole("button", { name: "Send message" }).click();
|
|
470
|
+
await page.getByText("Email is required").waitFor();
|
|
471
|
+
assert.deepEqual(posts, []);
|
|
472
|
+
await page.getByLabel("Email address").fill("ada@example.com");
|
|
473
|
+
const answer = page.waitForResponse(
|
|
474
|
+
(response) => response.request().method() === "POST",
|
|
475
|
+
);
|
|
476
|
+
await page.getByRole("button", { name: "Send message" }).click();
|
|
477
|
+
assert.equal((await answer).status(), 200);
|
|
478
|
+
for (let attempt = 0; attempt < 50 && logged.length === 0; attempt++)
|
|
479
|
+
await page.waitForTimeout(100);
|
|
480
|
+
assert.deepEqual(posts, [`${base}/contact`]);
|
|
481
|
+
assert.deepEqual(logged, [
|
|
482
|
+
{
|
|
483
|
+
name: "Ada",
|
|
484
|
+
email: "ada@example.com",
|
|
485
|
+
subject: "general",
|
|
486
|
+
message: "Hello",
|
|
487
|
+
},
|
|
488
|
+
]);
|
|
489
|
+
assert.equal(page.url(), `${base}/contact`);
|
|
490
|
+
assert.equal(await page.getByLabel("Full name").inputValue(), "Ada");
|
|
491
|
+
assert.equal(await page.getByText("Email is required").count(), 0);
|
|
492
|
+
});
|
|
493
|
+
});
|
|
494
|
+
<% } -%>
|
|
495
|
+
<% if (forms) { -%>
|
|
496
|
+
|
|
497
|
+
test("the contact form validates without JavaScript", async () => {
|
|
498
|
+
const response = await post("/contact", "name=Ada&email=&subject=support", {
|
|
499
|
+
accept: "text/html",
|
|
500
|
+
});
|
|
501
|
+
assert.equal(response.status, 400);
|
|
502
|
+
const html = await response.text().then(strip);
|
|
503
|
+
assert.match(html, /Email is required/);
|
|
504
|
+
assert.match(html, /value="Ada"/);
|
|
505
|
+
const valid = await post("/contact", "name=Ada&email=ada%40example.com", {
|
|
506
|
+
accept: "text/html",
|
|
507
|
+
});
|
|
508
|
+
assert.equal(valid.status, 200);
|
|
509
|
+
});
|
|
510
|
+
|
|
511
|
+
test("the contact form posts to the action in a browser without JavaScript", async () => {
|
|
512
|
+
await withPage({ javaScriptEnabled: false }, async (page) => {
|
|
513
|
+
await page.goto(`${base}/contact`);
|
|
514
|
+
await page.getByLabel("Full name").fill("Ada");
|
|
515
|
+
await page.getByLabel("Email address").fill(" ");
|
|
516
|
+
await page.getByLabel("Subject").selectOption("support");
|
|
517
|
+
await page.getByLabel("Message").fill("Hello");
|
|
518
|
+
await page.getByRole("button", { name: "Send message" }).click();
|
|
519
|
+
await page.getByText("Email is required").waitFor();
|
|
520
|
+
assert.equal(await page.getByLabel("Full name").inputValue(), "Ada");
|
|
521
|
+
assert.equal(await page.getByLabel("Subject").inputValue(), "support");
|
|
522
|
+
await page.getByLabel("Email address").fill("ada@example.com");
|
|
523
|
+
await page.getByRole("button", { name: "Send message" }).click();
|
|
524
|
+
await page.waitForLoadState("load");
|
|
525
|
+
assert.equal(await page.getByText("Email is required").count(), 0);
|
|
526
|
+
assert.equal(
|
|
527
|
+
await page.getByLabel("Email address").inputValue(),
|
|
528
|
+
"ada@example.com",
|
|
529
|
+
);
|
|
530
|
+
assert.equal(await page.getByLabel("Message").inputValue(), "Hello");
|
|
531
|
+
});
|
|
532
|
+
});
|
|
533
|
+
<% } -%>
|
|
534
|
+
<% if (appShell) { -%>
|
|
535
|
+
|
|
536
|
+
test("Create instance on the overview navigates to the instances", async () => {
|
|
537
|
+
await withPage({}, async (page) => {
|
|
538
|
+
await open(page, "/dashboard");
|
|
539
|
+
await page.evaluate(() => {
|
|
540
|
+
window.__sameDocument = true;
|
|
541
|
+
});
|
|
542
|
+
await page.getByRole("button", { name: "Create instance" }).click();
|
|
543
|
+
await page.waitForURL(`${base}/dashboard/instances`);
|
|
544
|
+
assert.equal(await page.evaluate(() => window.__sameDocument), true);
|
|
545
|
+
await page
|
|
546
|
+
.getByRole("navigation", { name: "Breadcrumb" })
|
|
547
|
+
.getByText("Instances")
|
|
548
|
+
.waitFor();
|
|
549
|
+
});
|
|
550
|
+
});
|
|
551
|
+
<% } -%>
|
|
552
|
+
<% if (appShell && forms) { -%>
|
|
553
|
+
|
|
554
|
+
test("the instances page selects, creates and closes its panel", async () => {
|
|
555
|
+
await withPage({}, async (page) => {
|
|
556
|
+
await open(page, "/dashboard/instances");
|
|
557
|
+
await page.getByText("Select an instance to see its details.").waitFor();
|
|
558
|
+
const details = page.getByRole("button", {
|
|
559
|
+
name: "Show details of db-01",
|
|
560
|
+
});
|
|
561
|
+
await details.click();
|
|
562
|
+
assert.equal(await details.getAttribute("aria-pressed"), "true");
|
|
563
|
+
await page.getByRole("heading", { name: "db-01" }).waitFor();
|
|
564
|
+
await page.getByText("16 GiB").waitFor();
|
|
565
|
+
assert.equal(page.url(), `${base}/dashboard/instances`);
|
|
566
|
+
|
|
567
|
+
const create = page
|
|
568
|
+
.locator("header")
|
|
569
|
+
.getByRole("button", { name: "Create instance" });
|
|
570
|
+
await create.click();
|
|
571
|
+
const panel = page.getByRole("dialog", { name: "Create instance" });
|
|
572
|
+
await panel.waitFor();
|
|
573
|
+
assert.equal(
|
|
574
|
+
await panel.getByLabel("Instance name").inputValue(),
|
|
575
|
+
"web-03",
|
|
576
|
+
);
|
|
577
|
+
assert.equal(
|
|
578
|
+
await panel.getByLabel("Ubuntu release").inputValue(),
|
|
579
|
+
"noble",
|
|
580
|
+
);
|
|
581
|
+
await page.keyboard.press("Escape");
|
|
582
|
+
await panel.waitFor({ state: "hidden" });
|
|
583
|
+
assert.equal(
|
|
584
|
+
await create.evaluate((element) => element === document.activeElement),
|
|
585
|
+
true,
|
|
586
|
+
);
|
|
587
|
+
|
|
588
|
+
await create.click();
|
|
589
|
+
await panel.getByLabel("Instance name").fill("web-04");
|
|
590
|
+
await panel.getByLabel("Ubuntu release").selectOption("jammy");
|
|
591
|
+
await panel.getByRole("button", { name: "Create instance" }).click();
|
|
592
|
+
await panel.waitFor({ state: "hidden" });
|
|
593
|
+
await page.getByRole("heading", { name: "web-04" }).waitFor();
|
|
594
|
+
assert.equal(await page.locator("h1 .ds.badge").textContent(), "7");
|
|
595
|
+
assert.equal(
|
|
596
|
+
await page
|
|
597
|
+
.getByRole("button", { name: "Show details of web-04" })
|
|
598
|
+
.getAttribute("aria-pressed"),
|
|
599
|
+
"true",
|
|
600
|
+
);
|
|
601
|
+
await page.getByText("Starting", { exact: true }).waitFor();
|
|
602
|
+
});
|
|
603
|
+
});
|
|
604
|
+
<% } -%>
|
|
605
|
+
<% if (appShell && forms) { -%>
|
|
606
|
+
|
|
607
|
+
test("the instances page works without JavaScript", async () => {
|
|
608
|
+
const selected = await (
|
|
609
|
+
await request("/dashboard/instances?selected=db-01")
|
|
610
|
+
)
|
|
611
|
+
.text()
|
|
612
|
+
.then(strip);
|
|
613
|
+
assert.match(selected, /<h2 id="details-title">db-01<\/h2>/);
|
|
614
|
+
assert.match(selected, /aria-pressed="true"/);
|
|
615
|
+
assert.match(
|
|
616
|
+
await (await request("/dashboard/instances?create=1")).text().then(strip),
|
|
617
|
+
/<dialog[^>]* open/,
|
|
618
|
+
);
|
|
619
|
+
const created = await post(
|
|
620
|
+
"/dashboard/instances?/create",
|
|
621
|
+
"instance_name=web-09&release=focal",
|
|
622
|
+
{ accept: "text/html" },
|
|
623
|
+
);
|
|
624
|
+
assert.equal(created.status, 200);
|
|
625
|
+
const html = await created.text().then(strip);
|
|
626
|
+
assert.match(html, /<div class="ds tile-header">web-09<\/div>/);
|
|
627
|
+
assert.match(html, /<h2 id="details-title">web-09<\/h2>/);
|
|
628
|
+
assert.match(html, /Ubuntu 20.04 LTS/);
|
|
629
|
+
const invalid = await post(
|
|
630
|
+
"/dashboard/instances?/create",
|
|
631
|
+
"instance_name=&release=noble",
|
|
632
|
+
{ accept: "text/html" },
|
|
633
|
+
);
|
|
634
|
+
assert.equal(invalid.status, 400);
|
|
635
|
+
assert.match(await invalid.text().then(strip), /Instance name is required/);
|
|
636
|
+
});
|
|
637
|
+
<% } -%>
|
|
638
|
+
<% if (appShell) { -%>
|
|
639
|
+
|
|
640
|
+
test("the settings page confirms the deletion in a modal", async () => {
|
|
641
|
+
await withPage({}, async (page) => {
|
|
642
|
+
<% if (forms) { -%>
|
|
643
|
+
const logs = [];
|
|
644
|
+
page.on("console", (message) => logs.push(message.text()));
|
|
645
|
+
await open(page, "/dashboard/settings");
|
|
646
|
+
assert.equal(
|
|
647
|
+
await page.getByLabel("Default bridge").inputValue(),
|
|
648
|
+
"lxdbr0",
|
|
649
|
+
);
|
|
650
|
+
assert.equal(
|
|
651
|
+
await page.getByLabel("Maximum instances").inputValue(),
|
|
652
|
+
"50",
|
|
653
|
+
);
|
|
654
|
+
await page.getByRole("button", { name: "Save changes" }).click();
|
|
655
|
+
assert.ok(logs.some((line) => line.startsWith("Settings saved:")));
|
|
656
|
+
<% } else { -%>
|
|
657
|
+
await open(page, "/dashboard/settings");
|
|
658
|
+
<% } -%>
|
|
659
|
+
await page.getByRole("button", { name: "Delete project" }).click();
|
|
660
|
+
const dialog = page.getByRole("dialog", { name: "Delete project?" });
|
|
661
|
+
await dialog.waitFor();
|
|
662
|
+
await dialog.getByText("default project").waitFor();
|
|
663
|
+
await dialog.getByRole("button", { name: "Cancel" }).click();
|
|
664
|
+
await dialog.waitFor({ state: "hidden" });
|
|
665
|
+
});
|
|
666
|
+
});
|
|
667
|
+
<% } -%>
|
|
668
|
+
<% if (appShell && forms) { -%>
|
|
669
|
+
|
|
670
|
+
test("the settings form posts without JavaScript", async () => {
|
|
671
|
+
const response = await post(
|
|
672
|
+
"/dashboard/settings?/save",
|
|
673
|
+
"bridge=ovn-1&max_instances=10",
|
|
674
|
+
{ accept: "text/html" },
|
|
675
|
+
);
|
|
676
|
+
assert.equal(response.status, 200);
|
|
677
|
+
});
|
|
678
|
+
<% } -%>
|
|
679
|
+
<% if (appShell) { -%>
|
|
680
|
+
|
|
681
|
+
test("the side navigation follows the page and discloses Help", async () => {
|
|
682
|
+
await withPage({}, async (page) => {
|
|
683
|
+
await open(page, "/dashboard");
|
|
684
|
+
const navigation = page.getByRole("navigation", { name: "Dashboard" });
|
|
685
|
+
await navigation.getByRole("link", { name: "Settings" }).click();
|
|
686
|
+
await page.waitForURL(`${base}/dashboard/settings`);
|
|
687
|
+
assert.equal(
|
|
688
|
+
await navigation
|
|
689
|
+
.getByRole("link", { name: "Settings" })
|
|
690
|
+
.getAttribute("aria-current"),
|
|
691
|
+
"page",
|
|
692
|
+
);
|
|
693
|
+
assert.equal(
|
|
694
|
+
await navigation
|
|
695
|
+
.getByText("Networks")
|
|
696
|
+
.evaluate((element) => element.closest("a")),
|
|
697
|
+
null,
|
|
698
|
+
);
|
|
699
|
+
await navigation.getByText("Help").click();
|
|
700
|
+
assert.equal(
|
|
701
|
+
await navigation
|
|
702
|
+
.getByRole("link", { name: "Legal information" })
|
|
703
|
+
.getAttribute("href"),
|
|
704
|
+
"https://ubuntu.com/legal",
|
|
705
|
+
);
|
|
706
|
+
});
|
|
707
|
+
});
|
|
708
|
+
<% } -%>
|
|
709
|
+
<% if (appShell) { -%>
|
|
710
|
+
|
|
711
|
+
test("the side navigation collapses from its toggle and Ctrl+B", async () => {
|
|
712
|
+
await withPage({}, async (page) => {
|
|
713
|
+
await open(page, "/dashboard");
|
|
714
|
+
const sideNavigation = page.locator(".ds.side-navigation");
|
|
715
|
+
assert.equal(await sideNavigation.getAttribute("data-expanded"), "true");
|
|
716
|
+
await page.getByRole("button", { name: "Collapse navigation" }).click();
|
|
717
|
+
assert.equal(await sideNavigation.getAttribute("data-expanded"), "false");
|
|
718
|
+
await page.getByRole("button", { name: "Expand navigation" }).waitFor();
|
|
719
|
+
await page.keyboard.press("Control+b");
|
|
720
|
+
assert.equal(await sideNavigation.getAttribute("data-expanded"), "true");
|
|
721
|
+
await page.keyboard.press("Control+b");
|
|
722
|
+
assert.equal(await sideNavigation.getAttribute("data-expanded"), "false");
|
|
723
|
+
});
|
|
724
|
+
});
|
|
725
|
+
<% } -%>
|
|
726
|
+
<% if (appShell) { -%>
|
|
727
|
+
|
|
728
|
+
test("the side navigation is a menu on a small screen", async () => {
|
|
729
|
+
await withPage({ viewport: { width: 400, height: 800 } }, async (page) => {
|
|
730
|
+
await open(page, "/dashboard");
|
|
731
|
+
const sideNavigation = page.locator(".ds.side-navigation");
|
|
732
|
+
await page.waitForFunction(
|
|
733
|
+
() =>
|
|
734
|
+
document
|
|
735
|
+
.querySelector(".ds.side-navigation")
|
|
736
|
+
?.getAttribute("data-expanded") === "false",
|
|
737
|
+
);
|
|
738
|
+
const menu = page.getByRole("button", { name: "Expand navigation" });
|
|
739
|
+
assert.equal((await menu.textContent())?.trim(), "Menu");
|
|
740
|
+
await menu.click();
|
|
741
|
+
assert.equal(
|
|
742
|
+
(
|
|
743
|
+
await page
|
|
744
|
+
.getByRole("button", { name: "Collapse navigation" })
|
|
745
|
+
.textContent()
|
|
746
|
+
)?.trim(),
|
|
747
|
+
"Close menu",
|
|
748
|
+
);
|
|
749
|
+
assert.equal(await sideNavigation.getAttribute("data-expanded"), "true");
|
|
750
|
+
await page
|
|
751
|
+
.getByRole("navigation", { name: "Dashboard" })
|
|
752
|
+
.getByRole("link", { name: "Instances" })
|
|
753
|
+
.click();
|
|
754
|
+
await page.waitForURL(`${base}/dashboard/instances`);
|
|
755
|
+
});
|
|
756
|
+
});
|
|
757
|
+
<% } -%>
|
|
141
758
|
});
|
|
142
|
-
<% } %>
|