diff --git a/.changeset/rich-snakes-suffer.md b/.changeset/rich-snakes-suffer.md new file mode 100644 index 000000000..40e356164 --- /dev/null +++ b/.changeset/rich-snakes-suffer.md @@ -0,0 +1,5 @@ +--- +"@shopware-pwa/composables-next": minor +--- + +Allow to pass full seach criteria according to loadNavigationElements method of useNavigation composable diff --git a/packages/composables/src/useNavigation/useNavigation.test.ts b/packages/composables/src/useNavigation/useNavigation.test.ts index 813073dcf..703c8be0c 100644 --- a/packages/composables/src/useNavigation/useNavigation.test.ts +++ b/packages/composables/src/useNavigation/useNavigation.test.ts @@ -48,4 +48,21 @@ describe("useNavigation", () => { ); expect(vm.navigationElements).toStrictEqual([]); }); + + it("should pass criteria to the api call", async () => { + const { vm, injections } = useSetup(useNavigation); + injections.apiClient.invoke.mockResolvedValue({ data: undefined }); + vi.spyOn(injections.apiClient, "invoke").mockImplementation(() => {}); + + await vm.loadNavigationElements({ + depth: 2, + includes: { category: ["name"] }, + }); + expect(injections.apiClient.invoke).toHaveBeenCalledWith( + expect.stringContaining("readNavigation"), + expect.objectContaining({ + body: { depth: 2, includes: { category: ["name"] } }, + }), + ); + }); }); diff --git a/packages/composables/src/useNavigation/useNavigation.ts b/packages/composables/src/useNavigation/useNavigation.ts index 5adfba595..fb4b6bf03 100644 --- a/packages/composables/src/useNavigation/useNavigation.ts +++ b/packages/composables/src/useNavigation/useNavigation.ts @@ -1,7 +1,7 @@ import { computed, inject, provide, ref } from "vue"; import type { ComputedRef, Ref } from "vue"; import { useShopwareContext } from "#imports"; -import type { Schemas } from "#shopware"; +import type { Schemas, operations } from "#shopware"; /** * @@ -15,9 +15,9 @@ export type UseNavigationReturn = { /** * Load navigation elements */ - loadNavigationElements(params: { - depth: number; - }): Promise; + loadNavigationElements( + params: operations["readNavigation post /navigation/{activeId}/{rootId}"]["body"], + ): Promise; }; /** @@ -49,7 +49,9 @@ export function useNavigation(params?: { const navigationElements = computed(() => sharedElements.value); - async function loadNavigationElements({ depth }: { depth: number }) { + async function loadNavigationElements( + params: operations["readNavigation post /navigation/{activeId}/{rootId}"]["body"], + ) { try { const navigationResponse = await apiClient.invoke( "readNavigation post /navigation/{activeId}/{rootId}", @@ -61,9 +63,7 @@ export function useNavigation(params?: { activeId: type, rootId: type, }, - body: { - depth, - }, + body: params, }, );