From 46e6c0b6c3783fc716056da18dc54100bbf431d4 Mon Sep 17 00:00:00 2001 From: Florent BENOIT Date: Tue, 7 Jan 2025 16:17:43 +0100 Subject: [PATCH] chore: move docker cli context select implem from core to docker extension (#10526) * chore: move docker cli context select implem from core to docker extension fixes https://github.com/podman-desktop/podman-desktop/issues/10517 Signed-off-by: Florent Benoit --- extensions/docker/package.json | 22 +++ extensions/docker/src/docker-api.ts | 35 +++++ .../src/docker-compatibility-setup.spec.ts | 130 ++++++++++++++++ .../docker/src/docker-compatibility-setup.ts | 61 ++++++++ .../src}/docker-context-handler.spec.ts | 18 ++- .../docker/src}/docker-context-handler.ts | 19 ++- extensions/docker/src/extension.ts | 13 +- .../src/plugin/docker/docker-compatibility.ts | 18 +-- packages/main/src/plugin/index.ts | 13 +- packages/preload/src/index.ts | 10 +- ...esDockerCompatibilityDockerContext.spec.ts | 140 ------------------ ...cesDockerCompatibilityDockerContext.svelte | 68 --------- ...erencesDockerCompatibilityRendering.svelte | 5 - 13 files changed, 285 insertions(+), 267 deletions(-) create mode 100644 extensions/docker/src/docker-api.ts create mode 100644 extensions/docker/src/docker-compatibility-setup.spec.ts create mode 100644 extensions/docker/src/docker-compatibility-setup.ts rename {packages/main/src/plugin/docker => extensions/docker/src}/docker-context-handler.spec.ts (96%) rename {packages/main/src/plugin/docker => extensions/docker/src}/docker-context-handler.ts (91%) delete mode 100644 packages/renderer/src/lib/preferences/docker-compat/PreferencesDockerCompatibilityDockerContext.spec.ts delete mode 100644 packages/renderer/src/lib/preferences/docker-compat/PreferencesDockerCompatibilityDockerContext.svelte diff --git a/extensions/docker/package.json b/extensions/docker/package.json index 411156212..61b09ae06 100644 --- a/extensions/docker/package.json +++ b/extensions/docker/package.json @@ -25,5 +25,27 @@ "mkdirp": "^3.0.1", "vite": "^6.0.7", "vitest": "^2.1.6" + }, + "contributes": { + "commands": [ + { + "command": "docker.cli.context.onChange", + "title": "Callback for Docker CLI context change", + "category": "Docker", + "enablement": "false" + } + ], + "configuration": { + "title": "Docker", + "properties": { + "docker.cli.context": { + "type": "string", + "enum": [], + "markdownDescription": "Select the active Docker CLI context:", + "group": "podman-desktop.docker", + "scope": "DockerCompatibility" + } + } + } } } diff --git a/extensions/docker/src/docker-api.ts b/extensions/docker/src/docker-api.ts new file mode 100644 index 000000000..07827d50f --- /dev/null +++ b/extensions/docker/src/docker-api.ts @@ -0,0 +1,35 @@ +/********************************************************************** + * Copyright (C) 2025 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + ***********************************************************************/ + +// handle the context information of the docker contexts +// https://docs.docker.com/engine/manage-resources/contexts/ +export interface DockerContextInfo { + name: string; + isCurrentContext: boolean; + metadata: { + description: string; + }; + endpoints: { + docker: { + host: string; + }; + }; +} + +export const WINDOWS_NPIPE = '//./pipe/docker_engine'; +export const UNIX_SOCKET_PATH = '/var/run/docker.sock'; diff --git a/extensions/docker/src/docker-compatibility-setup.spec.ts b/extensions/docker/src/docker-compatibility-setup.spec.ts new file mode 100644 index 000000000..a71b8f63a --- /dev/null +++ b/extensions/docker/src/docker-compatibility-setup.spec.ts @@ -0,0 +1,130 @@ +/********************************************************************** + * Copyright (C) 2024-2025 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + ***********************************************************************/ + +import type { Configuration } from '@podman-desktop/api'; +import { configuration, context } from '@podman-desktop/api'; +import { beforeEach, expect, test, vi } from 'vitest'; + +import { DockerCompatibilitySetup } from './docker-compatibility-setup.js'; +import type { DockerContextHandler } from './docker-context-handler.js'; + +vi.mock('@podman-desktop/api', async () => { + return { + context: { + setValue: vi.fn(), + }, + configuration: { + onDidChangeConfiguration: vi.fn(), + getConfiguration: vi.fn(), + }, + env: { + isLinux: false, + isWindows: false, + isMac: false, + }, + }; +}); + +const dockerContextHandler = { + listContexts: vi.fn(), + switchContext: vi.fn(), +} as unknown as DockerContextHandler; + +let dockerCompatibilitySetup: DockerCompatibilitySetup; + +beforeEach(() => { + vi.resetAllMocks(); + dockerCompatibilitySetup = new DockerCompatibilitySetup(dockerContextHandler); +}); + +test('check sending the docker cli contexts as context.setValue', async () => { + // return a list of 2 contexts, second one being the current one + vi.mocked(dockerContextHandler.listContexts).mockResolvedValue([ + { + name: 'context1', + metadata: { + description: 'description1', + }, + endpoints: { + docker: { + host: 'host1', + }, + }, + isCurrentContext: false, + }, + { + name: 'context2', + metadata: { + description: 'description2', + }, + endpoints: { + docker: { + host: 'host2', + }, + }, + isCurrentContext: true, + }, + ]); + + await dockerCompatibilitySetup.init(); + + // check we called listContexts + expect(dockerContextHandler.listContexts).toHaveBeenCalled(); + + // check we called setValue with the expected values + expect(context.setValue).toHaveBeenCalledWith( + 'docker.cli.context', + [ + { + label: 'context1 (host1)', + selected: false, + value: 'context1', + }, + { + label: 'context2 (host2)', + selected: true, + value: 'context2', + }, + ], + 'DockerCompatibility', + ); +}); + +test('check set the context when configuration change', async () => { + // empty list of context + vi.mocked(dockerContextHandler.listContexts).mockResolvedValue([]); + + await dockerCompatibilitySetup.init(); + + // capture the callback sent to onDidChangeConfiguration + const callback = vi.mocked(configuration.onDidChangeConfiguration).mock.calls[0][0]; + + // mock configuration.getConfiguration + vi.mocked(configuration.getConfiguration).mockReturnValue({ + get: vi.fn(() => 'context1'), + } as unknown as Configuration); + + // mock switchContext + vi.mocked(dockerContextHandler.switchContext).mockResolvedValue(); + + // call the callback + callback({ affectsConfiguration: vi.fn(() => true) }); + + // check we called switchContext + expect(dockerContextHandler.switchContext).toHaveBeenCalledWith('context1'); +}); diff --git a/extensions/docker/src/docker-compatibility-setup.ts b/extensions/docker/src/docker-compatibility-setup.ts new file mode 100644 index 000000000..b75e882ad --- /dev/null +++ b/extensions/docker/src/docker-compatibility-setup.ts @@ -0,0 +1,61 @@ +/********************************************************************** + * Copyright (C) 2025 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + ***********************************************************************/ + +import { configuration, context } from '@podman-desktop/api'; + +import type { DockerContextHandler } from './docker-context-handler'; + +// setup the management of the docker contexts +// registering the DockerCompatibility configuration +export class DockerCompatibilitySetup { + #dockerContextHandler: DockerContextHandler; + + constructor(dockerContextHandler: DockerContextHandler) { + this.#dockerContextHandler = dockerContextHandler; + } + + async init(): Promise { + // get the current contexts + const currentContexts = await this.#dockerContextHandler.listContexts(); + + // define the enum list + const contextEnumItems = currentContexts.map(context => { + return { + label: `${context.name} (${context.endpoints.docker.host})`, + value: context.name, + selected: context.isCurrentContext, + }; + }); + context.setValue('docker.cli.context', contextEnumItems, 'DockerCompatibility'); + + // track the changes operated by the user + configuration.onDidChangeConfiguration(event => { + if (event.affectsConfiguration('docker.cli.context')) { + // get the value + const value = configuration.getConfiguration('docker.cli', 'DockerCompatibility'); + const contextName = value.get('context'); + + if (contextName) { + this.#dockerContextHandler.switchContext(contextName).catch((error: unknown) => { + console.error('Error switching docker context', error); + }); + } + } + }); + } +} diff --git a/packages/main/src/plugin/docker/docker-context-handler.spec.ts b/extensions/docker/src/docker-context-handler.spec.ts similarity index 96% rename from packages/main/src/plugin/docker/docker-context-handler.spec.ts rename to extensions/docker/src/docker-context-handler.spec.ts index 4682a46ab..5fb24c97b 100644 --- a/packages/main/src/plugin/docker/docker-context-handler.spec.ts +++ b/extensions/docker/src/docker-context-handler.spec.ts @@ -1,5 +1,5 @@ /********************************************************************** - * Copyright (C) 2024 Red Hat, Inc. + * Copyright (C) 2024-2025 Red Hat, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,13 +20,13 @@ import * as fs from 'node:fs'; import { homedir } from 'node:os'; import { join } from 'node:path'; +import { env } from '@podman-desktop/api'; import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest'; -import * as util from '../../util.js'; import type { DockerContextParsingInfo } from './docker-context-handler.js'; import { DockerContextHandler } from './docker-context-handler.js'; -export class TestDockerContextHandler extends DockerContextHandler { +class TestDockerContextHandler extends DockerContextHandler { override getDockerConfigPath(): string { return super.getDockerConfigPath(); } @@ -43,6 +43,16 @@ export class TestDockerContextHandler extends DockerContextHandler { // mock exists sync vi.mock('node:fs'); +vi.mock('@podman-desktop/api', async () => { + return { + env: { + isLinux: false, + isWindows: false, + isMac: false, + }, + }; +}); + const originalConsoleError = console.error; let dockerContextHandler: TestDockerContextHandler; @@ -174,7 +184,7 @@ describe('getContexts', () => { test('check default on Windows', async () => { vi.spyOn(fs, 'existsSync').mockReturnValue(false); - vi.spyOn(util, 'isWindows').mockImplementation(() => true); + vi.mocked(env).isWindows = true; const contexts = await dockerContextHandler.getContexts(); diff --git a/packages/main/src/plugin/docker/docker-context-handler.ts b/extensions/docker/src/docker-context-handler.ts similarity index 91% rename from packages/main/src/plugin/docker/docker-context-handler.ts rename to extensions/docker/src/docker-context-handler.ts index 5d4efe6e6..782e7d885 100644 --- a/packages/main/src/plugin/docker/docker-context-handler.ts +++ b/extensions/docker/src/docker-context-handler.ts @@ -1,5 +1,5 @@ /********************************************************************** - * Copyright (C) 2024 Red Hat, Inc. + * Copyright (C) 2024-2025 Red Hat, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,10 +21,9 @@ import { existsSync, promises } from 'node:fs'; import { homedir } from 'node:os'; import { join } from 'node:path'; -import { isWindows } from '/@/util.js'; -import type { DockerContextInfo } from '/@api/docker-compatibility-info.js'; +import { env } from '@podman-desktop/api'; -import { DockerCompatibility } from './docker-compatibility.js'; +import { type DockerContextInfo, UNIX_SOCKET_PATH, WINDOWS_NPIPE } from './docker-api.js'; // omit current context as it is coming from another source // disabling the rule as we're not only extending the interface but omitting one field @@ -41,7 +40,7 @@ export class DockerContextHandler { } protected async getCurrentContext(): Promise { - let currentContext: string = 'default'; + let currentContext = 'default'; // if $HOME/.docker/config.json exists, read it and get the current context const dockerConfigExists = existsSync(this.getDockerConfigPath()); @@ -66,8 +65,8 @@ export class DockerContextHandler { protected async getContexts(): Promise { const contexts: DockerContextParsingInfo[] = []; - const defaultHostForWindows = `npipe://${DockerCompatibility.WINDOWS_NPIPE}`; - const defaultHostForMacOrLinux = `unix://${DockerCompatibility.UNIX_SOCKET_PATH}`; + const defaultHostForWindows = `npipe://${WINDOWS_NPIPE}`; + const defaultHostForMacOrLinux = `unix://${UNIX_SOCKET_PATH}`; // adds the default context contexts.push({ @@ -77,7 +76,7 @@ export class DockerContextHandler { }, endpoints: { docker: { - host: isWindows() ? defaultHostForWindows : defaultHostForMacOrLinux, + host: env.isWindows ? defaultHostForWindows : defaultHostForMacOrLinux, }, }, }); @@ -166,7 +165,7 @@ export class DockerContextHandler { // now, write the context name to the ~/.docker/config.json file // read current content const content = await promises.readFile(this.getDockerConfigPath(), 'utf-8'); - let config; + let config: { currentContext?: string }; try { config = JSON.parse(content); } catch (error: unknown) { @@ -174,7 +173,7 @@ export class DockerContextHandler { } // update the current context or drop the field if it is the default context if (contextName === 'default') { - delete config.currentContext; + config.currentContext = undefined; } else { config.currentContext = contextName; } diff --git a/extensions/docker/src/extension.ts b/extensions/docker/src/extension.ts index 897f693c4..940b2d72c 100644 --- a/extensions/docker/src/extension.ts +++ b/extensions/docker/src/extension.ts @@ -21,7 +21,10 @@ import * as os from 'node:os'; import * as extensionApi from '@podman-desktop/api'; +import { UNIX_SOCKET_PATH, WINDOWS_NPIPE } from './docker-api'; import { getDockerInstallation } from './docker-cli'; +import { DockerCompatibilitySetup } from './docker-compatibility-setup'; +import { DockerContextHandler } from './docker-context-handler'; let stopLoop = false; let socketPath: string; @@ -160,11 +163,17 @@ async function updateProvider(extensionContext: extensionApi.ExtensionContext): export async function activate(extensionContext: extensionApi.ExtensionContext): Promise { const isWindows = os.platform() === 'win32'; if (isWindows) { - socketPath = '//./pipe/docker_engine'; + socketPath = WINDOWS_NPIPE; } else { - socketPath = '/var/run/docker.sock'; + socketPath = UNIX_SOCKET_PATH; } + const dockerContextHandler = new DockerContextHandler(); + const dockerCompatibilitySetup = new DockerCompatibilitySetup(dockerContextHandler); + dockerCompatibilitySetup.init().catch((err: unknown) => { + console.error('Error while initializing docker compatibility setup', err); + }); + // monitor daemon monitorDaemon(extensionContext).catch((err: unknown) => { console.error('Error while monitoring docker daemon', err); diff --git a/packages/main/src/plugin/docker/docker-compatibility.ts b/packages/main/src/plugin/docker/docker-compatibility.ts index 28ac00cfc..419d60203 100644 --- a/packages/main/src/plugin/docker/docker-compatibility.ts +++ b/packages/main/src/plugin/docker/docker-compatibility.ts @@ -21,17 +21,12 @@ import { promises } from 'node:fs'; import Dockerode from 'dockerode'; import { isMac, isWindows } from '/@/util.js'; -import type { - DockerContextInfo, - DockerSocketMappingStatusInfo, - DockerSocketServerInfoType, -} from '/@api/docker-compatibility-info.js'; +import type { DockerSocketMappingStatusInfo, DockerSocketServerInfoType } from '/@api/docker-compatibility-info.js'; import { ExperimentalSettings } from '/@api/docker-compatibility-info.js'; import type { ConfigurationRegistry, IConfigurationNode } from '../configuration-registry.js'; import type { LibPod } from '../dockerode/libpod-dockerode.js'; import type { ProviderRegistry } from '../provider-registry.js'; -import { DockerContextHandler } from './docker-context-handler.js'; export class DockerCompatibility { static readonly WINDOWS_NPIPE = '//./pipe/docker_engine'; @@ -43,12 +38,9 @@ export class DockerCompatibility { #providerRegistry: ProviderRegistry; - #dockerContextHandler: DockerContextHandler; - constructor(configurationRegistry: ConfigurationRegistry, providerRegistry: ProviderRegistry) { this.#configurationRegistry = configurationRegistry; this.#providerRegistry = providerRegistry; - this.#dockerContextHandler = new DockerContextHandler(); } init(): void { @@ -178,12 +170,4 @@ export class DockerCompatibility { return { status: 'unreachable' }; } } - - async listDockerContexts(): Promise { - return this.#dockerContextHandler.listContexts(); - } - - async switchDockerContext(contextName: string): Promise { - return this.#dockerContextHandler.switchContext(contextName); - } } diff --git a/packages/main/src/plugin/index.ts b/packages/main/src/plugin/index.ts index e4a3fe41f..4cad0613c 100644 --- a/packages/main/src/plugin/index.ts +++ b/packages/main/src/plugin/index.ts @@ -76,7 +76,7 @@ import type { import type { ContainerInspectInfo } from '/@api/container-inspect-info.js'; import type { ContainerStatsInfo } from '/@api/container-stats-info.js'; import type { ContributionInfo } from '/@api/contribution-info.js'; -import type { DockerContextInfo, DockerSocketMappingStatusInfo } from '/@api/docker-compatibility-info.js'; +import type { DockerSocketMappingStatusInfo } from '/@api/docker-compatibility-info.js'; import type { ExtensionInfo } from '/@api/extension-info.js'; import type { GitHubIssue } from '/@api/feedback.js'; import type { HistoryInfo } from '/@api/history-info.js'; @@ -2862,17 +2862,6 @@ export class PluginSystem { }, ); - this.ipcHandle('docker-compatibility:listDockerContexts', async (): Promise => { - return dockerCompatibility.listDockerContexts(); - }); - - this.ipcHandle( - 'docker-compatibility:switchDockerContext', - async (_listener, dockerContextName: string): Promise => { - return dockerCompatibility.switchDockerContext(dockerContextName); - }, - ); - this.ipcHandle('path:relative', async (_listener, from: string, to: string): Promise => { return path.relative(from, to); }); diff --git a/packages/preload/src/index.ts b/packages/preload/src/index.ts index dda30c3ee..2b2e6bd37 100644 --- a/packages/preload/src/index.ts +++ b/packages/preload/src/index.ts @@ -56,7 +56,7 @@ import type { import type { ContainerInspectInfo } from '/@api/container-inspect-info'; import type { ContainerStatsInfo } from '/@api/container-stats-info'; import type { ContributionInfo } from '/@api/contribution-info'; -import type { DockerContextInfo, DockerSocketMappingStatusInfo } from '/@api/docker-compatibility-info'; +import type { DockerSocketMappingStatusInfo } from '/@api/docker-compatibility-info'; import type { ExtensionInfo } from '/@api/extension-info'; import type { FeedbackProperties, GitHubIssue } from '/@api/feedback'; import type { HistoryInfo } from '/@api/history-info'; @@ -2375,14 +2375,6 @@ export function initExposure(): void { }, ); - contextBridge.exposeInMainWorld('getDockerContexts', async (): Promise => { - return ipcInvoke('docker-compatibility:listDockerContexts'); - }); - - contextBridge.exposeInMainWorld('switchDockerContext', async (contextName: string): Promise => { - return ipcInvoke('docker-compatibility:switchDockerContext', contextName); - }); - contextBridge.exposeInMainWorld('pathRelative', async (from: string, to: string): Promise => { return ipcInvoke('path:relative', from, to); }); diff --git a/packages/renderer/src/lib/preferences/docker-compat/PreferencesDockerCompatibilityDockerContext.spec.ts b/packages/renderer/src/lib/preferences/docker-compat/PreferencesDockerCompatibilityDockerContext.spec.ts deleted file mode 100644 index 7cabef3c1..000000000 --- a/packages/renderer/src/lib/preferences/docker-compat/PreferencesDockerCompatibilityDockerContext.spec.ts +++ /dev/null @@ -1,140 +0,0 @@ -/********************************************************************** - * Copyright (C) 2024 Red Hat, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ***********************************************************************/ - -import '@testing-library/jest-dom/vitest'; - -import { render, screen } from '@testing-library/svelte'; -import userEvent from '@testing-library/user-event'; -import { tick } from 'svelte'; -import { beforeEach, expect, type Mock, test, vi } from 'vitest'; - -import type { DockerContextInfo } from '/@api/docker-compatibility-info'; - -import PreferencesDockerCompatibilityDockerContext from '././PreferencesDockerCompatibilityDockerContext.svelte'; - -const UNIX_OR_MAC_HOST = 'unix:///var/run/docker.sock'; - -const contextInfos = [ - { - name: 'default', - isCurrentContext: false, - metadata: { description: 'default context' }, - endpoints: { - docker: { - host: UNIX_OR_MAC_HOST, - }, - }, - }, - { - name: 'podman', - isCurrentContext: true, - metadata: { description: 'podman context' }, - endpoints: { - docker: { - host: UNIX_OR_MAC_HOST, - }, - }, - }, -]; - -const getDockerContextsMock: Mock<() => Promise> = vi.fn(); -const switchDockerContextMock: Mock<(contextName: string) => Promise> = vi.fn(); - -beforeEach(() => { - vi.resetAllMocks(); - - Object.defineProperty(global, 'window', { - value: { - navigator: { - clipboard: { - writeText: vi.fn(), - }, - }, - getDockerContexts: getDockerContextsMock, - switchDockerContext: switchDockerContextMock, - }, - writable: true, - }); -}); - -test('only default context', async () => { - getDockerContextsMock.mockResolvedValue([ - { - name: 'default', - isCurrentContext: true, - metadata: { description: 'default context' }, - endpoints: { - docker: { - host: UNIX_OR_MAC_HOST, - }, - }, - }, - ]); - - render(PreferencesDockerCompatibilityDockerContext); - - // wait for the promise to resolve - await vi.waitFor(() => expect(getDockerContextsMock).toBeCalled()); - await tick(); - - expect(screen.getByText(`default (${UNIX_OR_MAC_HOST})`)).toBeInTheDocument(); -}); - -test('multiple contexts', async () => { - getDockerContextsMock.mockResolvedValue(contextInfos); - - render(PreferencesDockerCompatibilityDockerContext); - - // wait for the promise to resolve - await vi.waitFor(() => expect(getDockerContextsMock).toBeCalled()); - await tick(); - - // default should be there - expect(screen.getByText(`default (${UNIX_OR_MAC_HOST})`)).toBeInTheDocument(); - - // podman should be there - expect(screen.getByText(`podman (${UNIX_OR_MAC_HOST})`)).toBeInTheDocument(); - - // get selected context from select component with id dockerContextChoice - const select = screen.getByRole('combobox', { name: 'Docker Context selection' }); - expect(select).toBeInTheDocument(); -}); - -test('change context', async () => { - getDockerContextsMock.mockResolvedValue(contextInfos); - switchDockerContextMock.mockResolvedValue(); - render(PreferencesDockerCompatibilityDockerContext); - - // wait for the promise to resolve - await vi.waitFor(() => expect(getDockerContextsMock).toBeCalled()); - await tick(); - - // select another item in the combo box - const select = screen.getByRole('combobox', { name: 'Docker Context selection' }); - expect(select).toBeInTheDocument(); - - // find default option - const defaultOption = screen.getByRole('option', { name: `default (${UNIX_OR_MAC_HOST})` }); - expect(defaultOption).toBeInTheDocument(); - - // click on the select - await userEvent.selectOptions(select, defaultOption); - - // expect we got a call to switchDockerContext - expect(switchDockerContextMock).toBeCalledWith('default'); -}); diff --git a/packages/renderer/src/lib/preferences/docker-compat/PreferencesDockerCompatibilityDockerContext.svelte b/packages/renderer/src/lib/preferences/docker-compat/PreferencesDockerCompatibilityDockerContext.svelte deleted file mode 100644 index 527b7eca6..000000000 --- a/packages/renderer/src/lib/preferences/docker-compat/PreferencesDockerCompatibilityDockerContext.svelte +++ /dev/null @@ -1,68 +0,0 @@ - - -
-
-
-
- Docker Context - -
- -
-
- {#if dockerContexts.length > 0} -
-
Select the active Docker CLI context:
-
- -
-
- {/if} -
-
-
diff --git a/packages/renderer/src/lib/preferences/docker-compat/PreferencesDockerCompatibilityRendering.svelte b/packages/renderer/src/lib/preferences/docker-compat/PreferencesDockerCompatibilityRendering.svelte index 6f3ca5ca9..e745a9b6b 100644 --- a/packages/renderer/src/lib/preferences/docker-compat/PreferencesDockerCompatibilityRendering.svelte +++ b/packages/renderer/src/lib/preferences/docker-compat/PreferencesDockerCompatibilityRendering.svelte @@ -1,7 +1,6 @@ @@ -15,10 +14,6 @@ import PreferencesDockerCompatibilitySocketMappingStatus from './PreferencesDock
Docker Preferences
-
-
Docker CLI Context
- -