From 4f52f171d366f621476fdb4a250e4058d1d9bad1 Mon Sep 17 00:00:00 2001 From: Liviu Burcusel Date: Fri, 12 Sep 2025 15:42:28 +0200 Subject: [PATCH] Added tests for vuetify plugin --- tests/plugins/vuetify.spec.ts | 97 +++++++++++++++++++++++++++++++++++ vitest.config.ts | 23 +++++---- 2 files changed, 111 insertions(+), 9 deletions(-) create mode 100644 tests/plugins/vuetify.spec.ts diff --git a/tests/plugins/vuetify.spec.ts b/tests/plugins/vuetify.spec.ts new file mode 100644 index 0000000..bd526bd --- /dev/null +++ b/tests/plugins/vuetify.spec.ts @@ -0,0 +1,97 @@ +import { describe, it, expect, vi, beforeEach } from "vitest"; +import { createVuetify } from "vuetify"; +import * as components from "vuetify/components"; +import * as directives from "vuetify/directives"; + +// Mock the CSS imports since they're not needed for testing +vi.mock("@mdi/font/css/materialdesignicons.css", () => ({})); +vi.mock("vuetify/styles", () => ({})); + +// Mock createVuetify to spy on its calls +vi.mock("vuetify", () => ({ + createVuetify: vi.fn(), +})); + +// Mock the components and directives +vi.mock("vuetify/components", () => ({ + VApp: {}, + VBtn: {}, + // Add other components as needed for your tests +})); + +vi.mock("vuetify/directives", () => ({ + vRipple: {}, + vTooltip: {}, + // Add other directives as needed for your tests +})); + +describe("Vuetify Plugin Configuration", () => { + const mockVuetifyInstance = { + theme: { + current: { value: { dark: true } }, + global: { name: { value: "dark" } }, + }, + defaults: {}, + display: {}, + locale: {}, + rtl: {}, + }; + + beforeEach(() => { + vi.clearAllMocks(); + (createVuetify as any).mockReturnValue(mockVuetifyInstance); + }); + + it("should create vuetify instance with correct configuration", async () => { + // Import the module to trigger the createVuetify call + await import("../../src/plugins/vuetify"); + + expect(createVuetify).toHaveBeenCalledTimes(1); + expect(createVuetify).toHaveBeenCalledWith({ + components, + directives, + theme: { + defaultTheme: "dark", + }, + }); + + const callArgs = (createVuetify as any).mock.calls[0][0]; + expect(callArgs.theme).toBeDefined(); + expect(callArgs.theme.defaultTheme).toBe("dark"); + expect(callArgs.components).toBe(components); + expect(callArgs.directives).toBe(directives); + + const expectedKeys = ["components", "directives", "theme"]; + const actualKeys = Object.keys(callArgs); + expect(actualKeys.sort()).toEqual(expectedKeys.sort()); + }); + + it("should export the vuetify instance", async () => { + const vuetifyModule = await import("../../src/plugins/vuetify"); + expect(vuetifyModule.default).toBeDefined(); + expect(vuetifyModule.default).toBe(mockVuetifyInstance); + }); + + it("should have proper module structure", () => { + // Test that the required dependencies are properly structured + expect(components).toBeDefined(); + expect(directives).toBeDefined(); + expect(typeof createVuetify).toBe("function"); + }); + + describe("CSS imports", () => { + it("should import Material Design Icons CSS", () => { + // Since we're mocking the CSS import, we just verify it doesn't throw + expect(() => { + require("@mdi/font/css/materialdesignicons.css"); + }).not.toThrow(); + }); + + it("should import Vuetify styles", () => { + // Since we're mocking the CSS import, we just verify it doesn't throw + expect(() => { + require("vuetify/styles"); + }).not.toThrow(); + }); + }); +}); diff --git a/vitest.config.ts b/vitest.config.ts index eb6638b..32ae17e 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -1,17 +1,22 @@ -import { fileURLToPath } from 'node:url' -import { mergeConfig, defineConfig, configDefaults } from 'vitest/config' -import viteConfig from './vite.config' +import { fileURLToPath } from "node:url"; +import { mergeConfig, defineConfig, configDefaults } from "vitest/config"; +import viteConfig from "./vite.config"; export default mergeConfig( viteConfig, defineConfig({ test: { - environment: 'jsdom', - exclude: [...configDefaults.exclude, 'e2e/**'], - root: fileURLToPath(new URL('./', import.meta.url)), + environment: "jsdom", + exclude: [...configDefaults.exclude, "e2e/**"], + root: fileURLToPath(new URL("./", import.meta.url)), coverage: { - reporter: ['text', 'lcov'] - } + reporter: ["text", "lcov"], + }, + server: { + deps: { + inline: ["vuetify"], + }, + }, }, }), -) +);