create-abcart-theme 0.0.0-stage → 0.10.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.
Files changed (253) hide show
  1. package/CHANGELOG.md +127 -0
  2. package/LICENSE +202 -0
  3. package/NOTICE +2 -0
  4. package/README.md +64 -2
  5. package/bin/create-abcart-theme.mjs +4 -0
  6. package/package.json +47 -4
  7. package/src/args.mjs +113 -0
  8. package/src/banner.mjs +21 -0
  9. package/src/cli.mjs +119 -0
  10. package/src/create.mjs +82 -0
  11. package/src/package-manager.mjs +32 -0
  12. package/src/style.mjs +17 -0
  13. package/templates/default/.agents/skills/shopify-theme-asset-collector/SKILL.md +125 -0
  14. package/templates/default/.agents/skills/shopify-theme-asset-collector/scripts/collect_public_assets.py +370 -0
  15. package/templates/default/.agents/skills/wocart-docs/SKILL.md +146 -0
  16. package/templates/default/.agents/skills/wocart-theme-from-design/SKILL.md +58 -0
  17. package/templates/default/.agents/skills/wocart-theme-from-design/references/inputs-and-rights.md +47 -0
  18. package/templates/default/.agents/skills/wocart-theme-from-design/references/layout-rtl-and-phone.md +36 -0
  19. package/templates/default/.agents/skills/wocart-theme-from-design/references/measure-the-design.md +60 -0
  20. package/templates/default/.agents/skills/wocart-theme-from-design/references/tokens-sections-content.md +103 -0
  21. package/templates/default/.agents/skills/wocart-theme-from-design/references/verify-and-report.md +102 -0
  22. package/templates/default/.agents/skills/wocart-theme-from-design/scripts/compare-design.cjs +230 -0
  23. package/templates/default/.agents/skills/wocart-theme-from-design/scripts/qa-pages.cjs +219 -0
  24. package/templates/default/.dev.vars.example +12 -0
  25. package/templates/default/AGENTS.md +240 -0
  26. package/templates/default/README.md +184 -0
  27. package/templates/default/_gitignore +11 -0
  28. package/templates/default/astro.config.mjs +85 -0
  29. package/templates/default/package.json +36 -0
  30. package/templates/default/public/fonts/OFL.txt +96 -0
  31. package/templates/default/public/fonts/alexandria-arabic.woff2 +0 -0
  32. package/templates/default/public/fonts/fraunces-latin.woff2 +0 -0
  33. package/templates/default/src/actions/index.ts +22 -0
  34. package/templates/default/src/components/cart/AddToCartButton.astro +45 -0
  35. package/templates/default/src/components/cart/CartDrawer.astro +47 -0
  36. package/templates/default/src/components/cart/CartSummary.astro +11 -0
  37. package/templates/default/src/components/cart/FreeShipping.astro +7 -0
  38. package/templates/default/src/components/checkout/CheckoutMain.astro +29 -0
  39. package/templates/default/src/components/checkout/OrderForm.astro +280 -0
  40. package/templates/default/src/components/checkout/ThankYouMain.astro +68 -0
  41. package/templates/default/src/components/landing/LandingImages.astro +51 -0
  42. package/templates/default/src/components/landing/LandingOrder.astro +46 -0
  43. package/templates/default/src/components/landing/LandingProduct.astro +41 -0
  44. package/templates/default/src/components/listing/ListingMain.astro +93 -0
  45. package/templates/default/src/components/listing/PageMain.astro +52 -0
  46. package/templates/default/src/components/listing/Pagination.astro +31 -0
  47. package/templates/default/src/components/listing/SortControl.astro +35 -0
  48. package/templates/default/src/components/product/BuyBox.astro +96 -0
  49. package/templates/default/src/components/product/Description.astro +24 -0
  50. package/templates/default/src/components/product/Gallery.astro +66 -0
  51. package/templates/default/src/components/product/MobileBuyBar.astro +29 -0
  52. package/templates/default/src/components/product/OfferChoice.astro +66 -0
  53. package/templates/default/src/components/product/ProductMain.astro +40 -0
  54. package/templates/default/src/components/product/ProductReviews.astro +72 -0
  55. package/templates/default/src/components/product/RelatedProducts.astro +30 -0
  56. package/templates/default/src/components/product/blocks/BenefitsBlock.astro +13 -0
  57. package/templates/default/src/components/product/blocks/CollapsibleBlock.astro +20 -0
  58. package/templates/default/src/components/product/blocks/DescriptionBlock.astro +19 -0
  59. package/templates/default/src/components/product/blocks/DetailsBlock.astro +33 -0
  60. package/templates/default/src/components/product/blocks/GalleryBlock.astro +12 -0
  61. package/templates/default/src/components/product/blocks/OrderBlock.astro +30 -0
  62. package/templates/default/src/components/product/blocks/PriceBlock.astro +23 -0
  63. package/templates/default/src/components/product/blocks/RatingBlock.astro +16 -0
  64. package/templates/default/src/components/product/blocks/StockBlock.astro +22 -0
  65. package/templates/default/src/components/product/blocks/TextBlock.astro +11 -0
  66. package/templates/default/src/components/product/blocks/TitleBlock.astro +20 -0
  67. package/templates/default/src/components/reviews/ReviewCard.astro +46 -0
  68. package/templates/default/src/components/reviews/ReviewForm.astro +113 -0
  69. package/templates/default/src/components/reviews/VoiceNote.astro +60 -0
  70. package/templates/default/src/components/sections/CollectionCards.astro +65 -0
  71. package/templates/default/src/components/sections/Countdown.astro +57 -0
  72. package/templates/default/src/components/sections/Faq.astro +44 -0
  73. package/templates/default/src/components/sections/FeaturedProduct.astro +71 -0
  74. package/templates/default/src/components/sections/Hero.astro +99 -0
  75. package/templates/default/src/components/sections/ImageBanner.astro +46 -0
  76. package/templates/default/src/components/sections/ProductGrid.astro +47 -0
  77. package/templates/default/src/components/sections/RichText.astro +35 -0
  78. package/templates/default/src/components/sections/Steps.astro +46 -0
  79. package/templates/default/src/components/sections/Testimonials.astro +57 -0
  80. package/templates/default/src/components/shell/Footer.astro +80 -0
  81. package/templates/default/src/components/shell/Header.astro +89 -0
  82. package/templates/default/src/components/shell/LanguageMenu.astro +33 -0
  83. package/templates/default/src/components/shell/MobileMenu.astro +65 -0
  84. package/templates/default/src/components/shell/SearchDialog.astro +19 -0
  85. package/templates/default/src/components/shell/TopBar.astro +54 -0
  86. package/templates/default/src/components/shell/WhatsAppWidget.astro +111 -0
  87. package/templates/default/src/components/store/ContactMain.astro +79 -0
  88. package/templates/default/src/components/store/SearchMain.astro +56 -0
  89. package/templates/default/src/components/store/TrackOrderMain.astro +161 -0
  90. package/templates/default/src/components/surface/Area.astro +20 -0
  91. package/templates/default/src/components/surface/PreviewBridge.astro +24 -0
  92. package/templates/default/src/components/surface/Sections.astro +35 -0
  93. package/templates/default/src/components/ui/Breadcrumbs.astro +36 -0
  94. package/templates/default/src/components/ui/Button.astro +45 -0
  95. package/templates/default/src/components/ui/EditorPlaceholder.astro +24 -0
  96. package/templates/default/src/components/ui/Icon.astro +93 -0
  97. package/templates/default/src/components/ui/Logo.astro +36 -0
  98. package/templates/default/src/components/ui/Photo.astro +46 -0
  99. package/templates/default/src/components/ui/Price.astro +24 -0
  100. package/templates/default/src/components/ui/ProductCard.astro +41 -0
  101. package/templates/default/src/components/ui/Rating.astro +22 -0
  102. package/templates/default/src/components/ui/Section.astro +34 -0
  103. package/templates/default/src/components/ui/SectionHeading.astro +19 -0
  104. package/templates/default/src/env.d.ts +23 -0
  105. package/templates/default/src/layouts/StoreLayout.astro +145 -0
  106. package/templates/default/src/lib/browser-copy.ts +37 -0
  107. package/templates/default/src/lib/context.ts +89 -0
  108. package/templates/default/src/lib/coupon-notice.ts +47 -0
  109. package/templates/default/src/lib/i18n.ts +32 -0
  110. package/templates/default/src/lib/images.ts +38 -0
  111. package/templates/default/src/lib/listing-query.ts +41 -0
  112. package/templates/default/src/lib/money.ts +16 -0
  113. package/templates/default/src/lib/motion.ts +16 -0
  114. package/templates/default/src/lib/nav.ts +26 -0
  115. package/templates/default/src/lib/offer-tiles.ts +105 -0
  116. package/templates/default/src/lib/order-outcome.ts +66 -0
  117. package/templates/default/src/lib/otp-message.ts +21 -0
  118. package/templates/default/src/lib/products.ts +38 -0
  119. package/templates/default/src/lib/review-refusals.ts +31 -0
  120. package/templates/default/src/lib/store.ts +31 -0
  121. package/templates/default/src/lib/whatsapp.ts +29 -0
  122. package/templates/default/src/middleware.ts +23 -0
  123. package/templates/default/src/pages/404.astro +22 -0
  124. package/templates/default/src/pages/api/abandoned/convert.ts +4 -0
  125. package/templates/default/src/pages/api/abandoned/upsert.ts +4 -0
  126. package/templates/default/src/pages/api/cart/validate.ts +4 -0
  127. package/templates/default/src/pages/api/communes/[wilayaId].ts +4 -0
  128. package/templates/default/src/pages/api/otp/send.ts +4 -0
  129. package/templates/default/src/pages/api/otp/verify.ts +4 -0
  130. package/templates/default/src/pages/api/reviews/[productId].ts +3 -0
  131. package/templates/default/src/pages/api/reviews/eligibility.ts +3 -0
  132. package/templates/default/src/pages/api/reviews/submit.ts +3 -0
  133. package/templates/default/src/pages/api/reviews/upload.ts +3 -0
  134. package/templates/default/src/pages/category/[slug].astro +20 -0
  135. package/templates/default/src/pages/checkout.astro +25 -0
  136. package/templates/default/src/pages/collections/[handle].astro +20 -0
  137. package/templates/default/src/pages/contact.astro +17 -0
  138. package/templates/default/src/pages/index.astro +9 -0
  139. package/templates/default/src/pages/lp/[slug].astro +47 -0
  140. package/templates/default/src/pages/pages/[slug].astro +16 -0
  141. package/templates/default/src/pages/products/[handle].astro +37 -0
  142. package/templates/default/src/pages/products/index.astro +15 -0
  143. package/templates/default/src/pages/robots.txt.ts +9 -0
  144. package/templates/default/src/pages/search.astro +19 -0
  145. package/templates/default/src/pages/sitemap.xml.ts +12 -0
  146. package/templates/default/src/pages/thank-you.astro +33 -0
  147. package/templates/default/src/pages/track-order.astro +17 -0
  148. package/templates/default/src/pages/wocart-preview.astro +43 -0
  149. package/templates/default/src/pages/wocart-revalidate.ts +10 -0
  150. package/templates/default/src/pages/wocart-styles.css.ts +5 -0
  151. package/templates/default/src/pages/wocart-theme.json.ts +5 -0
  152. package/templates/default/src/scripts/cart.ts +371 -0
  153. package/templates/default/src/scripts/checkout/coupon.ts +96 -0
  154. package/templates/default/src/scripts/checkout/delivery.ts +86 -0
  155. package/templates/default/src/scripts/checkout/form.ts +54 -0
  156. package/templates/default/src/scripts/checkout/otp.ts +106 -0
  157. package/templates/default/src/scripts/checkout/picker.ts +169 -0
  158. package/templates/default/src/scripts/checkout/quote.ts +169 -0
  159. package/templates/default/src/scripts/checkout/submit.ts +113 -0
  160. package/templates/default/src/scripts/checkout/tracking.ts +74 -0
  161. package/templates/default/src/scripts/countdown.ts +29 -0
  162. package/templates/default/src/scripts/events.ts +4 -0
  163. package/templates/default/src/scripts/hero.ts +49 -0
  164. package/templates/default/src/scripts/listing.ts +13 -0
  165. package/templates/default/src/scripts/order-form.ts +100 -0
  166. package/templates/default/src/scripts/product.ts +306 -0
  167. package/templates/default/src/scripts/public-config.ts +79 -0
  168. package/templates/default/src/scripts/reviews.ts +358 -0
  169. package/templates/default/src/scripts/site.ts +131 -0
  170. package/templates/default/src/scripts/thank-you.ts +11 -0
  171. package/templates/default/src/scripts/voice-note.ts +94 -0
  172. package/templates/default/src/styles/base.css +1030 -0
  173. package/templates/default/src/styles/checkout.css +1111 -0
  174. package/templates/default/src/styles/global.css +12 -0
  175. package/templates/default/src/styles/product.css +871 -0
  176. package/templates/default/src/styles/reviews.css +533 -0
  177. package/templates/default/src/styles/sections.css +931 -0
  178. package/templates/default/src/styles/shell.css +970 -0
  179. package/templates/default/src/styles/tokens.css +583 -0
  180. package/templates/default/src/theme/api-routes.ts +10 -0
  181. package/templates/default/src/theme/content/catalog.ts +117 -0
  182. package/templates/default/src/theme/content/checkout.ts +168 -0
  183. package/templates/default/src/theme/content/editor.ts +21 -0
  184. package/templates/default/src/theme/content/index.ts +45 -0
  185. package/templates/default/src/theme/content/reviews.ts +76 -0
  186. package/templates/default/src/theme/content/shell.ts +59 -0
  187. package/templates/default/src/theme/content/types.ts +12 -0
  188. package/templates/default/src/theme/documents/catalog.json +11 -0
  189. package/templates/default/src/theme/documents/category.json +11 -0
  190. package/templates/default/src/theme/documents/checkout.json +11 -0
  191. package/templates/default/src/theme/documents/collection.json +11 -0
  192. package/templates/default/src/theme/documents/contact.json +11 -0
  193. package/templates/default/src/theme/documents/footer.area.json +11 -0
  194. package/templates/default/src/theme/documents/header.area.json +16 -0
  195. package/templates/default/src/theme/documents/home.json +313 -0
  196. package/templates/default/src/theme/documents/landing.json +8 -0
  197. package/templates/default/src/theme/documents/page.json +11 -0
  198. package/templates/default/src/theme/documents/product.json +125 -0
  199. package/templates/default/src/theme/documents/search.json +11 -0
  200. package/templates/default/src/theme/documents/thank-you.json +11 -0
  201. package/templates/default/src/theme/documents/track-order.json +11 -0
  202. package/templates/default/src/theme/fields.ts +61 -0
  203. package/templates/default/src/theme/key.ts +11 -0
  204. package/templates/default/src/theme/labels.ts +231 -0
  205. package/templates/default/src/theme/locales.ts +11 -0
  206. package/templates/default/src/theme/palette.ts +14 -0
  207. package/templates/default/src/theme/sections/collection-cards.ts +65 -0
  208. package/templates/default/src/theme/sections/faq.ts +74 -0
  209. package/templates/default/src/theme/sections/featured-product.ts +42 -0
  210. package/templates/default/src/theme/sections/hero.ts +47 -0
  211. package/templates/default/src/theme/sections/image-banner.ts +25 -0
  212. package/templates/default/src/theme/sections/index.ts +40 -0
  213. package/templates/default/src/theme/sections/landing.ts +150 -0
  214. package/templates/default/src/theme/sections/listing.ts +84 -0
  215. package/templates/default/src/theme/sections/product-grid.ts +42 -0
  216. package/templates/default/src/theme/sections/product.ts +297 -0
  217. package/templates/default/src/theme/sections/rich-text.ts +39 -0
  218. package/templates/default/src/theme/sections/shared.ts +54 -0
  219. package/templates/default/src/theme/sections/shell.ts +85 -0
  220. package/templates/default/src/theme/sections/store-pages.ts +101 -0
  221. package/templates/default/src/theme/sections/testimonials.ts +61 -0
  222. package/templates/default/src/theme/sections/thank-you.ts +35 -0
  223. package/templates/default/src/theme/settings.ts +124 -0
  224. package/templates/default/src/theme/theme.ts +65 -0
  225. package/templates/default/tests/fixtures/canvas-tote.json +62 -0
  226. package/templates/default/tests/fixtures/linen-shirt.json +128 -0
  227. package/templates/default/tests/unit/checkout.test.ts +241 -0
  228. package/templates/default/tests/unit/contract.test.ts +169 -0
  229. package/templates/default/tests/unit/contrast.test.ts +68 -0
  230. package/templates/default/tests/unit/copy.test.ts +101 -0
  231. package/templates/default/tests/unit/design-values.test.ts +95 -0
  232. package/templates/default/tests/unit/editability.test.ts +180 -0
  233. package/templates/default/tests/unit/fixtures.ts +91 -0
  234. package/templates/default/tests/unit/footer.test.ts +54 -0
  235. package/templates/default/tests/unit/guards.test.ts +340 -0
  236. package/templates/default/tests/unit/images.test.ts +26 -0
  237. package/templates/default/tests/unit/landing.test.ts +151 -0
  238. package/templates/default/tests/unit/languages.test.ts +42 -0
  239. package/templates/default/tests/unit/middleware.test.ts +53 -0
  240. package/templates/default/tests/unit/offer-tiles.test.ts +75 -0
  241. package/templates/default/tests/unit/render.ts +38 -0
  242. package/templates/default/tests/unit/reviews.test.ts +25 -0
  243. package/templates/default/tests/unit/rules.test.ts +59 -0
  244. package/templates/default/tests/unit/source.ts +75 -0
  245. package/templates/default/tests/unit/store-pages.test.ts +147 -0
  246. package/templates/default/tests/unit/studio.test.ts +202 -0
  247. package/templates/default/tests/unit/testimonials.test.ts +52 -0
  248. package/templates/default/tests/unit/thank-you.test.ts +52 -0
  249. package/templates/default/tests/unit/tracking.test.ts +29 -0
  250. package/templates/default/tests/unit/voice-note.test.ts +42 -0
  251. package/templates/default/tsconfig.json +13 -0
  252. package/templates/default/vitest.config.ts +15 -0
  253. package/templates/default/wrangler.jsonc +17 -0
