diff --git a/assets/components/FuzzySearchModal.spec.ts b/assets/components/FuzzySearchModal.spec.ts
index 34244d11..8fe42062 100644
--- a/assets/components/FuzzySearchModal.spec.ts
+++ b/assets/components/FuzzySearchModal.spec.ts
@@ -4,12 +4,16 @@ import { mount } from "@vue/test-utils";
import FuzzySearchModal from "./FuzzySearchModal.vue";
import { Container } from "@/models/Container";
-import { describe, expect, test, vi } from "vitest";
+import { beforeEach, describe, expect, test, vi } from "vitest";
import { createI18n } from "vue-i18n";
+import { useRouter } from "vue-router";
+import { router } from "@/modules/router";
// @ts-ignore
import EventSource, { sources } from "eventsourcemock";
+vi.mock("vue-router");
+
vi.mock("@/stores/config", () => ({
__esModule: true,
default: { base: "", hosts: [{ name: "localhost", id: "localhost" }] },
@@ -28,8 +32,8 @@ function createFuzzySearchModal() {
container: {
containers: [
new Container("123", new Date(), "image", "test", "command", "host", {}, "status", "running"),
- new Container("123", new Date(), "image", "foo bar", "command", "host", {}, "status", "running"),
- new Container("123", new Date(), "image", "baz", "command", "host", {}, "status", "exited"),
+ new Container("345", new Date(), "image", "foo bar", "command", "host", {}, "status", "running"),
+ new Container("567", new Date(), "image", "baz", "command", "host", {}, "status", "exited"),
],
},
},
@@ -44,6 +48,14 @@ function createFuzzySearchModal() {
* @vitest-environment jsdom
*/
describe("", () => {
+ vi.mocked(useRouter).mockReturnValue({
+ ...router,
+ push: vi.fn(),
+ });
+
+ beforeEach(() => {
+ vi.mocked(useRouter().push).mockReset();
+ });
test("shows all", async () => {
const wrapper = createFuzzySearchModal();
expect(wrapper.findAll("li").length).toBe(3);
@@ -57,4 +69,11 @@ describe("", () => {
`"foo bar"`,
);
});
+
+ test("choose baz", async () => {
+ const wrapper = createFuzzySearchModal();
+ await wrapper.find("input").setValue("baz");
+ await wrapper.find("input").trigger("keyup.enter");
+ expect(useRouter().push).toHaveBeenCalledWith({ name: "container-id", params: { id: "567" } });
+ });
});
diff --git a/assets/modules/router.ts b/assets/modules/router.ts
index 852c5364..bbc826e9 100644
--- a/assets/modules/router.ts
+++ b/assets/modules/router.ts
@@ -3,13 +3,12 @@ import { createRouter, createWebHistory } from "vue-router";
import pages from "~pages";
import { setupLayouts } from "virtual:generated-layouts";
+const routes = setupLayouts(pages);
+export const router = createRouter({
+ history: createWebHistory(withBase("/")),
+ routes,
+});
+
export const install = (app: App) => {
- const routes = setupLayouts(pages);
-
- const router = createRouter({
- history: createWebHistory(withBase("/")),
- routes,
- });
-
app.use(router);
};