fix(ai): compact composer controls based on overflow
This commit is contained in:
2 files changed
+224
-39
No files matched your search
@@ -38,7 +38,7 @@ afterEach(() => {
|
||||
while (cleanups.length) cleanups.pop()?.();
|
||||
});
|
||||
|
||||
async function mountPanel(aiConfigLoaded: boolean, connection?: ConnectionConfig) {
|
||||
async function mountPanel(aiConfigLoaded: boolean, connection?: ConnectionConfig, configureSettings?: (settings: ReturnType<typeof useSettingsStore>) => void) {
|
||||
const pinia = createPinia();
|
||||
const errors: unknown[] = [];
|
||||
const app = createApp({ render: () => h(TooltipProvider, () => h(AiAssistant, { connection })) });
|
||||
@@ -46,7 +46,9 @@ async function mountPanel(aiConfigLoaded: boolean, connection?: ConnectionConfig
|
||||
app.use(i18n);
|
||||
app.config.errorHandler = (error) => errors.push(error);
|
||||
app.config.warnHandler = () => {};
|
||||
useSettingsStore(pinia).isAiConfigLoaded = aiConfigLoaded;
|
||||
const settings = useSettingsStore(pinia);
|
||||
settings.isAiConfigLoaded = aiConfigLoaded;
|
||||
configureSettings?.(settings);
|
||||
if (connection) useConnectionStore(pinia).connections = [connection];
|
||||
const container = document.createElement("div");
|
||||
document.body.append(container);
|
||||
@@ -69,6 +71,39 @@ describe("AiAssistant mount", () => {
|
||||
expect((await mountPanel(false)).errors.map(String)).toEqual([]);
|
||||
});
|
||||
|
||||
it("renders compactable composer controls with accessible labels", async () => {
|
||||
const { errors, container } = await mountPanel(true, undefined, (settings) => {
|
||||
settings.aiConfigs = [
|
||||
{
|
||||
id: "deepseek-default",
|
||||
name: "DeepSeek",
|
||||
provider: "deepseek",
|
||||
apiKey: "test-key",
|
||||
authMethod: "api-key",
|
||||
endpoint: "https://api.deepseek.com",
|
||||
model: "deepseek-chat",
|
||||
apiStyle: "completions",
|
||||
isDefault: true,
|
||||
},
|
||||
];
|
||||
settings.activeModel = { configId: "deepseek-default", modelId: "deepseek-chat" };
|
||||
});
|
||||
|
||||
expect(errors.map(String)).toEqual([]);
|
||||
expect(container.querySelector(".ai-prompt-context-container")).not.toBeNull();
|
||||
expect(container.querySelector("[data-ai-composer-actions]")).not.toBeNull();
|
||||
expect(container.querySelector<HTMLButtonElement>(".ai-template-selector-trigger")?.getAttribute("aria-label")).toBeTruthy();
|
||||
expect(container.querySelector<HTMLButtonElement>(".ai-skills-selector-trigger")?.getAttribute("aria-label")).toBe(i18n.global.t("ai.skillsEntry"));
|
||||
|
||||
const modeTrigger = container.querySelector<HTMLButtonElement>(".ai-mode-action-trigger");
|
||||
expect(modeTrigger?.getAttribute("aria-label")).toBeTruthy();
|
||||
expect(modeTrigger?.getAttribute("title")).toBe(modeTrigger?.getAttribute("aria-label"));
|
||||
|
||||
const modelTrigger = container.querySelector<HTMLButtonElement>(".ai-model-selector-trigger");
|
||||
expect(modelTrigger?.getAttribute("aria-label")).toBe("deepseek-chat");
|
||||
expect(modelTrigger?.getAttribute("title")).toBe("deepseek-chat");
|
||||
});
|
||||
|
||||
it.each(["plugin", "etcd"] as const)("hides database and schema selectors for %s connections", async (dbType) => {
|
||||
const { errors, container } = await mountPanel(true, { id: "connection", name: "Connection", db_type: dbType, plugin_id: dbType === "plugin" ? "sample.plugin" : undefined, host: "localhost", port: 22, username: "", password: "" });
|
||||
expect(errors.map(String)).toEqual([]);
|
||||
|
||||
Reference in new issue
Block a user