From 73aea07be48b648948fc5da0af927b149df749dd Mon Sep 17 00:00:00 2001 From: Thomas Parisot Date: Mon, 18 Dec 2023 19:33:53 +0100 Subject: [PATCH 1/4] fix: appelle une seule fois clearAllMocks --- src/components/DesignSystem/AccordionGroup.test.js | 4 +--- src/components/Features/FeatureGroup.test.js | 1 - .../Features/SingleItemCertificationBodyForm.test.js | 1 - src/components/Features/Table.test.js | 1 - src/components/OperatorSetup/index.test.js | 3 +-- tests-setup.js | 2 ++ widget/Notification.test.js | 6 +----- 7 files changed, 5 insertions(+), 13 deletions(-) diff --git a/src/components/DesignSystem/AccordionGroup.test.js b/src/components/DesignSystem/AccordionGroup.test.js index 134bc4c7..3ebaf037 100644 --- a/src/components/DesignSystem/AccordionGroup.test.js +++ b/src/components/DesignSystem/AccordionGroup.test.js @@ -1,4 +1,4 @@ -import { afterEach, describe, expect, test, vi } from "vitest" +import { describe, expect, test } from "vitest" import { defineComponent } from "vue" import { mount } from "@vue/test-utils" @@ -7,8 +7,6 @@ import AccordionGroup from "./AccordionGroup.vue" describe("AccordionGroup", () => { - afterEach(() => vi.clearAllMocks()) - test('we trigger an edit form', async () => { const TestComponent = defineComponent({ components: { AccordionGroup, AccordionSection }, diff --git a/src/components/Features/FeatureGroup.test.js b/src/components/Features/FeatureGroup.test.js index 8adf6b0a..eab7c6e9 100644 --- a/src/components/Features/FeatureGroup.test.js +++ b/src/components/Features/FeatureGroup.test.js @@ -26,7 +26,6 @@ describe("FeatureGroup", () => { afterEach(() => { document.body.outerHTML = '' permissions.$reset() - vi.clearAllMocks() }) test('properly renders a group', async () => { diff --git a/src/components/Features/SingleItemCertificationBodyForm.test.js b/src/components/Features/SingleItemCertificationBodyForm.test.js index ecc25a8c..81e27a7f 100644 --- a/src/components/Features/SingleItemCertificationBodyForm.test.js +++ b/src/components/Features/SingleItemCertificationBodyForm.test.js @@ -51,7 +51,6 @@ describe("SingleItemCertificationBodyForm", () => { afterEach(() => { document.body.outerHTML = '' - vi.clearAllMocks() }) test("we assign a certification state", async () => { diff --git a/src/components/Features/Table.test.js b/src/components/Features/Table.test.js index 4b82b3d3..3ebf638d 100644 --- a/src/components/Features/Table.test.js +++ b/src/components/Features/Table.test.js @@ -32,7 +32,6 @@ describe("Features Table", () => { afterEach(() => { document.body.outerHTML = '' - vi.clearAllMocks() }) test("features are listed as 3 groups of 2 and 1 and 2 features (one being multi-crops)", () => { diff --git a/src/components/OperatorSetup/index.test.js b/src/components/OperatorSetup/index.test.js index 353ff5dc..30c70029 100644 --- a/src/components/OperatorSetup/index.test.js +++ b/src/components/OperatorSetup/index.test.js @@ -1,4 +1,4 @@ -import { afterEach, beforeAll, describe, it, expect, vi } from "vitest" +import { beforeAll, describe, it, expect } from "vitest" import { mount, flushPromises } from "@vue/test-utils" import { createPinia, setActivePinia } from "pinia" @@ -27,7 +27,6 @@ describe("OperatorSetup", () => { ] }) }) - afterEach(() => vi.clearAllMocks()) it("should render only telepac tab if there is only telepac source in props", () => { const wrapper = mount(OperatorSetup, { diff --git a/tests-setup.js b/tests-setup.js index 5a96c545..ac74b8be 100644 --- a/tests-setup.js +++ b/tests-setup.js @@ -30,6 +30,8 @@ vi.mock('maplibre-gl', () => ({ getLayer: vi.fn(), getSource: vi.fn(), getStyle: vi.fn().mockImplementation(() => ({layers: []})), + isStyleLoaded: vi.fn().mockReturnValue(true), + setLayoutProperty: vi.fn(), resize: vi.fn(), })), NavigationControl: vi.fn(), diff --git a/widget/Notification.test.js b/widget/Notification.test.js index e12baccb..6792b1ac 100644 --- a/widget/Notification.test.js +++ b/widget/Notification.test.js @@ -1,4 +1,4 @@ -import { afterEach, beforeEach, describe, expect, it, vi } from "vitest" +import { beforeEach, describe, expect, it, vi } from "vitest" import { mount } from "@vue/test-utils" import Notification from "./Notification.ce.vue" @@ -17,10 +17,6 @@ describe("Notification", () => { setActivePinia(createPinia()) }) - afterEach(() => { - vi.clearAllMocks() - }) - it("should render loading state then Telepac form", async () => { const wrapper = mount(Notification, { props: { From d63b30a6f9971fac7e21d3c6656d4fc4f6c60c9c Mon Sep 17 00:00:00 2001 From: Thomas Parisot Date: Mon, 18 Dec 2023 20:14:49 +0100 Subject: [PATCH 2/4] =?UTF-8?q?feat(Map):=20affiche=20l'attribution=20comp?= =?UTF-8?q?acte=20et=20l'=C3=A9chelle?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Map/MapContainer.test.js | 42 ++++++++++++++ src/components/Map/MapContainer.vue | 76 +++++++++++++++++-------- tests-setup.js | 3 + 3 files changed, 98 insertions(+), 23 deletions(-) create mode 100644 src/components/Map/MapContainer.test.js diff --git a/src/components/Map/MapContainer.test.js b/src/components/Map/MapContainer.test.js new file mode 100644 index 00000000..47e3fcf5 --- /dev/null +++ b/src/components/Map/MapContainer.test.js @@ -0,0 +1,42 @@ +import { describe, expect, test, vi } from "vitest" +import { mount } from "@vue/test-utils" +import { NavigationControl, ScaleControl } from 'maplibre-gl' + +import MapContainer from "./MapContainer.vue" + +describe("MapContainer", () => { + test('we display navigation with no interactive elements', async () => { + const wrapper = mount(MapContainer, { + props: { controls: false } + }) + + expect(NavigationControl).toHaveBeenCalledTimes(0) + expect(ScaleControl).toHaveBeenCalledTimes(0) + }) + + test('we display navigation control, without attribution', async () => { + const wrapper = mount(MapContainer, { + props: { controls: true } + }) + + expect(NavigationControl).toHaveBeenCalledTimes(1) + expect(ScaleControl).toHaveBeenCalledTimes(0) + + const customMenuSpy = wrapper.vm.map.addControl.mock.calls.at(1) + expect(customMenuSpy).toHaveProperty('0.onAdd') + expect(customMenuSpy).toHaveProperty('1', 'bottom-right') + }) + + test('we display navigation control and attribution', async () => { + const wrapper = mount(MapContainer, { + props: { showAttribution: true } + }) + + expect(NavigationControl).toHaveBeenCalledOnce() + expect(ScaleControl).toHaveBeenCalledOnce() + + const attributionSpy = wrapper.vm.map.addControl.mock.calls.at(2) + expect(attributionSpy).toHaveProperty('0.onAdd') + expect(attributionSpy).toHaveProperty('1', 'bottom-right') + }) +}) diff --git a/src/components/Map/MapContainer.vue b/src/components/Map/MapContainer.vue index 537edb8a..678d083f 100644 --- a/src/components/Map/MapContainer.vue +++ b/src/components/Map/MapContainer.vue @@ -1,16 +1,12 @@