feat(web): add logout button for web mode
This commit is contained in:
1 parent
7aa69a0e5e
commit
e3ea4740c0
19 files changed
+405
-3
No files matched your search
@@ -26,6 +26,7 @@ import {
|
||||
GripVertical,
|
||||
HardDrive,
|
||||
Loader2,
|
||||
LogOut,
|
||||
Moon,
|
||||
PackageSearch,
|
||||
Palette,
|
||||
@@ -502,6 +503,7 @@ const emit = defineEmits<{
|
||||
"open-mcp-settings": [];
|
||||
"open-update-center": [];
|
||||
"ai-config-deep-link-handled": [];
|
||||
logout: [];
|
||||
}>();
|
||||
|
||||
const hasAnyUpdate = computed(() => Boolean(props.appUpdateAvailable || (props.driverUpdateCount || 0) > 0 || props.jdbcUpdateAvailable || props.mcpUpdateAvailable || (props.pluginUpdateCount || 0) > 0));
|
||||
@@ -11327,6 +11329,19 @@ LIMIT 100;</pre
|
||||
{{ passwordMessage }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="border-t border-border/60 pt-5 space-y-3">
|
||||
<Label class="text-base">{{ t("auth.logout") }}</Label>
|
||||
<p class="text-sm text-muted-foreground">
|
||||
{{ t("auth.logoutDescription") }}
|
||||
</p>
|
||||
<div>
|
||||
<Button variant="outline" class="gap-2 text-destructive hover:text-destructive" @click="emit('logout')">
|
||||
<LogOut class="h-4 w-4" />
|
||||
{{ t("auth.logout") }}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section v-else-if="activeSettingsTab === 'tunnels'" data-settings-search-id="tunnels" :class="['flex flex-col gap-5 py-2', settingsSearchTargetClass('tunnels')]">
|
||||
|
||||
+137
@@ -0,0 +1,137 @@
|
||||
// @vitest-environment happy-dom
|
||||
|
||||
import { createApp, defineComponent, h, nextTick, type App } from "vue";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { createPinia } from "pinia";
|
||||
|
||||
vi.mock("@/lib/backend/tauriRuntime", () => ({ isTauriRuntime: () => false }));
|
||||
|
||||
vi.mock("vue-i18n", async () => {
|
||||
const { ref } = await import("vue");
|
||||
const locale = ref("en");
|
||||
const t = (key: string) => key;
|
||||
return {
|
||||
createI18n: () => ({ global: { t, locale }, install: () => undefined }),
|
||||
useI18n: () => ({ t, locale }),
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("@/components/ui/dialog", async () => {
|
||||
const { defineComponent, h } = await import("vue");
|
||||
const passthrough = defineComponent({
|
||||
setup(_props, { slots }) {
|
||||
return () => h("div", slots.default?.());
|
||||
},
|
||||
});
|
||||
return {
|
||||
Dialog: passthrough,
|
||||
DialogContent: passthrough,
|
||||
DialogFooter: passthrough,
|
||||
DialogHeader: passthrough,
|
||||
DialogTitle: passthrough,
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("@/components/ui/button", async () => {
|
||||
const { defineComponent, h } = await import("vue");
|
||||
return {
|
||||
Button: defineComponent({
|
||||
inheritAttrs: false,
|
||||
setup(_props, { attrs, slots }) {
|
||||
return () => h("button", attrs, slots.default?.());
|
||||
},
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("@/components/settings/ChangelogPanel.vue", async () => {
|
||||
const { defineComponent } = await import("vue");
|
||||
return { default: defineComponent({ setup: () => () => null }) };
|
||||
});
|
||||
|
||||
vi.mock("@/stores/settingsStore", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("@/stores/settingsStore")>();
|
||||
const store = {
|
||||
settingsPageActive: false,
|
||||
editorSettings: actual.DEFAULT_EDITOR_SETTINGS,
|
||||
desktopSettings: actual.DEFAULT_DESKTOP_SETTINGS,
|
||||
mcpGlobalPolicy: { configured: false, readOnly: false },
|
||||
aiConfigs: [],
|
||||
aiDefaultTemplatesByDbType: {},
|
||||
defaultAiMode: "ask",
|
||||
restoreLastConversation: false,
|
||||
initMcpGlobalPolicy: vi.fn(async () => undefined),
|
||||
updateMcpGlobalPolicy: vi.fn(async () => undefined),
|
||||
initAiConfigs: vi.fn(async () => undefined),
|
||||
initDesktopSettings: vi.fn(async () => undefined),
|
||||
updateEditorSettingsAndPersist: vi.fn(async () => undefined),
|
||||
updateEditorSettings: vi.fn(),
|
||||
persistEditorSettings: vi.fn(async () => undefined),
|
||||
updateDesktopSettings: vi.fn(async () => undefined),
|
||||
reloadAiConfigs: vi.fn(async () => undefined),
|
||||
removeTemplateFromDefaultAndLastUsed: vi.fn(),
|
||||
setDefaultTemplatesForDbType: vi.fn(),
|
||||
updateAiConfigItem: vi.fn(),
|
||||
createAiConfig: vi.fn(),
|
||||
deleteAiConfig: vi.fn(),
|
||||
setDefaultAiConfig: vi.fn(),
|
||||
setDefaultAiMode: vi.fn(),
|
||||
setRestoreLastConversation: vi.fn(),
|
||||
};
|
||||
return { ...actual, useSettingsStore: () => store };
|
||||
});
|
||||
|
||||
import EditorSettingsDialog from "../EditorSettingsDialog.vue";
|
||||
|
||||
if (!("ResizeObserver" in globalThis)) {
|
||||
(globalThis as unknown as { ResizeObserver: unknown }).ResizeObserver = class {
|
||||
observe() {}
|
||||
unobserve() {}
|
||||
disconnect() {}
|
||||
};
|
||||
}
|
||||
|
||||
const mountedApps: Array<{ app: App; host: HTMLElement }> = [];
|
||||
|
||||
afterEach(() => {
|
||||
for (const { app, host } of mountedApps.splice(0)) {
|
||||
app.unmount();
|
||||
host.remove();
|
||||
}
|
||||
});
|
||||
|
||||
describe("EditorSettingsDialog web logout", () => {
|
||||
it("renders logout button under security tab and emits logout event", async () => {
|
||||
let logoutEmitted = false;
|
||||
const host = document.createElement("div");
|
||||
document.body.appendChild(host);
|
||||
|
||||
const app = createApp(
|
||||
defineComponent({
|
||||
setup() {
|
||||
return () =>
|
||||
h(EditorSettingsDialog, {
|
||||
variant: "page",
|
||||
initialTab: "security" as any,
|
||||
onLogout: () => {
|
||||
logoutEmitted = true;
|
||||
},
|
||||
});
|
||||
},
|
||||
}),
|
||||
);
|
||||
app.use(createPinia());
|
||||
app.mount(host);
|
||||
mountedApps.push({ app, host });
|
||||
|
||||
await nextTick();
|
||||
await Promise.resolve();
|
||||
|
||||
const buttons = Array.from(host.querySelectorAll("button"));
|
||||
const logoutBtn = buttons.find((btn) => btn.textContent?.includes("auth.logout"));
|
||||
expect(logoutBtn).toBeDefined();
|
||||
|
||||
logoutBtn?.click();
|
||||
expect(logoutEmitted).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -2,7 +2,7 @@
|
||||
import { computed, ref, onMounted, onBeforeUnmount, h, nextTick, watch } from "vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { ChevronsRight, DatabaseZap, FilePlus2, Moon, Sun, SunMoon, History, Bot, ArrowLeftRight, FileCode, BookMarked, GitCompareArrows, TableProperties, Settings, CloudDownload, Package, PlugZap, FileDown, FolderTree, Pin, PinOff, CalendarClock, Waypoints } from "@lucide/vue";
|
||||
import { ChevronsRight, DatabaseZap, FilePlus2, Moon, Sun, SunMoon, History, Bot, ArrowLeftRight, FileCode, BookMarked, GitCompareArrows, TableProperties, Settings, LogOut, CloudDownload, Package, PlugZap, FileDown, FolderTree, Pin, PinOff, CalendarClock, Waypoints } from "@lucide/vue";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
|
||||
import LightDropdown, { type LightDropdownItem } from "@/components/ui/LightDropdown.vue";
|
||||
@@ -53,6 +53,7 @@ const props = defineProps<{
|
||||
hasConnections: boolean;
|
||||
canNewQuery: boolean;
|
||||
hasSqlFileConnections: boolean;
|
||||
showLogout?: boolean;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
@@ -75,6 +76,7 @@ const emit = defineEmits<{
|
||||
"open-data-compare": [];
|
||||
"open-backups": [];
|
||||
"open-mcp-settings": [];
|
||||
logout: [];
|
||||
}>();
|
||||
|
||||
const { t } = useI18n();
|
||||
@@ -782,6 +784,15 @@ const toolbarStyle = computed(() => {
|
||||
<TooltipContent>{{ hasMcpUpdateAvailable ? t("toolbar.mcpUpdateAvailable") : t("settings.title") }}</TooltipContent>
|
||||
</Tooltip>
|
||||
|
||||
<Tooltip v-if="showLogout">
|
||||
<TooltipTrigger as-child>
|
||||
<Button variant="ghost" size="icon" class="toolbar-action-button h-8 w-8 shrink-0" :aria-label="t('auth.logout')" @click="emit('logout')">
|
||||
<LogOut class="toolbar-action-icon h-4 w-4" />
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>{{ t("auth.logout") }}</TooltipContent>
|
||||
</Tooltip>
|
||||
|
||||
<WindowControls v-if="showControls" :is-maximized="isMaximized" @minimize="minimize" @toggle-maximize="toggleMaximize" @close="close" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -0,0 +1,154 @@
|
||||
// @vitest-environment happy-dom
|
||||
import { createApp, nextTick, type Component } from "vue";
|
||||
import { createPinia } from "pinia";
|
||||
import { createI18n } from "vue-i18n";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
vi.mock("@/lib/backend/tauriRuntime", () => ({ isTauriRuntime: () => false }));
|
||||
vi.mock("@tauri-apps/api/core", () => ({ invoke: vi.fn(async () => undefined) }));
|
||||
vi.mock("@tauri-apps/api/event", () => ({
|
||||
listen: vi.fn(async () => () => {}),
|
||||
emit: vi.fn(async () => undefined),
|
||||
}));
|
||||
vi.mock("@tauri-apps/api/webviewWindow", () => ({
|
||||
getAllWebviewWindows: vi.fn(async () => []),
|
||||
WebviewWindow: { getByLabel: vi.fn(async () => null) },
|
||||
}));
|
||||
vi.mock("@tauri-apps/api/window", () => ({
|
||||
getCurrentWindow: () => ({
|
||||
label: "main",
|
||||
isMaximized: async () => false,
|
||||
isFullscreen: async () => false,
|
||||
isAlwaysOnTop: async () => false,
|
||||
setAlwaysOnTop: async () => {},
|
||||
onResized: async () => () => {},
|
||||
onFocusChanged: async () => () => {},
|
||||
minimize: async () => {},
|
||||
toggleMaximize: async () => {},
|
||||
}),
|
||||
}));
|
||||
|
||||
vi.mock("@/components/ui/button", () => ({
|
||||
Button: { name: "ButtonStub", props: ["ariaLabel"], template: `<button :aria-label="ariaLabel"><slot /></button>` },
|
||||
}));
|
||||
vi.mock("@/components/ui/tooltip", () => ({
|
||||
Tooltip: { name: "TooltipStub", template: `<span><slot /></span>` },
|
||||
TooltipTrigger: { name: "TooltipTriggerStub", template: `<span><slot /></span>` },
|
||||
TooltipContent: { name: "TooltipContentStub", template: `<span><slot /></span>` },
|
||||
}));
|
||||
vi.mock("@/components/ui/LightDropdown.vue", () => ({
|
||||
default: { name: "LightDropdownStub", template: `<div />` },
|
||||
}));
|
||||
vi.mock("@/components/layout/WindowControls.vue", () => ({
|
||||
default: { name: "WindowControlsStub", template: `<div />` },
|
||||
}));
|
||||
vi.mock("@/components/export/ExportProgressPopover.vue", () => ({
|
||||
default: { name: "ExportProgressPopoverStub", template: `<div />` },
|
||||
}));
|
||||
vi.mock("@/components/layout/ToolbarUpdateIcon.vue", () => ({
|
||||
default: { name: "ToolbarUpdateIconStub", template: `<span />` },
|
||||
}));
|
||||
|
||||
import AppToolbar from "../AppToolbar.vue";
|
||||
|
||||
const defaultToolbarProps = {
|
||||
isDark: false,
|
||||
themeMode: "system" as const,
|
||||
showSidebarExpand: false,
|
||||
showAiPanel: false,
|
||||
activeAiRunCount: 0,
|
||||
awaitingAiRunCount: 0,
|
||||
showHistory: false,
|
||||
showSqlLibrary: false,
|
||||
sqlLibrarySaveFeedbackId: 0,
|
||||
showSqlFilePanel: false,
|
||||
showDriverStore: false,
|
||||
showPluginCenter: false,
|
||||
showSettingsPage: false,
|
||||
checkingUpdates: false,
|
||||
hasUpdateAvailable: false,
|
||||
isDownloadingUpdate: false,
|
||||
downloadProgress: null,
|
||||
updateReadyToInstall: false,
|
||||
updateReady: false,
|
||||
agentDriverUpdateCount: 0,
|
||||
hasMcpUpdateAvailable: false,
|
||||
hasConnections: false,
|
||||
canNewQuery: false,
|
||||
hasSqlFileConnections: false,
|
||||
};
|
||||
|
||||
let pinia: ReturnType<typeof createPinia>;
|
||||
|
||||
function mount(props: Record<string, unknown>, onLogout?: () => void) {
|
||||
const host = document.createElement("div");
|
||||
document.body.appendChild(host);
|
||||
const app = createApp(AppToolbar, {
|
||||
...defaultToolbarProps,
|
||||
...props,
|
||||
onLogout,
|
||||
});
|
||||
app.use(pinia);
|
||||
app.use(
|
||||
createI18n({
|
||||
legacy: false,
|
||||
locale: "en",
|
||||
missingWarn: false,
|
||||
fallbackWarn: false,
|
||||
messages: {
|
||||
en: {
|
||||
auth: { logout: "Log out" },
|
||||
settings: { title: "Settings" },
|
||||
toolbar: { theme: "Theme" },
|
||||
updates: { check: "Check for updates" },
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
app.mount(host);
|
||||
return {
|
||||
host,
|
||||
unmount: () => {
|
||||
app.unmount();
|
||||
host.remove();
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
describe("AppToolbar web logout", () => {
|
||||
beforeEach(() => {
|
||||
pinia = createPinia();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
document.body.innerHTML = "";
|
||||
});
|
||||
|
||||
it("renders logout button when showLogout is true and emits logout on click", async () => {
|
||||
let logoutEmitted = false;
|
||||
const { host, unmount } = mount({ showLogout: true }, () => {
|
||||
logoutEmitted = true;
|
||||
});
|
||||
|
||||
await nextTick();
|
||||
const logoutBtn = host.querySelector('button[aria-label="Log out"]');
|
||||
expect(logoutBtn).not.toBeNull();
|
||||
|
||||
logoutBtn?.dispatchEvent(new MouseEvent("click", { bubbles: true }));
|
||||
expect(logoutEmitted).toBe(true);
|
||||
|
||||
unmount();
|
||||
});
|
||||
|
||||
it("does not render logout button when showLogout is false or undefined", async () => {
|
||||
const { host, unmount } = mount({ showLogout: false });
|
||||
await nextTick();
|
||||
expect(host.querySelector('button[aria-label="Log out"]')).toBeNull();
|
||||
unmount();
|
||||
|
||||
const { host: host2, unmount: unmount2 } = mount({});
|
||||
await nextTick();
|
||||
expect(host2.querySelector('button[aria-label="Log out"]')).toBeNull();
|
||||
unmount2();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user