@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
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
buildMenuSectionSchema,
|
|
4
|
+
buildOpeningHoursSpecification,
|
|
5
|
+
buildRestaurantSchema,
|
|
6
|
+
buildSpecialOpeningHoursSpecification,
|
|
7
|
+
} from "../../app/utils/schema";
|
|
8
|
+
|
|
9
|
+
const lunch = (dayOfWeek: number) => ({
|
|
10
|
+
dayOfWeek,
|
|
11
|
+
openingTime: "11:30:00",
|
|
12
|
+
closingTime: "14:30:00",
|
|
13
|
+
});
|
|
14
|
+
const dinner = (dayOfWeek: number) => ({
|
|
15
|
+
dayOfWeek,
|
|
16
|
+
openingTime: "17:30:00",
|
|
17
|
+
closingTime: "23:00:00",
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
describe("buildOpeningHoursSpecification", () => {
|
|
21
|
+
it("groups days with identical intervals", () => {
|
|
22
|
+
// Sunday listed before Saturday in the data, sorted in the output
|
|
23
|
+
const hours = [1, 7, 3, 4, 5].flatMap((day) => [lunch(day), dinner(day)]);
|
|
24
|
+
hours.push(dinner(6));
|
|
25
|
+
|
|
26
|
+
expect(buildOpeningHoursSpecification(hours)).toEqual([
|
|
27
|
+
{
|
|
28
|
+
"@type": "OpeningHoursSpecification",
|
|
29
|
+
dayOfWeek: ["Monday", "Wednesday", "Thursday", "Friday", "Sunday"],
|
|
30
|
+
opens: "11:30",
|
|
31
|
+
closes: "14:30",
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"@type": "OpeningHoursSpecification",
|
|
35
|
+
dayOfWeek: [
|
|
36
|
+
"Monday",
|
|
37
|
+
"Wednesday",
|
|
38
|
+
"Thursday",
|
|
39
|
+
"Friday",
|
|
40
|
+
"Saturday",
|
|
41
|
+
"Sunday",
|
|
42
|
+
],
|
|
43
|
+
opens: "17:30",
|
|
44
|
+
closes: "23:00",
|
|
45
|
+
},
|
|
46
|
+
]);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("skips incomplete entries", () => {
|
|
50
|
+
expect(
|
|
51
|
+
buildOpeningHoursSpecification([
|
|
52
|
+
{ dayOfWeek: 8, openingTime: "11:30", closingTime: "14:30" },
|
|
53
|
+
{ dayOfWeek: 1, openingTime: "11:30" },
|
|
54
|
+
]),
|
|
55
|
+
).toEqual([]);
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
describe("buildSpecialOpeningHoursSpecification", () => {
|
|
60
|
+
it("marks closing days with opens and closes at 00:00", () => {
|
|
61
|
+
expect(
|
|
62
|
+
buildSpecialOpeningHoursSpecification([
|
|
63
|
+
{
|
|
64
|
+
start: "2025-12-29T20:57:00.000+00:00",
|
|
65
|
+
end: "2026-01-01T22:59:00.000+00:00",
|
|
66
|
+
},
|
|
67
|
+
{ start: "2026-07-12T21:00:00.000+00:00" },
|
|
68
|
+
]),
|
|
69
|
+
).toEqual([
|
|
70
|
+
{
|
|
71
|
+
"@type": "OpeningHoursSpecification",
|
|
72
|
+
validFrom: "2025-12-29",
|
|
73
|
+
validThrough: "2026-01-01",
|
|
74
|
+
opens: "00:00",
|
|
75
|
+
closes: "00:00",
|
|
76
|
+
},
|
|
77
|
+
]);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
describe("buildRestaurantSchema", () => {
|
|
82
|
+
const site = {
|
|
83
|
+
name: "Pizzeria La Fattoria",
|
|
84
|
+
description: "Italienisch-deutsche Küche in Obertshausen seit 1997.",
|
|
85
|
+
url: "https://www.pizzeria-lafattoria.de",
|
|
86
|
+
image: "https://www.pizzeria-lafattoria.de/card.png",
|
|
87
|
+
telephone: "+49 6104 71427",
|
|
88
|
+
cuisine: "Italienisch",
|
|
89
|
+
priceRange: "€€",
|
|
90
|
+
googleBusinessProfileUrl: "https://maps.google.com/?cid=123",
|
|
91
|
+
address: {
|
|
92
|
+
street: "Kantstr. 6",
|
|
93
|
+
// a number: Nuxt parses a numeric env value
|
|
94
|
+
postalCode: 63179 as unknown as string,
|
|
95
|
+
city: "Obertshausen",
|
|
96
|
+
country: "DE",
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
it("builds a full Restaurant node with menu sections", () => {
|
|
101
|
+
const schema = buildRestaurantSchema({
|
|
102
|
+
site,
|
|
103
|
+
businessHours: [lunch(1)],
|
|
104
|
+
holidays: [
|
|
105
|
+
{ start: "2026-07-12T21:00:00Z", end: "2026-08-05T22:00:00Z" },
|
|
106
|
+
],
|
|
107
|
+
menuUrl: "https://www.pizzeria-lafattoria.de/speisekarte",
|
|
108
|
+
menuSections: [
|
|
109
|
+
{ name: "Pizza", url: "https://www.pizzeria-lafattoria.de/c/Pizza/" },
|
|
110
|
+
{
|
|
111
|
+
name: "Nudeln",
|
|
112
|
+
sections: [
|
|
113
|
+
{
|
|
114
|
+
name: "Spaghetti",
|
|
115
|
+
url: "https://www.pizzeria-lafattoria.de/c/Nudeln/Spaghetti/",
|
|
116
|
+
},
|
|
117
|
+
],
|
|
118
|
+
},
|
|
119
|
+
],
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
expect(schema).toEqual({
|
|
123
|
+
"@context": "https://schema.org",
|
|
124
|
+
"@type": "Restaurant",
|
|
125
|
+
"@id": "https://www.pizzeria-lafattoria.de#restaurant",
|
|
126
|
+
name: site.name,
|
|
127
|
+
description: site.description,
|
|
128
|
+
url: site.url,
|
|
129
|
+
image: site.image,
|
|
130
|
+
telephone: site.telephone,
|
|
131
|
+
servesCuisine: "Italienisch",
|
|
132
|
+
priceRange: "€€",
|
|
133
|
+
address: {
|
|
134
|
+
"@type": "PostalAddress",
|
|
135
|
+
streetAddress: "Kantstr. 6",
|
|
136
|
+
postalCode: "63179",
|
|
137
|
+
addressLocality: "Obertshausen",
|
|
138
|
+
addressCountry: "DE",
|
|
139
|
+
},
|
|
140
|
+
sameAs: ["https://maps.google.com/?cid=123"],
|
|
141
|
+
openingHoursSpecification: [
|
|
142
|
+
{
|
|
143
|
+
"@type": "OpeningHoursSpecification",
|
|
144
|
+
dayOfWeek: ["Monday"],
|
|
145
|
+
opens: "11:30",
|
|
146
|
+
closes: "14:30",
|
|
147
|
+
},
|
|
148
|
+
],
|
|
149
|
+
specialOpeningHoursSpecification: [
|
|
150
|
+
{
|
|
151
|
+
"@type": "OpeningHoursSpecification",
|
|
152
|
+
validFrom: "2026-07-12",
|
|
153
|
+
validThrough: "2026-08-05",
|
|
154
|
+
opens: "00:00",
|
|
155
|
+
closes: "00:00",
|
|
156
|
+
},
|
|
157
|
+
],
|
|
158
|
+
hasMenu: {
|
|
159
|
+
"@type": "Menu",
|
|
160
|
+
"@id": "https://www.pizzeria-lafattoria.de#menu",
|
|
161
|
+
name: "Speisekarte",
|
|
162
|
+
url: "https://www.pizzeria-lafattoria.de/speisekarte",
|
|
163
|
+
hasMenuSection: [
|
|
164
|
+
{
|
|
165
|
+
"@type": "MenuSection",
|
|
166
|
+
name: "Pizza",
|
|
167
|
+
url: "https://www.pizzeria-lafattoria.de/c/Pizza/",
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
"@type": "MenuSection",
|
|
171
|
+
name: "Nudeln",
|
|
172
|
+
hasMenuSection: [
|
|
173
|
+
{
|
|
174
|
+
"@type": "MenuSection",
|
|
175
|
+
name: "Spaghetti",
|
|
176
|
+
url: "https://www.pizzeria-lafattoria.de/c/Nudeln/Spaghetti/",
|
|
177
|
+
},
|
|
178
|
+
],
|
|
179
|
+
},
|
|
180
|
+
],
|
|
181
|
+
},
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it("leaves empty values out", () => {
|
|
186
|
+
const schema = buildRestaurantSchema({
|
|
187
|
+
site: {
|
|
188
|
+
name: "ShopBite",
|
|
189
|
+
url: "https://example.com",
|
|
190
|
+
telephone: "",
|
|
191
|
+
address: { street: "", postalCode: "", city: "", country: "DE" },
|
|
192
|
+
},
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
expect(schema).toEqual({
|
|
196
|
+
"@context": "https://schema.org",
|
|
197
|
+
"@type": "Restaurant",
|
|
198
|
+
"@id": "https://example.com#restaurant",
|
|
199
|
+
name: "ShopBite",
|
|
200
|
+
url: "https://example.com",
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
describe("buildMenuSectionSchema", () => {
|
|
206
|
+
it("lists the products with offers", () => {
|
|
207
|
+
expect(
|
|
208
|
+
buildMenuSectionSchema({
|
|
209
|
+
name: "Pizza",
|
|
210
|
+
description: "Alle Pizzen mit Tomatensoße und Käse.",
|
|
211
|
+
url: "https://example.com/c/Pizza/",
|
|
212
|
+
currency: "EUR",
|
|
213
|
+
restaurantUrl: "https://example.com",
|
|
214
|
+
items: [
|
|
215
|
+
{
|
|
216
|
+
name: "Pizza Salami",
|
|
217
|
+
description: "mit Salami",
|
|
218
|
+
price: 9.5,
|
|
219
|
+
image: "https://cdn.example.com/salami.webp",
|
|
220
|
+
},
|
|
221
|
+
{ name: "Pizza Tonno", description: "" },
|
|
222
|
+
],
|
|
223
|
+
}),
|
|
224
|
+
).toEqual({
|
|
225
|
+
"@context": "https://schema.org",
|
|
226
|
+
"@type": "MenuSection",
|
|
227
|
+
name: "Pizza",
|
|
228
|
+
description: "Alle Pizzen mit Tomatensoße und Käse.",
|
|
229
|
+
url: "https://example.com/c/Pizza/",
|
|
230
|
+
hasMenuItem: [
|
|
231
|
+
{
|
|
232
|
+
"@type": "MenuItem",
|
|
233
|
+
name: "Pizza Salami",
|
|
234
|
+
description: "mit Salami",
|
|
235
|
+
image: "https://cdn.example.com/salami.webp",
|
|
236
|
+
offers: { "@type": "Offer", price: "9.50", priceCurrency: "EUR" },
|
|
237
|
+
},
|
|
238
|
+
{ "@type": "MenuItem", name: "Pizza Tonno" },
|
|
239
|
+
],
|
|
240
|
+
isPartOf: { "@type": "Menu", "@id": "https://example.com#menu" },
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
});
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
buildHomeDescription,
|
|
4
|
+
buildHomeTitle,
|
|
5
|
+
formatPageTitle,
|
|
6
|
+
toAbsoluteUrl,
|
|
7
|
+
} from "../../app/utils/seo";
|
|
8
|
+
|
|
9
|
+
const TEMPLATE = "%s | %siteName – Online bestellen";
|
|
10
|
+
|
|
11
|
+
describe("formatPageTitle", () => {
|
|
12
|
+
it("applies the title template", () => {
|
|
13
|
+
expect(formatPageTitle("Pizza", "La Fattoria", TEMPLATE)).toBe(
|
|
14
|
+
"Pizza | La Fattoria – Online bestellen",
|
|
15
|
+
);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it("renders the bare site name for a missing or site-name title", () => {
|
|
19
|
+
expect(formatPageTitle(undefined, "La Fattoria", TEMPLATE)).toBe(
|
|
20
|
+
"La Fattoria",
|
|
21
|
+
);
|
|
22
|
+
expect(formatPageTitle("", "La Fattoria", TEMPLATE)).toBe("La Fattoria");
|
|
23
|
+
expect(formatPageTitle("La Fattoria", "La Fattoria", TEMPLATE)).toBe(
|
|
24
|
+
"La Fattoria",
|
|
25
|
+
);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("renders the title as is without a template", () => {
|
|
29
|
+
expect(formatPageTitle("Pizza", "La Fattoria", "")).toBe("Pizza");
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
describe("toAbsoluteUrl", () => {
|
|
34
|
+
it("joins site-relative paths and keeps the trailing slash", () => {
|
|
35
|
+
expect(toAbsoluteUrl("https://example.com", "/c/Pizza/")).toBe(
|
|
36
|
+
"https://example.com/c/Pizza/",
|
|
37
|
+
);
|
|
38
|
+
expect(toAbsoluteUrl("https://example.com/", "/agb")).toBe(
|
|
39
|
+
"https://example.com/agb",
|
|
40
|
+
);
|
|
41
|
+
expect(toAbsoluteUrl("https://example.com", "/")).toBe(
|
|
42
|
+
"https://example.com/",
|
|
43
|
+
);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("keeps absolute and protocol-relative URLs", () => {
|
|
47
|
+
expect(
|
|
48
|
+
toAbsoluteUrl("https://example.com", "https://cdn.example.com/a.webp"),
|
|
49
|
+
).toBe("https://cdn.example.com/a.webp");
|
|
50
|
+
expect(
|
|
51
|
+
toAbsoluteUrl("https://example.com", "//cdn.example.com/a.webp"),
|
|
52
|
+
).toBe("//cdn.example.com/a.webp");
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
describe("buildHomeTitle", () => {
|
|
57
|
+
it("adds the city to the shop name", () => {
|
|
58
|
+
expect(buildHomeTitle({ name: "La Fattoria", city: "Obertshausen" })).toBe(
|
|
59
|
+
"La Fattoria Obertshausen | Online bestellen & liefern lassen",
|
|
60
|
+
);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("does not repeat a city that is already part of the name", () => {
|
|
64
|
+
expect(
|
|
65
|
+
buildHomeTitle({ name: "Pizzeria Obertshausen", city: "Obertshausen" }),
|
|
66
|
+
).toBe("Pizzeria Obertshausen | Online bestellen & liefern lassen");
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("works without a city", () => {
|
|
70
|
+
expect(buildHomeTitle({ name: "La Fattoria", city: "" })).toBe(
|
|
71
|
+
"La Fattoria | Online bestellen & liefern lassen",
|
|
72
|
+
);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
describe("buildHomeDescription", () => {
|
|
77
|
+
it("combines cuisine, city and name", () => {
|
|
78
|
+
expect(
|
|
79
|
+
buildHomeDescription({
|
|
80
|
+
name: "La Fattoria",
|
|
81
|
+
city: "Obertshausen",
|
|
82
|
+
cuisine: "Italienische Küche",
|
|
83
|
+
}),
|
|
84
|
+
).toBe(
|
|
85
|
+
"Italienische Küche in Obertshausen: Bei La Fattoria online bestellen und liefern lassen oder abholen.",
|
|
86
|
+
);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("uses city or cuisine alone", () => {
|
|
90
|
+
expect(
|
|
91
|
+
buildHomeDescription({ name: "La Fattoria", city: "Obertshausen" }),
|
|
92
|
+
).toBe(
|
|
93
|
+
"La Fattoria in Obertshausen: Online bestellen und liefern lassen oder abholen.",
|
|
94
|
+
);
|
|
95
|
+
expect(
|
|
96
|
+
buildHomeDescription({ name: "La Fattoria", cuisine: "Pizza & Pasta" }),
|
|
97
|
+
).toBe(
|
|
98
|
+
"Pizza & Pasta: Bei La Fattoria online bestellen und liefern lassen oder abholen.",
|
|
99
|
+
);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it("returns undefined without city and cuisine", () => {
|
|
103
|
+
expect(
|
|
104
|
+
buildHomeDescription({ name: "La Fattoria", city: "", cuisine: "" }),
|
|
105
|
+
).toBeUndefined();
|
|
106
|
+
});
|
|
107
|
+
});
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { resolveSeoPath } from "../../app/utils/seoPath";
|
|
3
|
+
|
|
4
|
+
type SeoUrl = { seoPathInfo?: string; foreignKey: string };
|
|
5
|
+
|
|
6
|
+
// Backend lookups are case-insensitive but exact on the trailing slash; the
|
|
7
|
+
// fake resolver receives the (router-encoded) path like the real one.
|
|
8
|
+
const resolverFor = (seoUrls: Record<string, SeoUrl>) =>
|
|
9
|
+
vi.fn(async (path: string) => {
|
|
10
|
+
const key = Object.keys(seoUrls).find(
|
|
11
|
+
(seoPath) => seoPath.toLowerCase() === decodeURI(path).toLowerCase(),
|
|
12
|
+
);
|
|
13
|
+
return key ? seoUrls[key]! : null;
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const pizza = { seoPathInfo: "c/Pizza/", foreignKey: "pizza" };
|
|
17
|
+
const margherita = { seoPathInfo: "Pizza-Margherita/21", foreignKey: "p21" };
|
|
18
|
+
const drinks = { seoPathInfo: "c/Getränke/", foreignKey: "drinks" };
|
|
19
|
+
|
|
20
|
+
describe("resolveSeoPath", () => {
|
|
21
|
+
it("returns an exact match without a second lookup or redirect", async () => {
|
|
22
|
+
const resolve = resolverFor({ "/c/Pizza/": pizza });
|
|
23
|
+
|
|
24
|
+
await expect(resolveSeoPath("/c/Pizza/", resolve)).resolves.toEqual({
|
|
25
|
+
match: pizza,
|
|
26
|
+
});
|
|
27
|
+
expect(resolve).toHaveBeenCalledTimes(1);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("adds a missing trailing slash and redirects to the SEO URL", async () => {
|
|
31
|
+
const resolve = resolverFor({ "/c/Pizza/": pizza });
|
|
32
|
+
|
|
33
|
+
await expect(resolveSeoPath("/c/Pizza", resolve)).resolves.toEqual({
|
|
34
|
+
match: pizza,
|
|
35
|
+
redirectPath: "/c/Pizza/",
|
|
36
|
+
});
|
|
37
|
+
expect(resolve).toHaveBeenLastCalledWith("/c/Pizza/");
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("removes a superfluous trailing slash and redirects", async () => {
|
|
41
|
+
const resolve = resolverFor({ "/Pizza-Margherita/21": margherita });
|
|
42
|
+
|
|
43
|
+
await expect(
|
|
44
|
+
resolveSeoPath("/Pizza-Margherita/21/", resolve),
|
|
45
|
+
).resolves.toEqual({
|
|
46
|
+
match: margherita,
|
|
47
|
+
redirectPath: "/Pizza-Margherita/21",
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("redirects a differently cased path to the SEO URL (#244)", async () => {
|
|
52
|
+
const resolve = resolverFor({ "/c/Pizza/": pizza });
|
|
53
|
+
|
|
54
|
+
await expect(resolveSeoPath("/c/pizza/", resolve)).resolves.toEqual({
|
|
55
|
+
match: pizza,
|
|
56
|
+
redirectPath: "/c/Pizza/",
|
|
57
|
+
});
|
|
58
|
+
expect(resolve).toHaveBeenCalledTimes(1);
|
|
59
|
+
|
|
60
|
+
await expect(resolveSeoPath("/c/PIZZA", resolve)).resolves.toEqual({
|
|
61
|
+
match: pizza,
|
|
62
|
+
redirectPath: "/c/Pizza/",
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("does not redirect an encoded path that matches its SEO URL", async () => {
|
|
67
|
+
const resolve = resolverFor({ "/c/Getränke/": drinks });
|
|
68
|
+
|
|
69
|
+
await expect(resolveSeoPath("/c/Getr%C3%A4nke/", resolve)).resolves.toEqual(
|
|
70
|
+
{ match: drinks },
|
|
71
|
+
);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("redirects a technical path to its SEO URL", async () => {
|
|
75
|
+
const resolve = resolverFor({ "/navigation/abc": pizza });
|
|
76
|
+
|
|
77
|
+
await expect(resolveSeoPath("/navigation/abc", resolve)).resolves.toEqual({
|
|
78
|
+
match: pizza,
|
|
79
|
+
redirectPath: "/c/Pizza/",
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("returns no match for unknown paths", async () => {
|
|
84
|
+
const resolve = resolverFor({ "/c/Pizza/": pizza });
|
|
85
|
+
|
|
86
|
+
await expect(resolveSeoPath("/c/Unbekannt", resolve)).resolves.toEqual({
|
|
87
|
+
match: null,
|
|
88
|
+
});
|
|
89
|
+
expect(resolve).toHaveBeenCalledTimes(2);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("keeps matches without SEO path (technical fallback routes)", async () => {
|
|
93
|
+
const resolve = resolverFor({ "/navigation/abc": { foreignKey: "abc" } });
|
|
94
|
+
|
|
95
|
+
await expect(resolveSeoPath("/navigation/abc", resolve)).resolves.toEqual({
|
|
96
|
+
match: { foreignKey: "abc" },
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it("ignores toggled matches without SEO path", async () => {
|
|
101
|
+
const resolve = resolverFor({ "/navigation/abc/": { foreignKey: "abc" } });
|
|
102
|
+
|
|
103
|
+
await expect(resolveSeoPath("/navigation/abc", resolve)).resolves.toEqual({
|
|
104
|
+
match: null,
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it("does not toggle the root path", async () => {
|
|
109
|
+
const resolve = resolverFor({});
|
|
110
|
+
|
|
111
|
+
await expect(resolveSeoPath("/", resolve)).resolves.toEqual({
|
|
112
|
+
match: null,
|
|
113
|
+
});
|
|
114
|
+
expect(resolve).toHaveBeenCalledTimes(1);
|
|
115
|
+
});
|
|
116
|
+
});
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
categoriesToSitemapUrls,
|
|
4
|
+
restoreTrailingSlashes,
|
|
5
|
+
} from "../../server/utils/sitemap";
|
|
6
|
+
|
|
7
|
+
type Category = Parameters<typeof categoriesToSitemapUrls>[0][number];
|
|
8
|
+
// The tests only need a partial category shape.
|
|
9
|
+
const asCategories = (categories: unknown) => categories as Category[];
|
|
10
|
+
|
|
11
|
+
describe("categoriesToSitemapUrls", () => {
|
|
12
|
+
it("maps page categories with SEO URL, lastmod and image", () => {
|
|
13
|
+
const urls = categoriesToSitemapUrls(
|
|
14
|
+
asCategories([
|
|
15
|
+
{
|
|
16
|
+
type: "page",
|
|
17
|
+
seoUrl: "/c/Pizza/",
|
|
18
|
+
createdAt: "2025-01-01T00:00:00.000+00:00",
|
|
19
|
+
updatedAt: "2025-11-17T10:00:00.000+00:00",
|
|
20
|
+
media: { url: "https://cdn.example.com/pizza.webp" },
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
type: "page",
|
|
24
|
+
seoUrl: "/Salate",
|
|
25
|
+
createdAt: "2025-06-29T00:00:00.000+00:00",
|
|
26
|
+
updatedAt: null,
|
|
27
|
+
},
|
|
28
|
+
]),
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
expect(urls).toEqual([
|
|
32
|
+
{
|
|
33
|
+
loc: "/c/Pizza/",
|
|
34
|
+
lastmod: "2025-11-17T10:00:00.000+00:00",
|
|
35
|
+
images: [{ loc: "https://cdn.example.com/pizza.webp" }],
|
|
36
|
+
_trailingSlash: true,
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
loc: "/Salate",
|
|
40
|
+
lastmod: "2025-06-29T00:00:00.000+00:00",
|
|
41
|
+
},
|
|
42
|
+
]);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("skips links, folders, technical and missing URLs and duplicates", () => {
|
|
46
|
+
const urls = categoriesToSitemapUrls(
|
|
47
|
+
asCategories([
|
|
48
|
+
{
|
|
49
|
+
type: "page",
|
|
50
|
+
seoUrl: "/navigation/018d9f1649c9709580aab97a16368d8d",
|
|
51
|
+
},
|
|
52
|
+
{ type: "link", seoUrl: "/agb" },
|
|
53
|
+
{ type: "link", seoUrl: "tel:+491726723920" },
|
|
54
|
+
{ type: "folder", seoUrl: null },
|
|
55
|
+
{ type: "page", seoUrl: "//evil.example.com/" },
|
|
56
|
+
{ type: "page" },
|
|
57
|
+
{ type: "page", seoUrl: "/c/Nudeln/" },
|
|
58
|
+
{ type: "page", seoUrl: "/c/Nudeln/" },
|
|
59
|
+
]),
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
expect(urls.map((url) => url.loc)).toEqual(["/c/Nudeln/"]);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
describe("restoreTrailingSlashes", () => {
|
|
67
|
+
const xml = [
|
|
68
|
+
"<url><loc>https://example.com/c/Pizza</loc>",
|
|
69
|
+
"<image:image><image:loc>https://cdn.example.com/c/Pizza</image:loc></image:image></url>",
|
|
70
|
+
"<url><loc>https://example.com/agb</loc></url>",
|
|
71
|
+
"<url><loc>https://example.com/</loc></url>",
|
|
72
|
+
].join("");
|
|
73
|
+
|
|
74
|
+
it("re-appends the slash to listed paths only", () => {
|
|
75
|
+
expect(restoreTrailingSlashes(xml, new Set(["/c/Pizza"]))).toBe(
|
|
76
|
+
[
|
|
77
|
+
"<url><loc>https://example.com/c/Pizza/</loc>",
|
|
78
|
+
"<image:image><image:loc>https://cdn.example.com/c/Pizza</image:loc></image:image></url>",
|
|
79
|
+
"<url><loc>https://example.com/agb</loc></url>",
|
|
80
|
+
"<url><loc>https://example.com/</loc></url>",
|
|
81
|
+
].join(""),
|
|
82
|
+
);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("returns the sitemap unchanged without paths", () => {
|
|
86
|
+
expect(restoreTrailingSlashes(xml, new Set())).toBe(xml);
|
|
87
|
+
});
|
|
88
|
+
});
|