|
| 1 | +// @vitest-environment nuxt |
| 2 | + |
| 3 | +import { describe, expect, test } from "vitest" |
| 4 | +import { registerEndpoint, mountSuspended } from "@nuxt/test-utils/runtime" |
| 5 | +import { flushPromises } from "@vue/test-utils" |
| 6 | + |
| 7 | +import { createVuetify } from "vuetify" |
| 8 | +import * as components from "vuetify/components" |
| 9 | +import * as directives from "vuetify/directives" |
| 10 | + |
| 11 | +import InspectorInspectionButton from "@/components/Inspector/InspectionButton.vue" |
| 12 | +import schemas from "@geode/opengeodeweb-back/schemas.json" |
| 13 | +const schema = schemas.opengeodeweb_back.inspect_file |
| 14 | + |
| 15 | +const vuetify = createVuetify({ |
| 16 | + components, |
| 17 | + directives, |
| 18 | +}) |
| 19 | + |
| 20 | +describe("Inspector/InspectionButton.vue", async () => { |
| 21 | + test(`Test with issues`, async () => { |
| 22 | + var inspection_result = { |
| 23 | + title: "Brep inspection", |
| 24 | + nb_issues: 3, |
| 25 | + children: [ |
| 26 | + { |
| 27 | + title: "Brep inspection", |
| 28 | + nb_issues: 2, |
| 29 | + issues: ["issue 1", "issue 2"], |
| 30 | + }, |
| 31 | + { |
| 32 | + title: "Brep inspection", |
| 33 | + nb_issues: 1, |
| 34 | + issues: ["issue 1"], |
| 35 | + }, |
| 36 | + ], |
| 37 | + } |
| 38 | + |
| 39 | + registerEndpoint(schema.$id, { |
| 40 | + method: schema.methods[0], |
| 41 | + handler: () => ({ |
| 42 | + inspection_result, |
| 43 | + }), |
| 44 | + }) |
| 45 | + const input_geode_object = "BRep" |
| 46 | + const filename = "test.txt" |
| 47 | + |
| 48 | + const wrapper = await mountSuspended(InspectorInspectionButton, { |
| 49 | + global: { |
| 50 | + plugins: [vuetify], |
| 51 | + }, |
| 52 | + props: { input_geode_object, filename }, |
| 53 | + }) |
| 54 | + |
| 55 | + expect(wrapper.exists()).toBe(true) |
| 56 | + const v_btn = await wrapper.findComponent(components.VBtn) |
| 57 | + await v_btn.trigger("click") |
| 58 | + await flushPromises() |
| 59 | + |
| 60 | + expect(wrapper.emitted()).toHaveProperty("update_values") |
| 61 | + expect(wrapper.emitted().update_values).toHaveLength(1) |
| 62 | + expect(wrapper.emitted().update_values[0][0]).toStrictEqual({ |
| 63 | + inspection_result: [inspection_result], |
| 64 | + }) |
| 65 | + expect(wrapper.emitted()).toHaveProperty("increment_step") |
| 66 | + }) |
| 67 | +}) |
0 commit comments