@shopbite-de/storefront 1.23.2 → 1.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +19 -0
- package/.github/workflows/build.yaml +1 -1
- package/.github/workflows/ci.yaml +6 -3
- package/.nuxtrc +1 -1
- package/CLAUDE.md +41 -3
- package/README.md +139 -40
- package/api-gen.config.json +9 -0
- package/api-types/storeApiSchema.shopbite.overrides.json +35 -0
- package/api-types/storeApiTypes.d.ts +95 -81
- package/app/app.vue +37 -53
- package/app/assets/css/main.css +20 -4
- package/app/components/Address/Fields.vue +2 -21
- package/app/components/AnimatedSection.vue +9 -4
- package/app/components/BottomNavi.vue +9 -2
- package/app/components/Cart/Item.vue +21 -10
- package/app/components/Category/Breadcrumb.vue +11 -12
- package/app/components/Category/Header.vue +9 -3
- package/app/components/Category/Listing.vue +51 -42
- package/app/components/Checkout/PaymentAndDelivery.vue +19 -3
- package/app/components/Checkout/Summary.vue +65 -1
- package/app/components/Cta.vue +4 -2
- package/app/components/Food/MarqueeItem.vue +20 -8
- package/app/components/Footer/Contact.vue +78 -0
- package/app/components/Footer/StoreStatus.vue +30 -0
- package/app/components/Footer.vue +2 -1
- package/app/components/Header/Body.vue +1 -1
- package/app/components/Header/Right.vue +27 -13
- package/app/components/Header/Title.vue +1 -0
- package/app/components/Header.vue +5 -15
- package/app/components/Hero.vue +45 -2
- package/app/components/ImageGallery.vue +11 -5
- package/app/components/Product/Card.vue +9 -3
- package/app/components/Product/CardFooter.vue +22 -12
- package/app/components/User/RegistrationForm.vue +0 -1
- package/app/components/Wishlist.vue +2 -15
- package/app/composables/useAddToCart.ts +13 -13
- package/app/composables/useAddressAutocomplete.ts +12 -19
- package/app/composables/useAddressSuggestionArea.ts +16 -0
- package/app/composables/useAddressValidation.ts +3 -19
- package/app/composables/useCartMutations.ts +168 -0
- package/app/composables/{useCategory.ts → useCategoryById.ts} +1 -1
- package/app/composables/useCategorySeo.ts +22 -25
- package/app/composables/useCheckoutMethodGuard.ts +201 -0
- package/app/composables/useMatomo.ts +25 -0
- package/app/composables/useMatomoConfig.ts +12 -0
- package/app/composables/useMenuSectionSchema.ts +55 -0
- package/app/composables/useNavigation.ts +12 -9
- package/app/composables/usePageSeo.ts +50 -0
- package/app/composables/useRestaurantSchema.ts +64 -0
- package/app/composables/useScrollAnimation.ts +39 -8
- package/app/composables/useSearchTracking.ts +33 -0
- package/app/composables/useSeoUrlRoute.ts +58 -0
- package/app/composables/useSortingSelection.ts +28 -0
- package/app/composables/useStoreStatus.ts +48 -0
- package/app/composables/useTrackEvent.ts +29 -23
- package/app/pages/[...all].vue +4 -4
- package/app/pages/account/recover/password/index.vue +1 -0
- package/app/pages/anmelden.vue +4 -0
- package/app/pages/bestellung/[id]/erfolg.vue +1 -5
- package/app/pages/bestellung/[id]/fehler.vue +2 -2
- package/app/pages/bestellung/[id]/index.vue +10 -4
- package/app/pages/bestellung/bestaetigen.vue +1 -5
- package/app/pages/bestellung/warenkorb.vue +1 -5
- package/app/pages/bestellung/zahlung-versand.vue +1 -5
- package/app/pages/c/[...all].vue +2 -35
- package/app/pages/index.vue +25 -13
- package/app/pages/kontakt.vue +4 -0
- package/app/pages/konto/adressen.vue +4 -0
- package/app/pages/konto/bestellung/[id].vue +4 -0
- package/app/pages/konto/bestellungen.vue +4 -0
- package/app/pages/konto/index.vue +4 -0
- package/app/pages/konto/profil.vue +4 -0
- package/app/pages/maintenance.vue +6 -0
- package/app/pages/merkliste.vue +1 -7
- package/app/pages/passwort-vergessen.vue +1 -0
- package/app/pages/registrierung/bestaetigen.vue +4 -0
- package/app/pages/registrierung/index.vue +4 -0
- package/app/pages/speisekarte/[...all].vue +2 -36
- package/app/pages/suche.vue +24 -21
- package/app/plugins/matomo.ts +35 -0
- package/app/utils/hydrateWhenVisible.ts +20 -0
- package/app/utils/media.ts +33 -0
- package/app/utils/openingHours.ts +67 -0
- package/app/utils/schema.ts +235 -0
- package/app/utils/seo.ts +56 -0
- package/app/utils/seoPath.ts +57 -0
- package/content/index.yml +10 -9
- package/content.config.ts +3 -0
- package/docs/notes/2026-07-05-issue-259-matomo-broken.md +14 -0
- package/docs/notes/2026-09-07-dependency-update.md +113 -0
- package/docs/notes/2026-09-08-issue-240-shipping-method-blocked.md +83 -0
- package/docs/notes/2026-09-08-issue-241-cart-lock-conflicts.md +63 -0
- package/docs/notes/2026-09-08-issue-244-category-url-trailing-slash.md +65 -0
- package/docs/notes/2026-09-08-issue-276-payment-method-blocked.md +39 -0
- package/docs/notes/2026-09-08-issue-277-typecheck.md +99 -0
- package/docs/notes/2026-09-10-issue-250-animated-section.md +23 -0
- package/docs/notes/2026-09-10-issue-251-shop-data-in-base-layer.md +30 -0
- package/docs/notes/2026-09-10-issue-272-restaurant-schema.md +27 -0
- package/docs/notes/2026-09-10-issue-273-performance-media.md +64 -0
- package/docs/notes/2026-09-10-issue-274-seo-basics.md +49 -0
- package/docs/notes/2026-09-10-issue-275-accessibility.md +46 -0
- package/docs/notes/2026-09-10-issue-290-footer-nap.md +28 -0
- package/docs/notes/2026-09-10-issue-291-seo-url-trailing-slash.md +24 -0
- package/docs/notes/2026-09-10-issue-294-matomo-without-config.md +33 -0
- package/docs/notes/2026-09-10-issue-295-search-hydration-mismatch.md +25 -0
- package/docs/notes/2026-09-10-issue-296-track-direct-search.md +19 -0
- package/docs/notes/2026-09-10-issue-312-store-api-criteria-post.md +64 -0
- package/docs/notes/2026-09-10-issue-313-wishlist-scoped-tailwind.md +29 -0
- package/docs/notes/2026-09-10-issue-314-mobile-js-cost.md +119 -0
- package/node.dockerfile +5 -2
- package/nuxt.config.ts +74 -15
- package/package.json +45 -42
- package/patches/@shopware__nuxt-module@1.5.1.patch +32 -0
- package/pnpm-workspace.yaml +2 -0
- package/public/hero-poster.webp +0 -0
- package/server/api/__sitemap__/urls.get.ts +49 -0
- package/server/api/category/[categoryId].get.ts +20 -9
- package/server/api/content/home.get.ts +14 -0
- package/server/api/content/page.get.ts +22 -0
- package/server/api/listing/[categoryId].get.ts +12 -18
- package/server/api/product/[productId]/cross-selling.get.ts +3 -9
- package/server/api/product/[productId].get.ts +4 -8
- package/server/plugins/site-url.ts +13 -0
- package/server/plugins/sitemap-trailing-slash.ts +26 -0
- package/server/utils/sitemap.ts +60 -0
- package/server/utils/storeApi.ts +34 -0
- package/shopware.d.ts +35 -11
- package/test/nuxt/AddressFields.test.ts +2 -73
- package/test/nuxt/AnimatedSection.test.ts +67 -0
- package/test/nuxt/CartItem.test.ts +95 -0
- package/test/nuxt/FooterContact.test.ts +102 -0
- package/test/nuxt/FooterStoreStatus.test.ts +48 -0
- package/test/nuxt/HeaderRight.test.ts +14 -10
- package/test/nuxt/Hero.test.ts +68 -0
- package/test/nuxt/PaymentAndDelivery.test.ts +67 -8
- package/test/nuxt/RegistrationForm.test.ts +20 -6
- package/test/nuxt/useAddToCart.test.ts +34 -1
- package/test/nuxt/useAddressAutocomplete.test.ts +2 -38
- package/test/nuxt/useAddressSuggestionArea.test.ts +27 -0
- package/test/nuxt/useBusinessHours.test.ts +1 -1
- package/test/nuxt/useCartMutations.test.ts +225 -0
- package/test/nuxt/useCategoryListing.test.ts +5 -3
- package/test/nuxt/useCheckoutMethodGuard.test.ts +386 -0
- package/test/nuxt/useProductConfigurator.test.ts +4 -1
- package/test/nuxt/useScrollAnimation.test.ts +55 -49
- package/test/nuxt/useSearchTracking.test.ts +71 -0
- package/test/nuxt/useSeoUrlRoute.test.ts +93 -0
- package/test/nuxt/useStoreStatus.test.ts +77 -0
- package/test/nuxt/useTrackEvent.test.ts +112 -0
- package/test/unit/media.spec.ts +49 -0
- package/test/unit/openingHours.spec.ts +59 -0
- package/test/unit/schema.spec.ts +243 -0
- package/test/unit/seo.spec.ts +107 -0
- package/test/unit/seoPath.spec.ts +116 -0
- package/test/unit/sitemap.spec.ts +88 -0
- package/test/unit/useCategorySeo.spec.ts +40 -30
- package/test/unit/useSortingSelection.spec.ts +39 -0
- package/tsconfig.json +1 -1
- package/app/composables/useValidCitiesForDelivery.ts +0 -12
|
@@ -1,20 +1,35 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
1
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
2
2
|
import { useScrollAnimation } from "~/composables/useScrollAnimation";
|
|
3
3
|
import { mount } from "@vue/test-utils";
|
|
4
4
|
import { defineComponent, nextTick } from "vue";
|
|
5
5
|
|
|
6
|
+
const TestComponent = defineComponent({
|
|
7
|
+
setup() {
|
|
8
|
+
const { isHidden, elementRef } = useScrollAnimation();
|
|
9
|
+
return { isHidden, elementRef };
|
|
10
|
+
},
|
|
11
|
+
template: '<div ref="elementRef"></div>',
|
|
12
|
+
});
|
|
13
|
+
|
|
6
14
|
describe("useScrollAnimation", () => {
|
|
7
15
|
let observeMock: ReturnType<typeof vi.fn>;
|
|
8
16
|
let unobserveMock: ReturnType<typeof vi.fn>;
|
|
9
17
|
let disconnectMock: ReturnType<typeof vi.fn>;
|
|
10
18
|
let intersectionCallback: IntersectionObserverCallback;
|
|
11
19
|
|
|
20
|
+
const intersect = (isIntersecting: boolean) =>
|
|
21
|
+
intersectionCallback(
|
|
22
|
+
[
|
|
23
|
+
{ isIntersecting, target: document.createElement("div") },
|
|
24
|
+
] as unknown as IntersectionObserverEntry[],
|
|
25
|
+
{} as IntersectionObserver,
|
|
26
|
+
);
|
|
27
|
+
|
|
12
28
|
beforeEach(() => {
|
|
13
29
|
observeMock = vi.fn();
|
|
14
30
|
unobserveMock = vi.fn();
|
|
15
31
|
disconnectMock = vi.fn();
|
|
16
32
|
|
|
17
|
-
// Mock IntersectionObserver
|
|
18
33
|
global.IntersectionObserver = vi.fn().mockImplementation(function (
|
|
19
34
|
this: IntersectionObserver,
|
|
20
35
|
callback: IntersectionObserverCallback,
|
|
@@ -26,76 +41,67 @@ describe("useScrollAnimation", () => {
|
|
|
26
41
|
this.disconnect =
|
|
27
42
|
disconnectMock as unknown as IntersectionObserver["disconnect"];
|
|
28
43
|
}) as unknown as typeof IntersectionObserver;
|
|
44
|
+
|
|
45
|
+
vi.stubGlobal("matchMedia", () => ({ matches: false }));
|
|
29
46
|
});
|
|
30
47
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const { isVisible, elementRef } = useScrollAnimation();
|
|
35
|
-
return { isVisible, elementRef };
|
|
36
|
-
},
|
|
37
|
-
template: '<div ref="elementRef"></div>',
|
|
38
|
-
});
|
|
48
|
+
afterEach(() => {
|
|
49
|
+
vi.unstubAllGlobals();
|
|
50
|
+
});
|
|
39
51
|
|
|
52
|
+
it("renders visible before mount and starts observing on mount", async () => {
|
|
40
53
|
const wrapper = mount(TestComponent);
|
|
41
|
-
expect(wrapper.vm.
|
|
54
|
+
expect(wrapper.vm.isHidden).toBe(false);
|
|
55
|
+
|
|
56
|
+
await nextTick();
|
|
57
|
+
expect(global.IntersectionObserver).toHaveBeenCalledWith(
|
|
58
|
+
expect.any(Function),
|
|
59
|
+
expect.objectContaining({ rootMargin: "100000px 0px -100px 0px" }),
|
|
60
|
+
);
|
|
61
|
+
expect(observeMock).toHaveBeenCalled();
|
|
42
62
|
});
|
|
43
63
|
|
|
44
|
-
it("
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
const { isVisible, elementRef } = useScrollAnimation();
|
|
48
|
-
return { isVisible, elementRef };
|
|
49
|
-
},
|
|
50
|
-
template: '<div ref="elementRef"></div>',
|
|
51
|
-
});
|
|
64
|
+
it("keeps an element that is already in view visible and stops observing", async () => {
|
|
65
|
+
const wrapper = mount(TestComponent);
|
|
66
|
+
await nextTick();
|
|
52
67
|
|
|
53
|
-
|
|
68
|
+
intersect(true);
|
|
54
69
|
await nextTick();
|
|
55
70
|
|
|
56
|
-
expect(
|
|
57
|
-
expect(
|
|
71
|
+
expect(wrapper.vm.isHidden).toBe(false);
|
|
72
|
+
expect(unobserveMock).toHaveBeenCalled();
|
|
58
73
|
});
|
|
59
74
|
|
|
60
|
-
it("
|
|
61
|
-
const TestComponent = defineComponent({
|
|
62
|
-
setup() {
|
|
63
|
-
const { isVisible, elementRef } = useScrollAnimation();
|
|
64
|
-
return { isVisible, elementRef };
|
|
65
|
-
},
|
|
66
|
-
template: '<div ref="elementRef"></div>',
|
|
67
|
-
});
|
|
68
|
-
|
|
75
|
+
it("hides an element below the fold until it scrolls into view", async () => {
|
|
69
76
|
const wrapper = mount(TestComponent);
|
|
70
77
|
await nextTick();
|
|
71
78
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
79
|
+
intersect(false);
|
|
80
|
+
await nextTick();
|
|
81
|
+
expect(wrapper.vm.isHidden).toBe(true);
|
|
82
|
+
expect(unobserveMock).not.toHaveBeenCalled();
|
|
75
83
|
|
|
84
|
+
intersect(true);
|
|
76
85
|
await nextTick();
|
|
77
|
-
expect(wrapper.vm.
|
|
78
|
-
expect(unobserveMock).
|
|
86
|
+
expect(wrapper.vm.isHidden).toBe(false);
|
|
87
|
+
expect(unobserveMock).toHaveBeenCalled();
|
|
79
88
|
});
|
|
80
89
|
|
|
81
|
-
it("
|
|
82
|
-
|
|
83
|
-
setup() {
|
|
84
|
-
const { isVisible, elementRef } = useScrollAnimation();
|
|
85
|
-
return { isVisible, elementRef };
|
|
86
|
-
},
|
|
87
|
-
template: '<div ref="elementRef"></div>',
|
|
88
|
-
});
|
|
90
|
+
it("never hides content for users who prefer reduced motion", async () => {
|
|
91
|
+
vi.stubGlobal("matchMedia", () => ({ matches: true }));
|
|
89
92
|
|
|
90
93
|
const wrapper = mount(TestComponent);
|
|
91
94
|
await nextTick();
|
|
92
95
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
+
expect(global.IntersectionObserver).not.toHaveBeenCalled();
|
|
97
|
+
expect(wrapper.vm.isHidden).toBe(false);
|
|
98
|
+
});
|
|
96
99
|
|
|
100
|
+
it("disconnects the observer on unmount", async () => {
|
|
101
|
+
const wrapper = mount(TestComponent);
|
|
97
102
|
await nextTick();
|
|
98
|
-
|
|
99
|
-
|
|
103
|
+
|
|
104
|
+
wrapper.unmount();
|
|
105
|
+
expect(disconnectMock).toHaveBeenCalled();
|
|
100
106
|
});
|
|
101
107
|
});
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
|
+
import { mockNuxtImport } from "@nuxt/test-utils/runtime";
|
|
3
|
+
import { nextTick, ref } from "vue";
|
|
4
|
+
import type { Schemas } from "#shopware";
|
|
5
|
+
import { useSearchTracking } from "../../app/composables/useSearchTracking";
|
|
6
|
+
|
|
7
|
+
const { mockTrackSearch } = vi.hoisted(() => ({ mockTrackSearch: vi.fn() }));
|
|
8
|
+
|
|
9
|
+
mockNuxtImport("useTrackEvent", () => () => ({
|
|
10
|
+
trackSearch: mockTrackSearch,
|
|
11
|
+
}));
|
|
12
|
+
|
|
13
|
+
const products = (...numbers: string[]) =>
|
|
14
|
+
numbers.map((productNumber) => ({ productNumber }) as Schemas["Product"]);
|
|
15
|
+
|
|
16
|
+
describe("useSearchTracking", () => {
|
|
17
|
+
beforeEach(() => {
|
|
18
|
+
vi.clearAllMocks();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("tracks results that are already present on setup (direct page load)", () => {
|
|
22
|
+
useSearchTracking(ref("pizza"), ref(products("21", "22")), ref(false));
|
|
23
|
+
|
|
24
|
+
expect(mockTrackSearch).toHaveBeenCalledTimes(1);
|
|
25
|
+
expect(mockTrackSearch).toHaveBeenCalledWith("pizza", ["21", "22"]);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("waits for the skeleton to disappear (client-side navigation)", async () => {
|
|
29
|
+
const elements = ref(products());
|
|
30
|
+
const showSkeleton = ref(true);
|
|
31
|
+
useSearchTracking(ref("pizza"), elements, showSkeleton);
|
|
32
|
+
|
|
33
|
+
expect(mockTrackSearch).not.toHaveBeenCalled();
|
|
34
|
+
|
|
35
|
+
elements.value = products("21");
|
|
36
|
+
showSkeleton.value = false;
|
|
37
|
+
await nextTick();
|
|
38
|
+
|
|
39
|
+
expect(mockTrackSearch).toHaveBeenCalledTimes(1);
|
|
40
|
+
expect(mockTrackSearch).toHaveBeenCalledWith("pizza", ["21"]);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("tracks a new term once and ignores re-fetches of the same term", async () => {
|
|
44
|
+
const query = ref("pizza");
|
|
45
|
+
const elements = ref(products("21"));
|
|
46
|
+
useSearchTracking(query, elements, ref(false));
|
|
47
|
+
expect(mockTrackSearch).toHaveBeenCalledTimes(1);
|
|
48
|
+
|
|
49
|
+
// sorting change: same term, new results
|
|
50
|
+
elements.value = products("22", "21");
|
|
51
|
+
await nextTick();
|
|
52
|
+
expect(mockTrackSearch).toHaveBeenCalledTimes(1);
|
|
53
|
+
|
|
54
|
+
// new search
|
|
55
|
+
query.value = "salat";
|
|
56
|
+
elements.value = products("12");
|
|
57
|
+
await nextTick();
|
|
58
|
+
expect(mockTrackSearch).toHaveBeenCalledTimes(2);
|
|
59
|
+
expect(mockTrackSearch).toHaveBeenLastCalledWith("salat", ["12"]);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("does not track without a search term", async () => {
|
|
63
|
+
const elements = ref(products());
|
|
64
|
+
useSearchTracking(ref(""), elements, ref(false));
|
|
65
|
+
|
|
66
|
+
elements.value = products("21");
|
|
67
|
+
await nextTick();
|
|
68
|
+
|
|
69
|
+
expect(mockTrackSearch).not.toHaveBeenCalled();
|
|
70
|
+
});
|
|
71
|
+
});
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
|
+
import { mockNuxtImport } from "@nuxt/test-utils/runtime";
|
|
3
|
+
import { ref } from "vue";
|
|
4
|
+
import { useSeoUrlRoute } from "~/composables/useSeoUrlRoute";
|
|
5
|
+
|
|
6
|
+
const { mockResolvePath, mockNavigateTo, routeState } = vi.hoisted(() => ({
|
|
7
|
+
mockResolvePath: vi.fn(),
|
|
8
|
+
mockNavigateTo: vi.fn(),
|
|
9
|
+
routeState: { path: "/c/Pizza/", query: {} as Record<string, string> },
|
|
10
|
+
}));
|
|
11
|
+
|
|
12
|
+
mockNuxtImport("useNavigationSearch", () => () => ({
|
|
13
|
+
resolvePath: mockResolvePath,
|
|
14
|
+
}));
|
|
15
|
+
|
|
16
|
+
mockNuxtImport("useRoute", () => () => routeState);
|
|
17
|
+
|
|
18
|
+
mockNuxtImport("navigateTo", () => mockNavigateTo);
|
|
19
|
+
|
|
20
|
+
// Run the handler directly; no caching between tests.
|
|
21
|
+
mockNuxtImport(
|
|
22
|
+
"useAsyncData",
|
|
23
|
+
() => async (_key: string, handler: () => Promise<unknown>) => {
|
|
24
|
+
const data = ref<unknown>(null);
|
|
25
|
+
const error = ref<unknown>(null);
|
|
26
|
+
try {
|
|
27
|
+
data.value = await handler();
|
|
28
|
+
} catch (e) {
|
|
29
|
+
error.value = e;
|
|
30
|
+
}
|
|
31
|
+
return { data, error };
|
|
32
|
+
},
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
const pizza = {
|
|
36
|
+
seoPathInfo: "c/Pizza/",
|
|
37
|
+
foreignKey: "cat-pizza",
|
|
38
|
+
routeName: "frontend.navigation.page",
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
describe("useSeoUrlRoute", () => {
|
|
42
|
+
beforeEach(() => {
|
|
43
|
+
vi.clearAllMocks();
|
|
44
|
+
routeState.path = "/c/Pizza/";
|
|
45
|
+
routeState.query = {};
|
|
46
|
+
history.replaceState(null, "");
|
|
47
|
+
// the backend lookup is case-insensitive and exact on the trailing slash
|
|
48
|
+
mockResolvePath.mockImplementation(async (path: string) =>
|
|
49
|
+
path.toLowerCase() === "/c/pizza/" ? pizza : null,
|
|
50
|
+
);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("resolves the route and does not redirect on the SEO URL", async () => {
|
|
54
|
+
const { seoUrl } = await useSeoUrlRoute();
|
|
55
|
+
|
|
56
|
+
expect(mockResolvePath).toHaveBeenCalledWith("/c/Pizza/");
|
|
57
|
+
expect(seoUrl.value).toEqual(pizza);
|
|
58
|
+
expect(mockNavigateTo).not.toHaveBeenCalled();
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("redirects permanently to the SEO URL for an alias, keeping the query", async () => {
|
|
62
|
+
routeState.path = "/c/pizza";
|
|
63
|
+
routeState.query = { page: "2" };
|
|
64
|
+
|
|
65
|
+
const { seoUrl } = await useSeoUrlRoute();
|
|
66
|
+
|
|
67
|
+
expect(seoUrl.value).toEqual(pizza);
|
|
68
|
+
expect(mockNavigateTo).toHaveBeenCalledWith(
|
|
69
|
+
{ path: "/c/Pizza/", query: { page: "2" } },
|
|
70
|
+
{ redirectCode: 301, replace: true },
|
|
71
|
+
);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("throws a 404 when the path cannot be resolved", async () => {
|
|
75
|
+
routeState.path = "/c/Unbekannt/";
|
|
76
|
+
|
|
77
|
+
await expect(useSeoUrlRoute()).rejects.toMatchObject({ statusCode: 404 });
|
|
78
|
+
expect(mockNavigateTo).not.toHaveBeenCalled();
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("uses the history state from client-side navigation without a request", async () => {
|
|
82
|
+
history.replaceState(
|
|
83
|
+
{ routeName: "frontend.navigation.page", foreignKey: "cat-from-link" },
|
|
84
|
+
"",
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
const { seoUrl } = await useSeoUrlRoute();
|
|
88
|
+
|
|
89
|
+
expect(mockResolvePath).not.toHaveBeenCalled();
|
|
90
|
+
expect(seoUrl.value?.foreignKey).toBe("cat-from-link");
|
|
91
|
+
expect(mockNavigateTo).not.toHaveBeenCalled();
|
|
92
|
+
});
|
|
93
|
+
});
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
2
|
+
import { mockNuxtImport } from "@nuxt/test-utils/runtime";
|
|
3
|
+
import { ref } from "vue";
|
|
4
|
+
import { useStoreStatus } from "../../app/composables/useStoreStatus";
|
|
5
|
+
|
|
6
|
+
const { state } = vi.hoisted(() => ({
|
|
7
|
+
state: {
|
|
8
|
+
businessHours: null as null | object[],
|
|
9
|
+
holidays: null as null | object[],
|
|
10
|
+
open: false,
|
|
11
|
+
intervals: [] as { start: Date; end: Date }[],
|
|
12
|
+
nextOpening: null as string | null,
|
|
13
|
+
},
|
|
14
|
+
}));
|
|
15
|
+
|
|
16
|
+
mockNuxtImport("useBusinessHours", () => () => ({
|
|
17
|
+
businessHours: ref(state.businessHours),
|
|
18
|
+
getServiceIntervals: () => state.intervals,
|
|
19
|
+
isStoreOpen: () => state.open,
|
|
20
|
+
getNextOpeningTime: () => state.nextOpening,
|
|
21
|
+
}));
|
|
22
|
+
|
|
23
|
+
mockNuxtImport("useHolidays", () => () => ({
|
|
24
|
+
holidays: ref(state.holidays),
|
|
25
|
+
isClosedHoliday: () => false,
|
|
26
|
+
}));
|
|
27
|
+
|
|
28
|
+
const at = (hours: number, minutes = 0) => {
|
|
29
|
+
const date = new Date();
|
|
30
|
+
date.setHours(hours, minutes, 0, 0);
|
|
31
|
+
return date;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
describe("useStoreStatus", () => {
|
|
35
|
+
beforeEach(() => {
|
|
36
|
+
vi.useFakeTimers();
|
|
37
|
+
vi.setSystemTime(at(12, 30));
|
|
38
|
+
state.businessHours = [{}];
|
|
39
|
+
state.holidays = [];
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
afterEach(() => {
|
|
43
|
+
vi.useRealTimers();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("is unknown until business hours and holidays are loaded", () => {
|
|
47
|
+
state.businessHours = null;
|
|
48
|
+
expect(useStoreStatus().status.value).toBeNull();
|
|
49
|
+
|
|
50
|
+
state.businessHours = [{}];
|
|
51
|
+
state.holidays = null;
|
|
52
|
+
expect(useStoreStatus().status.value).toBeNull();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("reports the closing time of the current interval when open", () => {
|
|
56
|
+
state.open = true;
|
|
57
|
+
state.intervals = [
|
|
58
|
+
{ start: at(11, 30), end: at(14, 30) },
|
|
59
|
+
{ start: at(17, 30), end: at(23, 0) },
|
|
60
|
+
];
|
|
61
|
+
|
|
62
|
+
expect(useStoreStatus().status.value).toEqual({
|
|
63
|
+
open: true,
|
|
64
|
+
closesAt: "14:30",
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("reports the next opening when closed", () => {
|
|
69
|
+
state.open = false;
|
|
70
|
+
state.nextOpening = "17:30 Uhr";
|
|
71
|
+
|
|
72
|
+
expect(useStoreStatus().status.value).toEqual({
|
|
73
|
+
open: false,
|
|
74
|
+
nextOpening: "17:30 Uhr",
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
});
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
|
+
import { mockNuxtImport } from "@nuxt/test-utils/runtime";
|
|
3
|
+
import { useMatomo } from "../../app/composables/useMatomo";
|
|
4
|
+
import { useTrackEvent } from "../../app/composables/useTrackEvent";
|
|
5
|
+
|
|
6
|
+
const { mockUseScriptMatomoAnalytics } = vi.hoisted(() => ({
|
|
7
|
+
mockUseScriptMatomoAnalytics: vi.fn(() => ({
|
|
8
|
+
proxy: { _paq: { push: vi.fn() } },
|
|
9
|
+
})),
|
|
10
|
+
}));
|
|
11
|
+
|
|
12
|
+
mockNuxtImport("useScriptMatomoAnalytics", () => mockUseScriptMatomoAnalytics);
|
|
13
|
+
|
|
14
|
+
// A useRuntimeConfig mock would also have to provide `app.baseURL` for the
|
|
15
|
+
// router setup of the test environment; setting the real config is simpler.
|
|
16
|
+
function setMatomoConfig(matomoUrl: string, siteId: string | number) {
|
|
17
|
+
Object.assign(useRuntimeConfig().public.scripts.matomoAnalytics, {
|
|
18
|
+
matomoUrl,
|
|
19
|
+
siteId,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
describe("useMatomo", () => {
|
|
24
|
+
beforeEach(() => {
|
|
25
|
+
vi.clearAllMocks();
|
|
26
|
+
setMatomoConfig("", "");
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("does not create the script without configuration", () => {
|
|
30
|
+
expect(useMatomo()).toBeNull();
|
|
31
|
+
expect(mockUseScriptMatomoAnalytics).not.toHaveBeenCalled();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("does not create the script with an incomplete configuration", () => {
|
|
35
|
+
setMatomoConfig("", 3);
|
|
36
|
+
expect(useMatomo()).toBeNull();
|
|
37
|
+
|
|
38
|
+
setMatomoConfig("https://analytics.example.com/", "");
|
|
39
|
+
expect(useMatomo()).toBeNull();
|
|
40
|
+
|
|
41
|
+
expect(mockUseScriptMatomoAnalytics).not.toHaveBeenCalled();
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("creates the script once Matomo URL and site ID are set", () => {
|
|
45
|
+
setMatomoConfig("https://analytics.example.com/", 3);
|
|
46
|
+
|
|
47
|
+
expect(useMatomo()).not.toBeNull();
|
|
48
|
+
expect(mockUseScriptMatomoAnalytics).toHaveBeenCalledWith({
|
|
49
|
+
watch: false,
|
|
50
|
+
scriptOptions: { trigger: "onNuxtReady" },
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
describe("useTrackEvent", () => {
|
|
56
|
+
const matomoWindow = window as Window & { _paq?: unknown[][] };
|
|
57
|
+
|
|
58
|
+
beforeEach(() => {
|
|
59
|
+
vi.clearAllMocks();
|
|
60
|
+
setMatomoConfig("", "");
|
|
61
|
+
// @nuxt/scripts declares `_paq` as always present; the queue only exists
|
|
62
|
+
// once something was pushed.
|
|
63
|
+
Reflect.deleteProperty(matomoWindow, "_paq");
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("is a no-op without Matomo configuration", () => {
|
|
67
|
+
const { trackSearch } = useTrackEvent();
|
|
68
|
+
|
|
69
|
+
expect(() => trackSearch("pizza", ["21", "22"])).not.toThrow();
|
|
70
|
+
expect(mockUseScriptMatomoAnalytics).not.toHaveBeenCalled();
|
|
71
|
+
expect(matomoWindow._paq).toBeUndefined();
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
// The commands land in Matomo's own `_paq` queue, so they do not depend on
|
|
75
|
+
// the registry script, which is loaded after `onNuxtReady` (#314).
|
|
76
|
+
it("queues tracking commands in _paq when Matomo is configured", () => {
|
|
77
|
+
setMatomoConfig("https://analytics.example.com/", 3);
|
|
78
|
+
|
|
79
|
+
const { trackSearch } = useTrackEvent();
|
|
80
|
+
trackSearch("pizza", ["21", "22"]);
|
|
81
|
+
|
|
82
|
+
expect(matomoWindow._paq).toEqual([["trackSiteSearch", "pizza", false, 2]]);
|
|
83
|
+
expect(mockUseScriptMatomoAnalytics).not.toHaveBeenCalled();
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it("tracks a page view with URL and title", () => {
|
|
87
|
+
setMatomoConfig("https://analytics.example.com/", 3);
|
|
88
|
+
document.title = "Pizza";
|
|
89
|
+
|
|
90
|
+
useTrackEvent().trackPageView("/c/Pizza/");
|
|
91
|
+
|
|
92
|
+
expect(matomoWindow._paq).toEqual([
|
|
93
|
+
["setCustomUrl", "/c/Pizza/"],
|
|
94
|
+
["setDocumentTitle", "Pizza"],
|
|
95
|
+
["trackPageView"],
|
|
96
|
+
]);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it("appends to an existing _paq queue", () => {
|
|
100
|
+
setMatomoConfig("https://analytics.example.com/", 3);
|
|
101
|
+
matomoWindow._paq = [["setSiteId", "3"]];
|
|
102
|
+
|
|
103
|
+
useTrackEvent().trackAddToWishlist({
|
|
104
|
+
productNumber: "21",
|
|
105
|
+
} as Parameters<ReturnType<typeof useTrackEvent>["trackAddToWishlist"]>[0]);
|
|
106
|
+
|
|
107
|
+
expect(matomoWindow._paq).toEqual([
|
|
108
|
+
["setSiteId", "3"],
|
|
109
|
+
["trackEvent", "Product", "AddToWishlist", "21"],
|
|
110
|
+
]);
|
|
111
|
+
});
|
|
112
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { mediaSize, mediaSrcSet } from "../../app/utils/media";
|
|
3
|
+
|
|
4
|
+
describe("mediaSrcSet", () => {
|
|
5
|
+
it("lists the thumbnails by width", () => {
|
|
6
|
+
expect(
|
|
7
|
+
mediaSrcSet({
|
|
8
|
+
url: "https://cdn.example.com/media/pizza.webp",
|
|
9
|
+
thumbnails: [
|
|
10
|
+
{
|
|
11
|
+
url: "https://cdn.example.com/thumbnail/pizza_1920x545.webp",
|
|
12
|
+
width: 1920,
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
url: "https://cdn.example.com/thumbnail/pizza_400x114.webp",
|
|
16
|
+
width: 400,
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
url: "https://cdn.example.com/thumbnail/pizza_800x227.webp",
|
|
20
|
+
width: 800,
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
}),
|
|
24
|
+
).toBe(
|
|
25
|
+
"https://cdn.example.com/thumbnail/pizza_400x114.webp 400w, https://cdn.example.com/thumbnail/pizza_800x227.webp 800w, https://cdn.example.com/thumbnail/pizza_1920x545.webp 1920w",
|
|
26
|
+
);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("skips incomplete thumbnails and returns undefined without any", () => {
|
|
30
|
+
expect(
|
|
31
|
+
mediaSrcSet({ thumbnails: [{ url: "x" }, { width: 400 }] }),
|
|
32
|
+
).toBeUndefined();
|
|
33
|
+
expect(mediaSrcSet({ thumbnails: [] })).toBeUndefined();
|
|
34
|
+
expect(mediaSrcSet({ thumbnails: null })).toBeUndefined();
|
|
35
|
+
expect(mediaSrcSet(undefined)).toBeUndefined();
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
describe("mediaSize", () => {
|
|
40
|
+
it("returns the intrinsic size from the meta data", () => {
|
|
41
|
+
expect(mediaSize({ metaData: { width: 4928, height: 1400 } })).toEqual({
|
|
42
|
+
width: 4928,
|
|
43
|
+
height: 1400,
|
|
44
|
+
});
|
|
45
|
+
expect(mediaSize({ metaData: { width: 4928 } })).toBeUndefined();
|
|
46
|
+
expect(mediaSize({ metaData: null })).toBeUndefined();
|
|
47
|
+
expect(mediaSize(null)).toBeUndefined();
|
|
48
|
+
});
|
|
49
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { groupOpeningHours, toTelHref } from "../../app/utils/openingHours";
|
|
3
|
+
|
|
4
|
+
const lunch = (dayOfWeek: number) => ({
|
|
5
|
+
dayOfWeek,
|
|
6
|
+
openingTime: "11:30:00",
|
|
7
|
+
closingTime: "14:30:00",
|
|
8
|
+
});
|
|
9
|
+
const dinner = (dayOfWeek: number) => ({
|
|
10
|
+
dayOfWeek,
|
|
11
|
+
openingTime: "17:30",
|
|
12
|
+
closingTime: "23:00",
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
describe("groupOpeningHours", () => {
|
|
16
|
+
it("groups consecutive days with identical intervals", () => {
|
|
17
|
+
// Pizzeria La Fattoria: closed on Tuesday, Saturday dinner only
|
|
18
|
+
const businessHours = [1, 3, 4, 5, 7].flatMap((day) => [
|
|
19
|
+
dinner(day),
|
|
20
|
+
lunch(day),
|
|
21
|
+
]);
|
|
22
|
+
businessHours.push(dinner(6));
|
|
23
|
+
|
|
24
|
+
expect(groupOpeningHours(businessHours)).toEqual([
|
|
25
|
+
{ days: "Mo", intervals: ["11:30–14:30", "17:30–23:00"] },
|
|
26
|
+
{ days: "Di", intervals: [] },
|
|
27
|
+
{ days: "Mi–Fr", intervals: ["11:30–14:30", "17:30–23:00"] },
|
|
28
|
+
{ days: "Sa", intervals: ["17:30–23:00"] },
|
|
29
|
+
{ days: "So", intervals: ["11:30–14:30", "17:30–23:00"] },
|
|
30
|
+
]);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("groups the whole week into one row", () => {
|
|
34
|
+
expect(
|
|
35
|
+
groupOpeningHours([1, 2, 3, 4, 5, 6, 7].map((day) => dinner(day))),
|
|
36
|
+
).toEqual([{ days: "Mo–So", intervals: ["17:30–23:00"] }]);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("groups trailing closed days", () => {
|
|
40
|
+
expect(groupOpeningHours([1, 2, 3, 4, 5].map(lunch))).toEqual([
|
|
41
|
+
{ days: "Mo–Fr", intervals: ["11:30–14:30"] },
|
|
42
|
+
{ days: "Sa–So", intervals: [] },
|
|
43
|
+
]);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("returns no rows without usable opening hours", () => {
|
|
47
|
+
expect(groupOpeningHours([])).toEqual([]);
|
|
48
|
+
expect(groupOpeningHours([{ dayOfWeek: 1, openingTime: "11:30" }])).toEqual(
|
|
49
|
+
[],
|
|
50
|
+
);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
describe("toTelHref", () => {
|
|
55
|
+
it("strips formatting from the phone number", () => {
|
|
56
|
+
expect(toTelHref("+49 6104 71427")).toBe("tel:+49610471427");
|
|
57
|
+
expect(toTelHref("06104 / 71-427")).toBe("tel:0610471427");
|
|
58
|
+
});
|
|
59
|
+
});
|