diff --git a/ui/package.json b/ui/package.json index d9b128881..7a1e19776 100644 --- a/ui/package.json +++ b/ui/package.json @@ -12,10 +12,10 @@ "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch", "lint": "prettier --check . && eslint .", "format": "prettier --write .", - "test:local-auth": "playwright test tests/local-auth.spec.ts --config=playwright.config.local-auth.ts", - "test:reconnect": "playwright test tests/reconnect.spec.ts --config=playwright.reconnect.config.ts", - "test:e2e": "playwright test", - "test:e2e-in-cluster": "playwright test --config=playwright.config.in-cluster.ts", + "test:local-auth": "TEST_CFG=localAuth playwright test", + "test:reconnect": "TEST_CFG=reconnect playwright test", + "test:e2e": "TEST_CFG=default playwright test", + "test:e2e-in-cluster": "TEST_CFG=inCluster playwright test", "test:install": "playwright install", "test:unit": "vitest run" }, diff --git a/ui/playwright.config.in-cluster.ts b/ui/playwright.config.in-cluster.ts deleted file mode 100644 index d325d0001..000000000 --- a/ui/playwright.config.in-cluster.ts +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2024 Defense Unicorns -// SPDX-License-Identifier: AGPL-3.0-or-later OR LicenseRef-Defense-Unicorns-Commercial - -import { defineConfig } from '@playwright/test' - -const protocol = 'https' -const host = 'runtime.admin.uds.dev' - -export default defineConfig({ - globalSetup: './tests/global-setup', - timeout: 10 * 1000, - testDir: 'tests', - /* Run tests in files in parallel */ - fullyParallel: true, - retries: process.env.CI ? 2 : 1, - testMatch: /^(?!.*local-auth|.*reconnect)(.+\.)?(test|spec)\.[jt]s$/, - use: { - baseURL: `${protocol}://${host}/`, - storageState: './tests/state.json', - }, -}) diff --git a/ui/playwright.config.local-auth.ts b/ui/playwright.config.local-auth.ts deleted file mode 100644 index 663d378c4..000000000 --- a/ui/playwright.config.local-auth.ts +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2024 Defense Unicorns -// SPDX-License-Identifier: AGPL-3.0-or-later OR LicenseRef-Defense-Unicorns-Commercial - -import { defineConfig } from '@playwright/test' -import { loadEnv } from 'vite' - -const { VITE_PORT_ENV } = loadEnv('dev', process.cwd()) -const port = VITE_PORT_ENV ?? '8443' - -export default defineConfig({ - timeout: 60 * 1000, - testDir: 'tests', - fullyParallel: false, - retries: process.env.CI ? 2 : 1, - testMatch: /^(?!.*in-cluster|.*reconnect)(.+\.)?(test|spec)\.[jt]s$/, - use: { - baseURL: `https://runtime-local.uds.dev:${port}/`, - }, -}) - -export { port } diff --git a/ui/playwright.config.ts b/ui/playwright.config.ts index 4cb96c422..0fbab79b5 100644 --- a/ui/playwright.config.ts +++ b/ui/playwright.config.ts @@ -1,17 +1,22 @@ // Copyright 2024 Defense Unicorns // SPDX-License-Identifier: AGPL-3.0-or-later OR LicenseRef-Defense-Unicorns-Commercial -import { defineConfig } from '@playwright/test' +import { defineConfig, PlaywrightTestConfig } from '@playwright/test' import { loadEnv } from 'vite' const { VITE_PORT_ENV } = loadEnv('dev', process.cwd()) +type TestConfig = keyof typeof configs +const TEST_CONFIG: TestConfig = (process.env.TEST_CFG as TestConfig) || 'default' + // use port 8443 because by default we use TLS when running locally const port = VITE_PORT_ENV ?? '8443' const protocol = 'https' const host = 'runtime-local.uds.dev' -export default defineConfig({ +// For all default E2E tests +const defaultConfig: PlaywrightTestConfig = { + name: 'default', webServer: { command: '../build/uds-runtime', url: `${protocol}://${host}:${port}`, @@ -27,6 +32,64 @@ export default defineConfig({ use: { baseURL: `${protocol}://${host}:${port}/`, }, -}) +} + +// For testing reconnecting to the cluster +const reconnect: PlaywrightTestConfig = { + name: 'reconnect', + webServer: { + command: '../build/uds-runtime', + url: `${protocol}://${host}:${port}`, + reuseExistingServer: !process.env.CI, + env: { LOCAL_AUTH_ENABLED: 'false' }, + }, + timeout: 10 * 1000, + testDir: 'tests', + fullyParallel: false, + retries: process.env.CI ? 2 : 1, + testMatch: 'reconnect.spec.ts', + use: { + baseURL: `https://runtime-local.uds.dev:${port}/`, + }, +} + +// For testing local auth only +const localAuth: PlaywrightTestConfig = { + name: 'local-auth', + timeout: 60 * 1000, + testDir: 'tests', + fullyParallel: false, + retries: process.env.CI ? 2 : 1, + testMatch: 'local-auth.spec.ts', + use: { + baseURL: `https://runtime-local.uds.dev:${port}/`, + }, +} + +// For running E2E tests against Runtime in-cluster +const inCluster: PlaywrightTestConfig = { + name: 'in-cluster', + globalSetup: './tests/global-setup', + timeout: 10 * 1000, + testDir: 'tests', + /* Run tests in files in parallel */ + fullyParallel: true, + retries: process.env.CI ? 2 : 1, + testMatch: /^(?!.*local-auth|.*reconnect)(.+\.)?(test|spec)\.[jt]s$/, + use: { + baseURL: `${protocol}://runtime.admin.uds.dev/`, + storageState: './tests/state.json', + }, +} + +// Use configs object for selecting desired config based on TEST_CONFIG, which is set by caller script in package.json +const configs = { + default: defaultConfig, + localAuth, + inCluster, + reconnect, +} + +export default defineConfig({ ...configs[TEST_CONFIG] }) export { port } diff --git a/ui/playwright.reconnect.config.ts b/ui/playwright.reconnect.config.ts deleted file mode 100644 index bd5ca9766..000000000 --- a/ui/playwright.reconnect.config.ts +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2024 Defense Unicorns -// SPDX-License-Identifier: AGPL-3.0-or-later OR LicenseRef-Defense-Unicorns-Commercial - -import { defineConfig } from '@playwright/test' -import { loadEnv } from 'vite' - -const { VITE_PORT_ENV } = loadEnv('dev', process.cwd()) - -// use port 8443 because by default we use TLS when running locally -const port = VITE_PORT_ENV ?? '8443' -const protocol = 'https' -const host = 'runtime-local.uds.dev' - -export default defineConfig({ - webServer: { - command: '../build/uds-runtime', - url: `${protocol}://${host}:${port}`, - reuseExistingServer: !process.env.CI, - env: { LOCAL_AUTH_ENABLED: 'false' }, - }, - timeout: 10 * 1000, - testDir: 'tests', - fullyParallel: false, - retries: process.env.CI ? 2 : 1, - testMatch: 'reconnect.spec.ts', - use: { - baseURL: `https://runtime-local.uds.dev:${port}/`, - }, -}) - -export { port } diff --git a/ui/src/lib/features/k8s/networks/gateways/store.ts b/ui/src/lib/features/k8s/networks/gateways/store.ts index 47a3f0c74..bbf264234 100644 --- a/ui/src/lib/features/k8s/networks/gateways/store.ts +++ b/ui/src/lib/features/k8s/networks/gateways/store.ts @@ -24,7 +24,7 @@ interface Resource extends VirtualService { export type Columns = ColumnWrapper export function createStore(): ResourceStoreInterface { - const url = `/api/v1/resources/networks/gateways?fields=.metadata.name,.metadata.namespace,.metadata.creationTimestamp,.spec.servers` + const url = `/api/v1/resources/networks/gateways?fields=.metadata,.spec.servers` const transform = transformResource((r) => { const hosts = r.spec?.servers?.map((gateway) => gateway.hosts[0]) diff --git a/ui/src/lib/features/navigation/sidebar/component.svelte b/ui/src/lib/features/navigation/sidebar/component.svelte index c2705d0ef..706545950 100644 --- a/ui/src/lib/features/navigation/sidebar/component.svelte +++ b/ui/src/lib/features/navigation/sidebar/component.svelte @@ -43,6 +43,20 @@ return route }) } + + // If link was clicked, updating url, but path is a child route that is currently not renendered + // we need to toggle the submenu to show the child route + function updateOnLinkClicks(path: string) { + for (const route of routes) { + if (path.includes(route.path) && !toggleSubmenus[route.path]) { + toggleSubmenus[route.path] = true + } + } + } + + $: if ($page.url.pathname) { + updateOnLinkClicks($page.url.pathname) + }