diff --git a/client/web-sveltekit/.env b/client/web-sveltekit/.env index 87a5252303c..9d01e51baa3 100644 --- a/client/web-sveltekit/.env +++ b/client/web-sveltekit/.env @@ -1 +1,5 @@ PUBLIC_DOTCOM= +PUBLIC_CODY_ENABLED_ON_INSTANCE=true +PUBLIC_CODY_ENABLED_FOR_CURRENT_USER=true +PUBLIC_BATCH_CHANGES_ENABLED=true +PUBLIC_CODE_INSIGHTS_ENABLED=true diff --git a/client/web-sveltekit/.env.dotcom b/client/web-sveltekit/.env.dotcom index a71e18ed418..65ae7b2b3e3 100644 --- a/client/web-sveltekit/.env.dotcom +++ b/client/web-sveltekit/.env.dotcom @@ -1 +1,5 @@ PUBLIC_DOTCOM=true +PUBLIC_CODY_ENABLED_ON_INSTANCE=true +PUBLIC_CODY_ENABLED_FOR_CURRENT_USER=true +PUBLIC_BATCH_CHANGES_ENABLED= +PUBLIC_CODE_INSIGHTS_ENABLED= diff --git a/client/web-sveltekit/BUILD.bazel b/client/web-sveltekit/BUILD.bazel index d0f514e3823..1de41561055 100644 --- a/client/web-sveltekit/BUILD.bazel +++ b/client/web-sveltekit/BUILD.bazel @@ -324,6 +324,10 @@ svelte_check.svelte_check_test( args = [ "--tsconfig", "tsconfig.json", + "--compiler-warnings", + # missing-declaration is raised for our icon components. The Svelte compiler + # does not take into account ambient declarations (will be fixed in Svelte 5). + "missing-declaration:ignore", ], chdir = package_name(), data = SRCS + BUILD_DEPS + CONFIGS + [ diff --git a/client/web-sveltekit/package.json b/client/web-sveltekit/package.json index c9ce2192760..bb9b803529e 100644 --- a/client/web-sveltekit/package.json +++ b/client/web-sveltekit/package.json @@ -10,7 +10,7 @@ "build:watch": "vite build --watch", "preview": "vite preview", "install:browsers": "playwright install", - "test": "playwright test", + "test": "DISABLE_APP_ASSETS_MOCKING=true playwright test", "test:dev": "DISABLE_APP_ASSETS_MOCKING=true PORT=5173 playwright test --ui", "test:svelte": "vitest --run", "sync": "svelte-kit sync", diff --git a/client/web-sveltekit/playwright.config.ts b/client/web-sveltekit/playwright.config.ts index 022e457a087..1eec99e2ce3 100644 --- a/client/web-sveltekit/playwright.config.ts +++ b/client/web-sveltekit/playwright.config.ts @@ -5,6 +5,14 @@ const PORT = process.env.PORT ? Number(process.env.PORT) : 4173 const config: PlaywrightTestConfig = { testMatch: 'src/**/*.spec.ts', + // For local testing + webServer: process.env.DISABLE_APP_ASSETS_MOCKING + ? { + command: 'pnpm build:preview && pnpm preview', + port: PORT, + reuseExistingServer: true, + } + : undefined, reporter: 'list', // note: if you proxy into a locally running vite preview, you may have to raise this to 60 seconds timeout: 5_000, diff --git a/client/web-sveltekit/src/app.html b/client/web-sveltekit/src/app.html index fda170ee383..0dc9e416cd3 100644 --- a/client/web-sveltekit/src/app.html +++ b/client/web-sveltekit/src/app.html @@ -19,7 +19,14 @@ }, // Local standalone dev server for dotcom can be started with // pnpm dev:dotcom - sourcegraphDotComMode: '%sveltekit.env.PUBLIC_DOTCOM%' ? true : false, + sourcegraphDotComMode: !!'%sveltekit.env.PUBLIC_DOTCOM%', + codyEnabledOnInstance: !!'%sveltekit.env.PUBLIC_CODY_ENABLED_ON_INSTANCE%', + codyEnabledForCurrentUser: !!'%sveltekit.env.PUBLIC_CODY_ENABLED_FOR_CURRENT_USER%', + batchChangesEnabled: !!'%sveltekit.env.PUBLIC_BATCH_CHANGES_ENABLED%', + codeInsightsEnabled: !!'%sveltekit.env.PUBLIC_CODE_INSIGHTS_ENABLED%', + + // The following are used to mock context in playwright tests + ...(typeof window.context === 'object' ? window.context : {}), } window.pageError = undefined diff --git a/client/web-sveltekit/src/lib/dom.ts b/client/web-sveltekit/src/lib/dom.ts index dd13cd58d41..6e41f570c7d 100644 --- a/client/web-sveltekit/src/lib/dom.ts +++ b/client/web-sveltekit/src/lib/dom.ts @@ -12,7 +12,7 @@ import { type FlipOptions, } from '@floating-ui/dom' import { tick } from 'svelte' -import type { ActionReturn, Action } from 'svelte/action' +import type { Action } from 'svelte/action' import * as uuid from 'uuid' import { highlightNode } from '$lib/common' @@ -96,18 +96,29 @@ export function uniqueID(prefix = ''): string { * An action that dispatches a custom 'click-outside' event when the user clicks * outside the attached element. */ -export function onClickOutside( - node: HTMLElement -): ActionReturn) => void }> { +export const onClickOutside: Action< + HTMLElement, + { enabled?: boolean } | undefined, + { 'on:click-outside': (event: CustomEvent) => void } +> = (node, { enabled } = { enabled: true }) => { function handler(event: MouseEvent): void { if (event.target && !node.contains(event.target as HTMLElement)) { node.dispatchEvent(new CustomEvent('click-outside', { detail: event.target })) } } - window.addEventListener('mousedown', handler) + if (enabled) { + window.addEventListener('mousedown', handler) + } return { + update({ enabled } = { enabled: true }) { + if (enabled) { + window.addEventListener('mousedown', handler) + } else { + window.removeEventListener('mousedown', handler) + } + }, destroy() { window.removeEventListener('mousedown', handler) }, diff --git a/client/web-sveltekit/src/lib/navigation/GlobalHeader.svelte b/client/web-sveltekit/src/lib/navigation/GlobalHeader.svelte index bc0d9050a39..6addf5877df 100644 --- a/client/web-sveltekit/src/lib/navigation/GlobalHeader.svelte +++ b/client/web-sveltekit/src/lib/navigation/GlobalHeader.svelte @@ -14,57 +14,114 @@ -
- {#if isSidebarNavigationOpen} - (isSidebarNavigationOpen = false)} {entries} /> - {/if} - - diff --git a/client/web-sveltekit/src/testing/integration.ts b/client/web-sveltekit/src/testing/integration.ts index 445af7a2152..15fe4f68aa7 100644 --- a/client/web-sveltekit/src/testing/integration.ts +++ b/client/web-sveltekit/src/testing/integration.ts @@ -231,6 +231,16 @@ class Sourcegraph { this.graphqlMock.addFixtures(fixtures) } + public setWindowContext(context: Partial): Promise { + return this.page.addInitScript(context => { + if (!window.context) { + // @ts-expect-error - Unclear how to type this correctly + window.context = {} + } + Object.assign(window.context, context) + }, context) + } + public signIn(userMock: UserMock = {}): void { this.mockTypes({ Query: () => ({