@@ -0,0 +1,340 @@
1
+ /**
2
+ * Source guards: rules every theme keeps, checked on the shipped source under
3
+ * `src/` (tests and build output left out). One walker, so every guard agrees
4
+ * on what "the theme" is; each first proves it found something to check.
5
+ */
6
+ import { describe, expect, it } from "vitest";
7
+ import { readFileSync, readdirSync } from "node:fs";
8
+ import { join } from "node:path";
9
+ import { SCHEME_MARKER_CLASS } from "@abcart/theme";
10
+ import { STOREFRONT_API_PATHS } from "@abcart/storefront";
11
+ import { content } from "../../src/theme/content";
12
+ import { ROOT, browserModuleGraph, code, files, runtimeImports } from "./source";
13
+
14
+ describe("the theme's browser code", () => {
15
+ const graph = browserModuleGraph();
16
+
17
+ it("is found, so these guards check something", () => {
18
+ expect([...graph.keys()]).toEqual(expect.arrayContaining(["scripts/order-form.ts", "scripts/cart.ts", "scripts/product.ts", "lib/coupon-notice.ts"]));
19
+ });
20
+
21
+ it("imports no schema and nothing from Zod: the server checked the data", () => {
22
+ const offenders = [...graph.values()].flatMap((file) =>
23
+ runtimeImports(file.text).flatMap(({ from, names }) => [
24
+ ...(from === "zod" || from.startsWith("zod/") ? [`${file.path}: zod`] : []),
25
+ ...(from.startsWith("@wocart/") ? names.filter((name) => /Schema\b/.test(name)).map((name) => `${file.path}: ${name}`) : []),
26
+ ]),
27
+ );
28
+ expect(offenders).toEqual([]);
29
+ });
30
+
31
+ it("never reaches a server-only module, so the API key cannot ship", () => {
32
+ const serverOnly = /^(astro:env\/server|astro:actions|@wocart\/storefront\/(server|astro)|@\/lib\/(store|env)(\.ts)?)$/;
33
+ const offenders = [...graph.values()].flatMap((file) =>
34
+ runtimeImports(file.text).filter(({ from }) => serverOnly.test(from)).map(({ from }) => `${file.path} → ${from}`),
35
+ );
36
+ expect(offenders).toEqual([]);
37
+ });
38
+
39
+ it("takes from @abcart/theme only its browser entries: the lifecycle and the messages", () => {
40
+ const offenders = [...graph.values()].flatMap((file) =>
41
+ runtimeImports(file.text)
42
+ .filter(({ from }) => from.startsWith("@abcart/theme") && !["@abcart/theme/lifecycle", "@abcart/theme/messages"].includes(from))
43
+ .filter(({ from }) => !(from === "@abcart/theme/preview" && file.path.startsWith("components/surface/PreviewBridge")))
44
+ .map(({ from }) => `${file.path} → ${from}`),
45
+ );
46
+ expect(offenders).toEqual([]);
47
+ });
48
+
49
+ it("never ships the editor's bridge to a shopper's page", () => {
50
+ const shipsBridge = [...graph.values()].filter((file) => !file.path.startsWith("components/surface/PreviewBridge") && runtimeImports(file.text).some(({ from }) => from === "@abcart/theme/preview")).map((file) => file.path);
51
+ expect(shipsBridge).toEqual([]);
52
+ });
53
+
54
+ it("binds every behaviour through the SDK's lifecycle, so the editor's preview can swap a section or the page", () => {
55
+ // A script that finds its elements once at load would stay bound to markup the preview replaced.
56
+ const scripts = code.filter((file) => file.path.startsWith("scripts/") && !file.path.startsWith("scripts/checkout/") && !["scripts/events.ts", "scripts/public-config.ts", "scripts/cart.ts"].includes(file.path));
57
+ expect(scripts.length).toBeGreaterThanOrEqual(5);
58
+ const unbound = scripts.filter((file) => !runtimeImports(file.text).some(({ from, names }) => from === "@abcart/theme/lifecycle" && names.includes("bindEach"))).map((file) => file.path);
59
+ expect(unbound).toEqual([]);
60
+ // The swap events are the SDK's to name: a theme that listens for them itself has a second lifecycle.
61
+ const ownLifecycle = code.filter((file) => /["'](?:wocart:section-load|astro:page-load|astro:before-swap)["']/.test(file.text)).map((file) => file.path);
62
+ expect(ownLifecycle).toEqual([]);
63
+ const cart = code.find((file) => file.path === "scripts/cart.ts")!;
64
+ expect(cart.text).not.toMatch(/^const \w+ = document\.querySelector/m);
65
+ });
66
+
67
+ it("binds the order form's parts from its one entry: no part binds itself or touches the page on load", () => {
68
+ const parts = code.filter((file) => file.path.startsWith("scripts/checkout/"));
69
+ expect(parts.map((file) => file.path.replace("scripts/checkout/", "")).sort()).toEqual(expect.arrayContaining(["coupon.ts", "delivery.ts", "otp.ts", "quote.ts", "submit.ts"]));
70
+ const entry = code.find((file) => file.path === "scripts/order-form.ts")!.text;
71
+ expect(parts.filter((file) => !entry.includes(`"./checkout/${file.path.replace("scripts/checkout/", "").replace(/\.ts$/, "")}"`)).map((file) => file.path)).toEqual([]);
72
+ expect(parts.filter((file) => runtimeImports(file.text).some(({ names }) => names.includes("bindEach") || names.includes("onEachPage"))).map((file) => file.path)).toEqual([]);
73
+ const onLoad = parts.flatMap((file) => file.text.split("\n").map((line, index) => ({ line, at: `${file.path}:${index + 1}` })).filter(({ line }) => /^(?![\s/*}]).*\b(document|window)\.(querySelector|addEventListener|location)/.test(line)).map(({ at }) => at));
74
+ expect(onLoad).toEqual([]);
75
+ });
76
+
77
+ it("gives every order form its checkout key, so a refresh or a retry places no second order", () => {
78
+ const orderForms = code.filter((file) => /<form\b[^>]*action=\{actions\.placeOrder\}/.test(file.text));
79
+ expect(orderForms.map((file) => file.path)).toEqual(["components/checkout/OrderForm.astro"]);
80
+ expect(orderForms[0]!.text).toMatch(/<form\b[^>]*\bdata-order-form\b/);
81
+ const orderForm = code.find((file) => file.path === "scripts/order-form.ts")!;
82
+ expect(orderForm.text).toMatch(/bindEach<HTMLFormElement>\("\[data-order-form\]", initForm\)/);
83
+ expect(orderForm.text).toMatch(/function initForm\(form: HTMLFormElement\) \{\n(?:\s*\/\/.*\n)*\s*const unbindCheckoutKey = bindCheckoutKey\(form\);/);
84
+ // Every way out of initForm hands back the cleanup that unbinds the key.
85
+ expect(orderForm.text).toMatch(/const cleanups: Cleanup\[\] = \[unbindCheckoutKey(?:, [^\]]+)?\];/);
86
+ const body = orderForm.text.slice(orderForm.text.indexOf("function initForm("));
87
+ const returns = [...body.matchAll(/\breturn\b[^;\n]*/g)].map((match) => match[0]).filter((statement) => !/^return window\.location/.test(statement));
88
+ expect(returns.length).toBeGreaterThanOrEqual(2);
89
+ expect(returns.every((statement) => statement === "return () => cleanups.forEach((cleanup) => cleanup())")).toBe(true);
90
+ });
91
+ });
92
+
93
+ describe("the SDK boundary", () => {
94
+ it("answers a missing product, category, collection, page or landing page through the SDK's notFound, never cached", () => {
95
+ const routes = ["pages/products/[handle].astro", "pages/category/[slug].astro", "pages/collections/[handle].astro", "pages/pages/[slug].astro", "pages/lp/[slug].astro"];
96
+ for (const route of routes) expect(code.find((file) => file.path === route)?.text, route).toMatch(/return notFound\(Astro\);/);
97
+ const handRolled = code.filter((file) => file.path.startsWith("pages/") && file.path !== "pages/404.astro" && /rewrite\(["']\/404["']\)|cache\.set\(false\)/.test(file.text)).map((file) => file.path);
98
+ expect(handRolled).toEqual([]);
99
+ });
100
+
101
+ it("mounts a route file at every API path the browser calls, and none it does not", () => {
102
+ // The SDK's `:wilayaId` is Astro's `[wilayaId]`: each path names exactly one route file.
103
+ const routeFiles = files.filter((file) => file.path.startsWith("pages/api/")).map((file) => `/${file.path.replace(/^pages\//, "").replace(/\.ts$/, "")}`);
104
+ const expected = Object.values(STOREFRONT_API_PATHS).map((path) => path.replace(/:(\w+)/g, "[$1]"));
105
+ expect(expected.filter((path) => !routeFiles.includes(path))).toEqual([]);
106
+ expect(routeFiles.filter((route) => !expected.includes(route))).toEqual([]);
107
+ const ownTables = code.filter((file) => /["'`]\/api\//.test(file.text) && !file.path.startsWith("pages/api/")).map((file) => file.path);
108
+ expect(ownTables).toEqual([]);
109
+ });
110
+
111
+ it("creates SDK clients in one place only", () => {
112
+ const creators = code.filter((file) => /\bcreateStoreClient\s*\(/.test(file.text)).map((file) => file.path);
113
+ expect(creators).toEqual(["lib/store.ts"]);
114
+ });
115
+
116
+ it("shows a store it cannot read through the SDK's unavailable store, built in one place", () => {
117
+ const fallbacks = code.filter((file) => /\bunavailableStoreConfig\s*\(/.test(file.text)).map((file) => file.path);
118
+ expect(fallbacks).toEqual(["middleware.ts"]);
119
+ expect(code.find((file) => file.path === "middleware.ts")!.text).toMatch(/fallback: unavailableStoreConfig\(/);
120
+ });
121
+
122
+ it("imports the SDKs through their published entry points only", () => {
123
+ // What each installed package itself exports: a deep import of anything else is a private path.
124
+ const published = new Set(
125
+ ["@abcart/storefront", "@abcart/theme"].flatMap((name) => {
126
+ const { exports } = JSON.parse(readFileSync(join(ROOT, "node_modules", name, "package.json"), "utf8")) as { exports: Record<string, unknown> };
127
+ return Object.keys(exports).filter((entry) => entry !== "./package.json").map((entry) => (entry === "." ? name : `${name}/${entry.slice(2)}`));
128
+ }),
129
+ );
130
+ expect(published).toContain("@abcart/theme/lifecycle");
131
+ const offenders = code.flatMap((file) =>
132
+ [...file.text.matchAll(/from\s+["'](@wocart\/[^"']+)["']|import\s+["'](@wocart\/[^"']+)["']/g)]
133
+ .map((match) => match[1] ?? match[2]!)
134
+ .filter((from) => !published.has(from))
135
+ .map((from) => `${file.path}: ${from}`),
136
+ );
137
+ expect(offenders).toEqual([]);
138
+ });
139
+
140
+ it("builds every link to a platform page with storefrontPath, never by hand", () => {
141
+ const handWritten = [/`\/(products|category|pages|lp|collections)\/\$\{/, /["'`]\/(checkout|thank-you|track-order)["'`]/];
142
+ const offenders = code.flatMap((file) =>
143
+ file.text
144
+ .split("\n")
145
+ .map((line, index) => ({ line, at: `${file.path}:${index + 1}` }))
146
+ .filter(({ line }) => !/^\s*(\/\/|\/?\*)/.test(line) && handWritten.some((pattern) => pattern.test(line)))
147
+ .map(({ at, line }) => `${at} ${line.trim()}`),
148
+ );
149
+ expect(offenders).toEqual([]);
150
+ });
151
+ });
152
+
153
+ describe("the design system", () => {
154
+ const BRAND_VALUES: [RegExp, string][] = [
155
+ [/#[0-9a-f]{3,8}\b/i, "a hex color"],
156
+ [/\b(?:rgba?|hsla?|oklch|oklab|lab|lch)\(/, "a color function"],
157
+ [/(?<![-\w.])(?:white|black)(?![-\w])/, "a named color"],
158
+ [/font-family:(?!\s*var\()/, "a font family"],
159
+ [/border-radius:(?![^;]*var\()[^;]*\d+px/, "a radius"],
160
+ [/box-shadow:(?![^;]*var\()[^;]*\d+px/, "a shadow"],
161
+ [/font-weight:\s*\d/, "a font weight"],
162
+ ];
163
+
164
+ it("keeps every brand value in tokens.css, so restyling the theme is one file", () => {
165
+ const sheets = files.filter((file) => file.path.endsWith(".css") && file.path !== "styles/tokens.css");
166
+ expect(sheets.length).toBeGreaterThan(3);
167
+ const offenders = sheets.flatMap((file) =>
168
+ file.text
169
+ .replace(/\/\*[\s\S]*?\*\//g, (comment) => comment.replace(/[^\n]/g, " "))
170
+ .replace(/url\("[^"]*"\)/g, "url()")
171
+ .split("\n")
172
+ .flatMap((line, index) => BRAND_VALUES.filter(([pattern]) => pattern.test(line)).map(([, what]) => `${file.path}:${index + 1} ${what}: ${line.trim()}`)),
173
+ );
174
+ expect(offenders).toEqual([]);
175
+ });
176
+
177
+ it("lays out with logical properties, so right to left needs no rule of its own", () => {
178
+ // A physical side is right only where the rule names one direction or the side the WhatsApp App was set to.
179
+ const physical = /(?:^|[;{\s])(?:left|right)\s*:|(?:margin|padding|border)-(?:left|right)\b|(?:text-align|float|background-position)\s*:\s*(?:left|right)\b/;
180
+ const oneSide = /\[dir="(?:rtl|ltr)"\]|\[data-wa-side=|\[data-position=/;
181
+ const sheets = files.filter((file) => file.path.endsWith(".css"));
182
+ const offenders = sheets.flatMap((file) =>
183
+ [...file.text.replace(/\/\*[\s\S]*?\*\//g, "").matchAll(/([^{}]+)\{([^{}]*)\}/g)]
184
+ .filter((rule) => physical.test(rule[2]!) && !oneSide.test(rule[1]!))
185
+ .map((rule) => `${file.path}: ${rule[1]!.trim().replace(/\s+/g, " ")}`),
186
+ );
187
+ expect(sheets.length).toBeGreaterThan(3);
188
+ expect(offenders).toEqual([]);
189
+ });
190
+
191
+ it("styles components from the theme's stylesheets, never from a scoped <style> block", () => {
192
+ const scoped = code.filter((file) => file.path.endsWith(".astro") && /<style\b(?![^>]*is:inline)/.test(file.text)).map((file) => file.path);
193
+ expect(scoped).toEqual([]);
194
+ });
195
+ });
196
+
197
+ describe("what a shopper reads and loads", () => {
198
+ it("derives its colours on the SDK's scheme marker, never on a marker of its own", () => {
199
+ // schemeClass() always emits the marker; tokens derived on any other selector miss the merchant's colours.
200
+ const derivers = files
201
+ .filter((file) => file.path.endsWith(".css"))
202
+ .flatMap((file) =>
203
+ [...file.text.replace(/\/\*[\s\S]*?\*\//g, "").matchAll(/([^{}]+)\{([^{}]*)\}/g)]
204
+ .filter((rule) => /--[\w-]+:\s*var\(--wc-color-/.test(rule[2]!))
205
+ .map((rule) => `${file.path}: ${rule[1]!.trim().replace(/\s+/g, " ")}`),
206
+ );
207
+ expect(derivers).toEqual([`styles/tokens.css: :root, .${SCHEME_MARKER_CLASS}`]);
208
+ expect(code.filter((file) => /\bschemeClass\(/.test(file.text)).length).toBeGreaterThanOrEqual(7);
209
+ });
210
+
211
+ it("asks for no consent in a form: the store's legal pages are linked in the footer", () => {
212
+ const consent = /consent|توافق على|vous acceptez|you agree/i;
213
+ const copy = (["ar", "fr", "en"] as const).flatMap((locale) => Object.entries(content[locale]).filter(([key, text]) => consent.test(key) || consent.test(text)).map(([key]) => `${locale}: ${key}`));
214
+ expect([...copy, ...code.filter((file) => !file.path.startsWith("theme/content/") && consent.test(file.text)).map((file) => file.path)]).toEqual([]);
215
+ });
216
+
217
+ it("self-hosts two font families, each file used, licensed and preloaded for its direction", () => {
218
+ const tokens = files.find((file) => file.path === "styles/tokens.css")!.text;
219
+ const faces = [...tokens.matchAll(/@font-face\s*\{[^}]*font-family:\s*"([^"]+)"[^}]*url\("\/fonts\/([^"]+)"\)[^}]*unicode-range:/g)].map((match) => ({ family: match[1]!, file: match[2]! }));
220
+ expect(new Set(faces.map((face) => face.family)).size).toBe(2);
221
+ const fontDir = join(ROOT, "public/fonts");
222
+ const shipped = readdirSync(fontDir).filter((name) => name.endsWith(".woff2"));
223
+ expect(shipped.sort()).toEqual(faces.map((face) => face.file).sort());
224
+ const license = readFileSync(join(fontDir, "OFL.txt"), "utf8");
225
+ expect(shipped.filter((name) => !license.includes(name))).toEqual([]);
226
+ const layout = files.find((file) => file.path === "layouts/StoreLayout.astro")!.text;
227
+ const preload = /\{isRTL \? \(\s*<link rel="preload" href="\/fonts\/([^"]+)"[^>]*\/>\s*\) : \(\s*<link rel="preload" href="\/fonts\/([^"]+)"/.exec(layout);
228
+ expect(preload?.slice(1)).toEqual([expect.stringMatching(/arabic/), expect.stringMatching(/latin/)]);
229
+ expect(preload!.slice(1).every((file) => shipped.includes(file))).toBe(true);
230
+ });
231
+
232
+ it("loads no font from a third party", () => {
233
+ const thirdParty = /fonts\.googleapis\.com|fonts\.gstatic\.com|use\.typekit\.net|fonts\.bunny\.net/;
234
+ expect(files.filter((file) => thirdParty.test(file.text)).map((file) => file.path)).toEqual([]);
235
+ });
236
+
237
+ it("writes no visible or spoken text in the markup: it comes from the copy", () => {
238
+ const literal = /\b(aria-label|alt|title|placeholder)="[A-Za-z][^"{]*"/g;
239
+ const offenders = code
240
+ .filter((file) => file.path.endsWith(".astro"))
241
+ .flatMap((file) => [...file.text.matchAll(literal)].map((match) => `${file.path}: ${match[0]}`));
242
+ expect(offenders).toEqual([]);
243
+ });
244
+
245
+ it("points every label at a field that exists in the same component", () => {
246
+ const broken = code
247
+ .filter((file) => file.path.endsWith(".astro"))
248
+ .flatMap((file) =>
249
+ [...file.text.matchAll(/<label\b[^>]*\bfor="([^"]+)"/g)]
250
+ .map((match) => match[1]!)
251
+ .filter((target) => !new RegExp(`\\bid="${target}"`).test(file.text))
252
+ .map((target) => `${file.path} → ${target}`),
253
+ );
254
+ expect(broken).toEqual([]);
255
+ });
256
+
257
+
258
+ it("names nothing in the editor that no field shows: every editor label is used", () => {
259
+ const labels = files.find((file) => file.path === "theme/labels.ts")!.text;
260
+ const source = code.filter((file) => file.path !== "theme/labels.ts").map((file) => file.text).join("\n");
261
+ const unused = [...labels.matchAll(/export const (\w+) = \{([\s\S]*?)\n\};/g)]
262
+ .filter(([, group]) => !new RegExp(`Object\\.keys\\(${group}\\)`).test(source))
263
+ .flatMap(([, group, body]) => [...body!.matchAll(/^ {2}(\w+):/gm)].map(([, key]) => `${group}.${key}`))
264
+ .filter((name) => !new RegExp(`\\b${name.replace(".", "\\.")}\\b`).test(source));
265
+ expect(unused).toEqual([]);
266
+ });
267
+
268
+ });
269
+
270
+ describe("the store's WhatsApp", () => {
271
+ it("is reached one way: every link comes from the SDK through the theme's one binding", () => {
272
+ const binding = "lib/whatsapp.ts";
273
+ const of = (test: (text: string) => boolean) => code.filter((file) => test(file.text)).map((file) => file.path).sort();
274
+ expect(of((text) => text.includes("storeWhatsApp(")).length).toBeGreaterThan(3);
275
+ expect(of((text) => text.includes("whatsAppContact("))).toEqual([binding]);
276
+ expect(of((text) => /wa\.me|api\.whatsapp\.com|\?text=/.test(text))).toEqual([]);
277
+ expect(of((text) => text.includes("config.whatsapp"))).toEqual([]);
278
+ });
279
+
280
+ it("never writes a platform page's path by hand: contact, search and order tracking come from storefrontPath", () => {
281
+ expect(code.filter((file) => /["'`]\/(contact|search|track-order)["'`?]/.test(file.text)).map((file) => file.path)).toEqual([]);
282
+ });
283
+ });
284
+
285
+ describe("where the theme runs", () => {
286
+ it("builds for Cloudflare Workers and for Vercel, so Wocart Cloud can deploy it on the host a merchant picks", () => {
287
+ const pkg = JSON.parse(readFileSync(join(ROOT, "package.json"), "utf8")) as { scripts: Record<string, string>; dependencies: Record<string, string> };
288
+ expect(pkg.scripts.build).toBe("astro build");
289
+ expect(pkg.scripts["build:vercel"]).toBe("DEPLOY_TARGET=vercel astro build");
290
+ expect(Object.keys(pkg.dependencies)).toEqual(expect.arrayContaining(["@astrojs/cloudflare", "@astrojs/vercel"]));
291
+ const config = readFileSync(join(ROOT, "astro.config.mjs"), "utf8");
292
+ expect(config).toMatch(/cloudflare: async \(\) =>[\s\S]*@astrojs\/cloudflare"\)\)\.default/);
293
+ expect(config).toMatch(/vercel: async \(\) =>[\s\S]*@astrojs\/vercel"\)\)\.default/);
294
+ expect(config).toMatch(/process\.env\.DEPLOY_TARGET \|\| "cloudflare"/);
295
+ });
296
+ });
297
+
298
+ describe("colour and section style", () => {
299
+ const ALLOWED = new Set(["styles/tokens.css", "theme/palette.ts"]);
300
+ const COLOUR: [RegExp, string][] = [
301
+ [/(?<![\w&-])#[0-9a-fA-F]{3,8}(?![\w-])/, "a hex colour"],
302
+ [/%23[0-9a-fA-F]{3,8}/, "a hex colour in a data URI"],
303
+ [/\b(?:rgba?|hsla?|oklch|oklab|lab|lch)\(/, "a colour function"],
304
+ [/\b(?:fill|stroke|stop-color)(?:=|:)\s*["']?(?!none\b|currentColor|inherit|transparent)[a-zA-Z]/, "a named SVG paint"],
305
+ ];
306
+
307
+ it("holds no colour outside the tokens and the palette: a colour is a token, or a value of palette.ts", () => {
308
+ expect(files.length).toBeGreaterThan(80);
309
+ const offenders = files
310
+ .filter((file) => !ALLOWED.has(file.path))
311
+ .flatMap((file) =>
312
+ file.text.split("\n").flatMap((line, index) =>
313
+ COLOUR.filter(([pattern]) => pattern.test(line)).map(([, what]) => `${file.path}:${index + 1} ${what}: ${line.trim().slice(0, 100)}`),
314
+ ),
315
+ );
316
+ expect(offenders).toEqual([]);
317
+ });
318
+
319
+ it("gives every section a colour scheme and a style, and draws it inside the shared frame", () => {
320
+ const definitions = files.filter((file) => file.path.startsWith("theme/sections/") && file.path.endsWith(".ts"));
321
+ const offenders: string[] = [];
322
+ let checked = 0;
323
+ for (const file of definitions) {
324
+ const components = new Map([...file.text.matchAll(/import (\w+)(?:,\s*\{[^}]*\})? from "(@\/components\/[^"]+\.astro)"/g)].map((match) => [match[1]!, match[2]!]));
325
+ for (const block of file.text.split("defineComponent({").slice(1)) {
326
+ if (!/placement: "section"/.test(block) || /"area:/.test(block)) continue;
327
+ checked++;
328
+ const type = /type: "([\w-]+)"/.exec(block)?.[1] ?? "?";
329
+ const path = components.get(/component: (\w+)/.exec(block)?.[1] ?? "");
330
+ const source = path ? code.find((candidate) => candidate.path === path.replace(/^@\//, ""))?.text ?? "" : "";
331
+ if (!path) offenders.push(`${type}: no component import`);
332
+ if (!/schemeField\(|key: "scheme"/.test(block)) offenders.push(`${type}: no colour scheme field`);
333
+ if (!/styleField\(|key: "style"/.test(block)) offenders.push(`${type}: no style field`);
334
+ if (!source.includes('"@/components/ui/Section.astro"')) offenders.push(`${type}: does not render through Section.astro`);
335
+ }
336
+ }
337
+ expect(checked).toBeGreaterThan(15);
338
+ expect(offenders).toEqual([]);
339
+ });
340
+ });
@@ -0,0 +1,26 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import type { MediaDelivery } from "@abcart/storefront";
3
+ import { catalogPicture, imageSrcset, imageUrl, pickedImage } from "../../src/lib/images";
4
+
5
+ const IMAGEKIT: MediaDelivery = { kind: "imagekit", origin: "https://ik.imagekit.io/wocart/stores/demo" };
6
+ const DIRECT: MediaDelivery = { kind: "direct", origin: "http://localhost:8787/media" };
7
+ const PHOTO = `${IMAGEKIT.origin}/products/shirt.webp`;
8
+
9
+ describe("the theme's photos", () => {
10
+ it("asks the store's delivery for a photo at its size, cropped to a ratio or kept in shape", () => {
11
+ expect(imageUrl(PHOTO, IMAGEKIT, 240, 1)).toBe(`${PHOTO}?tr=w-240,h-240,c-maintain_ratio,q-82,f-auto`);
12
+ expect(imageUrl(PHOTO, IMAGEKIT, 1080)).toBe(`${PHOTO}?tr=w-1080,c-at_max,q-82,f-auto`);
13
+ expect(imageSrcset(PHOTO, IMAGEKIT, [360, 720], 1.25)).toBe(`${PHOTO}?tr=w-360,h-450,c-maintain_ratio,q-82,f-auto 360w, ${PHOTO}?tr=w-720,h-900,c-maintain_ratio,q-82,f-auto 720w`);
14
+ });
15
+
16
+ it("keeps a photo's URL when its delivery does not resize it, and has nothing for no photo", () => {
17
+ expect(imageUrl(`${DIRECT.origin}/products/a.png`, DIRECT, 240)).toBe(`${DIRECT.origin}/products/a.png`);
18
+ expect(imageSrcset(`${DIRECT.origin}/products/a.png`, DIRECT, [360])).toBeUndefined();
19
+ expect(imageUrl(null, IMAGEKIT, 240)).toBeNull();
20
+ });
21
+
22
+ it("draws a picked image from its key, and a catalog photo with its size", () => {
23
+ expect(pickedImage({ key: "products/hero.webp", alt: "Chemise" }, IMAGEKIT)?.src).toBe(`${IMAGEKIT.origin}/products/hero.webp`);
24
+ expect(catalogPicture({ key: "products/shirt.webp", url: PHOTO, width: 1200, height: 1500, altText: null })).toEqual({ src: PHOTO, alt: "", width: 1200, height: 1500, position: undefined });
25
+ });
26
+ });
@@ -0,0 +1,151 @@
1
+ /**
2
+ * A landing page is composed like any page, each with its own document
3
+ * (`lp:<id>`): the page's images in their saved order with the saved gap —
4
+ * all, or ranges with sections between them — and its one order form, never
5
+ * the product page. It may leave out the header and footer, and holds the
6
+ * sections that help a shopper decide.
7
+ */
8
+ import { describe, expect, it } from "vitest";
9
+ import { readFileSync } from "node:fs";
10
+ import { experimental_AstroContainer as AstroContainer } from "astro/container";
11
+ import { isAreaShown, landingSurface, resolveSurfaceDocument } from "@abcart/theme";
12
+ import type { LandingPage, Review } from "@abcart/storefront";
13
+ import type { StoreClient } from "@abcart/storefront/server";
14
+ import { createReadCache } from "@abcart/theme/astro";
15
+ import Sections from "../../src/components/surface/Sections.astro";
16
+ import { theme } from "../../src/theme/theme";
17
+ import { shirt, storeContext, storeDouble } from "./fixtures";
18
+
19
+ const image = (id: string, position: number) => ({ id, key: `landing/${id}.webp`, url: `https://media.example.test/landing/${id}.webp`, width: 1080, height: 1350, altText: `alt ${id}`, position });
20
+
21
+ const landing = (overrides: Partial<LandingPage> = {}): LandingPage => ({
22
+ id: "7f3a",
23
+ slug: "lp-shirt",
24
+ name: "Shirt ad",
25
+ status: "published",
26
+ imageGap: 24,
27
+ metaTitle: null,
28
+ metaDescription: null,
29
+ publishedAt: "2026-10-01T00:00:00.000Z",
30
+ images: [image("third", 3), image("first", 1), image("second", 2), image("fourth", 4)],
31
+ product: shirt,
32
+ document: null,
33
+ tracking: { pixelId: null },
34
+ ...overrides,
35
+ });
36
+
37
+ const own = (sections: unknown[], extra: Record<string, unknown> = {}) => ({ version: 1, surface: "lp:7f3a", sections, ...extra });
38
+
39
+ function client(page: LandingPage, reviews: Review[] = []): StoreClient {
40
+ const double = storeDouble();
41
+ return {
42
+ ...double,
43
+ pages: { ...(double as unknown as { pages: object }).pages, landing: async (slug: string) => (slug === page.slug ? page : null) },
44
+ products: { ...double.products, reviews: { list: async () => ({ rows: reviews, total: reviews.length }) } },
45
+ } as unknown as StoreClient;
46
+ }
47
+
48
+ async function render(page: LandingPage, options: { locale?: string; preview?: boolean; reviews?: Review[] } = {}) {
49
+ const container = await AstroContainer.create();
50
+ return container.renderToString(Sections, {
51
+ props: { surface: landingSurface(page.id), document: page.document, params: { slug: page.slug, surface: "landing" }, reads: createReadCache(), preview: options.preview ?? false },
52
+ locals: { store: storeContext(options.locale ?? "ar", client(page, options.reviews)) } as unknown as App.Locals,
53
+ });
54
+ }
55
+
56
+ const PRODUCT_PAGE = {
57
+ gallery: /class="gallery[\s_"]/,
58
+ description: /class="(prose|accordion)/,
59
+ related: /class="product-grid/,
60
+ addToCart: /data-add-to-cart/,
61
+ };
62
+ const at = (html: string, id: string) => html.indexOf(`/landing/${id}.webp`);
63
+
64
+ describe("a landing page with no layout of its own", () => {
65
+ for (const locale of ["ar", "fr", "en"]) {
66
+ it(`is its images, then its order form, and none of the product page (${locale})`, async () => {
67
+ const html = await render(landing(), { locale });
68
+ for (const [part, marker] of Object.entries(PRODUCT_PAGE)) expect(html, part).not.toMatch(marker);
69
+ expect(html.match(/<form[^>]*data-order-form/g)).toHaveLength(1);
70
+ expect(html).toMatch(/name="landingPageSlug" value="lp-shirt"/);
71
+ const order = ["first", "second", "third", "fourth"].map((id) => at(html, id));
72
+ expect(order.every((index) => index > 0)).toBe(true);
73
+ expect(order).toEqual([...order].sort((a, b) => a - b));
74
+ expect(order[3]).toBeLessThan(html.indexOf("data-order-form"));
75
+ });
76
+ }
77
+
78
+ it("puts the page's saved gap between its images, whatever it is", async () => {
79
+ for (const gap of [0, 17, 64]) expect(await render(landing({ imageGap: gap }))).toContain(`--landing-gap:${gap}px`);
80
+ });
81
+
82
+ it("shows the header and footer, until a page leaves them out", () => {
83
+ const start = resolveSurfaceDocument(theme, "lp:7f3a", null).page;
84
+ expect(["header", "footer"].map((key) => isAreaShown(theme, start, key))).toEqual([true, true]);
85
+ const bare = resolveSurfaceDocument(theme, "lp:7f3a", own([{ id: "order", type: "landing-order" }], { hiddenAreas: ["header", "footer"] })).page;
86
+ expect(["header", "footer"].map((key) => isAreaShown(theme, bare, key))).toEqual([false, false]);
87
+ });
88
+ });
89
+
90
+ describe("a landing page's own layout", () => {
91
+ it("splits the images into ranges with sections between them", async () => {
92
+ const html = await render(
93
+ landing({
94
+ document: own([
95
+ { id: "top", type: "landing-images", props: { first: 1, count: 2 } },
96
+ { id: "steps", type: "steps" },
97
+ { id: "rest", type: "landing-images", props: { first: 3 } },
98
+ { id: "order", type: "landing-order" },
99
+ ]),
100
+ }),
101
+ );
102
+ const steps = html.indexOf('class="steps"');
103
+ expect(at(html, "second")).toBeLessThan(steps);
104
+ expect(steps).toBeLessThan(at(html, "third"));
105
+ expect(html.match(/landing\/first\.webp/g)?.length).toBe(html.match(/landing\/fourth\.webp/g)?.length);
106
+ expect(at(html, "fourth")).toBeLessThan(html.indexOf("data-order-form"));
107
+ });
108
+
109
+ it("always keeps its order form, even when its document lost it", async () => {
110
+ const html = await render(landing({ document: own([{ id: "faq", type: "faq", props: { items: [{ id: "q", props: { question: { ar: "سؤال؟" } } }] } }]) }));
111
+ expect(html.match(/<form[^>]*data-order-form/g)).toHaveLength(1);
112
+ });
113
+
114
+ it("shows the reviews of the product it sells, without the write button when the merchant hides it", async () => {
115
+ const review: Review = { id: "r1", customerName: "أمينة", rating: 5, title: null, body: "قماش ناعم ومقاس مضبوط.", createdAt: "2026-10-20T10:00:00.000Z", verified: true, media: [] };
116
+ const html = await render(landing({ document: own([{ id: "reviews", type: "product-reviews", props: { showForm: false } }, { id: "order", type: "landing-order" }]) }), { reviews: [review] });
117
+ expect(html).toContain("قماش ناعم ومقاس مضبوط.");
118
+ expect(html).not.toContain("data-review-open");
119
+ });
120
+
121
+ it("counts the offer down to the merchant's end, left to right, and shows nothing once it ended", async () => {
122
+ const ahead = await render(landing({ document: own([{ id: "cd", type: "countdown", props: { mode: "date", endsOn: "2099-01-01" } }, { id: "order", type: "landing-order" }]) }));
123
+ expect(ahead).toMatch(/data-countdown="2099-01-01"/);
124
+ expect(ahead).toMatch(/class="countdown__clock" dir="ltr"/);
125
+ const ended = landing({ document: own([{ id: "cd", type: "countdown", props: { mode: "date", endsOn: "2020-01-01" } }, { id: "order", type: "landing-order" }]) });
126
+ expect(await render(ended)).not.toContain("data-countdown");
127
+ expect(await render(ended, { preview: true })).toContain("editor-placeholder");
128
+ });
129
+
130
+ it("names its product and price for a page whose images do not", async () => {
131
+ const html = await render(landing({ document: own([{ id: "name", type: "landing-product" }, { id: "order", type: "landing-order" }]) }));
132
+ expect(html).toMatch(/<h1 class="landing-product__name">قميص كتان<\/h1>/);
133
+ });
134
+ });
135
+
136
+ describe("the landing route", () => {
137
+ const route = readFileSync(new URL("../../src/pages/lp/[slug].astro", import.meta.url), "utf8");
138
+
139
+ it("renders the page's own document by its id, never the product template", () => {
140
+ expect(route).toMatch(/landingSurface\(landing\.id\)/);
141
+ expect(route).toMatch(/resolveSurfaceDocument\(theme, surface, landing\.document/);
142
+ expect(route).not.toMatch(/pageData\.get|surface="product"/);
143
+ });
144
+
145
+ it("shares its first picture, names its own pixel, and leaves out the areas the page hides", () => {
146
+ expect(route).toMatch(/ogImage=\{imageUrl\(cover\?\.url/);
147
+ expect(route).toMatch(/pixelId=\{landing\.tracking\.pixelId\}/);
148
+ expect(route).toMatch(/header=\{isAreaShown\(theme, page, "header"\)\}/);
149
+ expect(route).toMatch(/footer=\{isAreaShown\(theme, page, "footer"\)\}/);
150
+ });
151
+ });
@@ -0,0 +1,42 @@
1
+ /**
2
+ * A landing page lives in the store's primary language only: it offers no
3
+ * other language, in its menu or its alternate links. Every other page keeps
4
+ * the store's languages. (The SDK sends `/fr/lp/…` to `/lp/…`; the
5
+ * middleware test proves the theme is wired to it.)
6
+ */
7
+ import { describe, expect, it } from "vitest";
8
+ import { experimental_AstroContainer as AstroContainer } from "astro/container";
9
+ import { buildStoreContext, pageLanguages } from "../../src/lib/context";
10
+ import { localeRouting } from "@abcart/storefront";
11
+ import { storeDouble, testConfig } from "./fixtures";
12
+
13
+ const config = testConfig("ar");
14
+ const routing = localeRouting(config);
15
+
16
+ describe("single-language pages", () => {
17
+ it("offer no other language; every other page offers each published one", () => {
18
+ expect(pageLanguages(config, routing, "/lp/summer-offer")).toEqual([]);
19
+ expect(pageLanguages(config, routing, "/products/linen-shirt").map((language) => language.href)).toEqual(["/products/linen-shirt", "/fr/products/linen-shirt", "/en/products/linen-shirt"]);
20
+ expect(pageLanguages({ ...config, locales: [config.locales[0]!] }, localeRouting({ ...config, locales: [config.locales[0]!] }), "/products/linen-shirt")).toEqual([]);
21
+ });
22
+ });
23
+
24
+ describe("the layout", () => {
25
+ async function render(pathname: string) {
26
+ const container = await AstroContainer.create();
27
+ const { default: StoreLayout } = await import("../../src/layouts/StoreLayout.astro");
28
+ return container.renderToString(StoreLayout, {
29
+ locals: { store: buildStoreContext(config, "ar", pathname, storeDouble()) } as unknown as App.Locals,
30
+ request: new Request(`https://boutique.test${pathname}`),
31
+ });
32
+ }
33
+
34
+ it("shows no language menu and no alternate languages on a landing page", async () => {
35
+ const landing = await render("/lp/lp-shirt");
36
+ expect(landing).not.toContain("data-locale-menu");
37
+ expect(landing).not.toContain('hreflang="fr"');
38
+ const product = await render("/products/linen-shirt");
39
+ expect(product).toContain("data-locale-menu");
40
+ expect(product).toContain('hreflang="fr"');
41
+ });
42
+ });
@@ -0,0 +1,53 @@
1
+ /**
2
+ * The theme's middleware is the SDK's, wired to this theme's store: a page's
3
+ * notFound() rewrites to /404 and the second run keeps the store and language
4
+ * the page already had (a shopper on /fr/… reads a French 404); and a landing
5
+ * page, which exists in the primary language only, is never served under a
6
+ * language prefix.
7
+ */
8
+ import { describe, expect, it, vi } from "vitest";
9
+ import type { APIContext, MiddlewareNext } from "astro";
10
+ import { storeContext, testConfig } from "./fixtures";
11
+
12
+ vi.mock("astro:env/server", () => ({ COD_SERVER_URL: "http://store.invalid", STORE_API_KEY: "test-key", WOCART_PREVIEW_KEY: undefined }));
13
+
14
+ const { onRequest } = await import("../../src/middleware");
15
+
16
+ describe("the middleware", () => {
17
+ it("keeps the store a rewritten request already has, so a 404 stays in the shopper's language", async () => {
18
+ const store = storeContext("fr");
19
+ const context = { isPrerendered: false, url: new URL("https://boutique.test/404"), request: new Request("https://boutique.test/404"), locals: { store } };
20
+ const next = vi.fn(async () => new Response("page"));
21
+ const fetchSpy = vi.spyOn(globalThis, "fetch");
22
+ await onRequest(context as unknown as APIContext, next as unknown as MiddlewareNext);
23
+ expect(next).toHaveBeenCalledWith();
24
+ expect(context.locals.store).toBe(store);
25
+ expect(fetchSpy).not.toHaveBeenCalled();
26
+ fetchSpy.mockRestore();
27
+ });
28
+
29
+ it("sends a landing page asked for in another language to the primary one, its ad query kept", async () => {
30
+ const fetchSpy = vi.spyOn(globalThis, "fetch").mockImplementation(async (input) => Response.json({ data: testConfig(new URL(String(input)).searchParams.get("locale") ?? "ar") }));
31
+ const redirect = vi.fn((location: string, status: number) => new Response(null, { status, headers: { Location: location } }));
32
+ const visit = async (path: string, method = "GET") => {
33
+ const url = new URL(`https://boutique.test${path}`);
34
+ const context = { isPrerendered: false, url, request: new Request(url, { method }), locals: {}, redirect };
35
+ const next = vi.fn(async () => new Response("page"));
36
+ await onRequest(context as unknown as APIContext, next as unknown as MiddlewareNext);
37
+ return { next, locals: context.locals as { store?: { locale: string } } };
38
+ };
39
+ try {
40
+ await visit("/fr/lp/summer-offer?fbclid=abc");
41
+ expect(redirect).toHaveBeenCalledWith("/lp/summer-offer?fbclid=abc", 301);
42
+ redirect.mockClear();
43
+ const landing = await visit("/lp/summer-offer");
44
+ expect(redirect).not.toHaveBeenCalled();
45
+ expect(landing.locals.store?.locale).toBe("ar");
46
+ const product = await visit("/fr/products/linen-shirt");
47
+ expect(redirect).not.toHaveBeenCalled();
48
+ expect(product.locals.store?.locale).toBe("fr");
49
+ } finally {
50
+ fetchSpy.mockRestore();
51
+ }
52
+ });
53
+ });