diff --git a/jest.config.js b/jest.config.js index 5dd25b5..7da59af 100644 --- a/jest.config.js +++ b/jest.config.js @@ -34,7 +34,6 @@ const config = deepmerge(defaultPreset, { // Exclude "!/src/**/index.(js|ts)", - "!/src/plugins/vuetify.ts", ], }); diff --git a/sonar-project.properties b/sonar-project.properties index 89679c1..1befaf6 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -2,11 +2,14 @@ sonar.organization=schulcloud-verbund sonar.projectKey=hpi-schul-cloud_shd-client sonar.sources=. -sonar.tests=src/ +sonar.tests=. # Exclude test files, locales and generated code from source scope sonar.exclusions=src/serverApi/**/*,**/locales/**.ts +# Exclude scripts from root folder, app setup scripts from src and route config from coverage +sonar.coverage.exclusions=./*,src/*,src/router/* + # Include test files and test utils in test scope sonar.test.inclusions=tests/**/*,**/*.unit.ts,**/*.unit.js diff --git a/src/vuetify.options.ts b/src/plugins/vuetify.options.ts similarity index 100% rename from src/vuetify.options.ts rename to src/plugins/vuetify.options.ts diff --git a/src/plugins/vuetify.ts b/src/plugins/vuetify.ts index fcf0fee..0ec8762 100644 --- a/src/plugins/vuetify.ts +++ b/src/plugins/vuetify.ts @@ -1,7 +1,7 @@ import "vuetify/styles"; import { createVuetify } from "vuetify"; -import theme from "@/vuetify.options"; +import theme from "./vuetify.options"; export default createVuetify({ ...theme, diff --git a/src/plugins/vuetify.unit.ts b/src/plugins/vuetify.unit.ts new file mode 100644 index 0000000..9ec23a2 --- /dev/null +++ b/src/plugins/vuetify.unit.ts @@ -0,0 +1,41 @@ +import { mount } from "@vue/test-utils"; +import { defineComponent } from "vue"; +import { VBtn } from "vuetify/lib/components/index.mjs"; +import vuetify from "./vuetify"; + +jest.mock("vuetify/styles", () => ({}), { virtual: true }); +jest.mock( + "vuetify/iconsets/mdi-svg", + () => ({ + aliases: [], + mdi: [], + }), + { virtual: true } +); + +describe("vuetify plugin", () => { + describe("when creating the vuetify plugin", () => { + const setup = () => { + const TestComponent = defineComponent({ + template: "", + components: { VBtn }, + }); + + const wrapper = mount(TestComponent, { + global: { plugins: [vuetify] }, + }); + + return { + wrapper, + }; + }; + + it("should make vuetify components available", () => { + const { wrapper } = setup(); + + const button = wrapper.findComponent(VBtn); + + expect(button.exists()).toEqual(true); + }); + }); +}); diff --git a/tests/test-utils/mountComposable.ts b/tests/test-utils/mountComposable.ts new file mode 100644 index 0000000..38fb83e --- /dev/null +++ b/tests/test-utils/mountComposable.ts @@ -0,0 +1,20 @@ +import { ComponentMountingOptions, mount } from "@vue/test-utils"; +import { DefineComponent, defineComponent } from "vue"; + +export const mountComposable = ( + composable: () => T, + options?: ComponentMountingOptions +): T => { + const TestComponent = defineComponent({ + setup() { + const result = composable(); + return { result }; + }, + template: "
", + }); + + const wrapper = mount(TestComponent, options); + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + return wrapper.vm.result; +};