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,95 @@
1
+ /**
2
+ * Design values live in tokens.css. A stylesheet names a token wherever a
3
+ * size, line height, letter-spacing, motion, opacity, border, shadow, radius,
4
+ * surface, shape or filter appears; a script reads its timings from a token.
5
+ * Layout geometry (gap, padding, margin, sizes, insets, grids) stays in the
6
+ * stylesheets by design and is not checked here.
7
+ */
8
+ import { describe, expect, it } from "vitest";
9
+ import { code, files } from "./source";
10
+
11
+ const TOKENS = files.find((file) => file.path === "styles/tokens.css")!.text;
12
+
13
+ /** Properties whose values are design values, not layout geometry. */
14
+ const DESIGN_PROPERTIES = new Set([
15
+ "font-size", "line-height", "letter-spacing",
16
+ "transition", "transition-duration", "transition-delay", "transition-timing-function",
17
+ "animation", "animation-duration", "animation-delay", "animation-timing-function", "transform",
18
+ "opacity", "aspect-ratio", "box-shadow", "border-radius", "border-top-left-radius", "border-top-right-radius",
19
+ "border-bottom-left-radius", "border-bottom-right-radius", "border", "border-width", "border-top", "border-bottom",
20
+ "border-left", "border-right", "border-top-width", "border-bottom-width", "border-block-start", "border-block-end",
21
+ "border-inline-start", "border-inline-end", "outline", "outline-offset",
22
+ "background", "background-color", "background-image", "filter", "backdrop-filter",
23
+ ]);
24
+
25
+ /** Values with no design meaning: resets, hidden and shown states, structure. */
26
+ const STRUCTURAL = /^(0|0s|0px|0%|1|none|normal|auto|inherit|initial|unset|revert|transparent|currentColor|(scale|translate|translateX|translateY|rotate)\((0|1|0px|0%|0deg)\))$/;
27
+
28
+ /** The literal parts of a value: what remains once every `var(…)` is removed. */
29
+ function literalPart(value: string): string {
30
+ let out = value;
31
+ for (let i = 0; i < 6 && /var\(/.test(out); i++) out = out.replace(/var\([^()]*(?:\([^()]*\)[^()]*)*\)/g, "");
32
+ return out.replace(/!important/g, "").trim();
33
+ }
34
+
35
+ describe("design values", () => {
36
+ it("names every design value in a stylesheet as a token", () => {
37
+ const sheets = files.filter((file) => file.path.startsWith("styles/") && file.path.endsWith(".css") && file.path !== "styles/tokens.css");
38
+ expect(sheets.length).toBeGreaterThan(3);
39
+ const offenders: string[] = [];
40
+ for (const sheet of sheets) {
41
+ sheet.text.split("\n").forEach((line, index) => {
42
+ const match = /^\s*([a-z-]+)\s*:\s*(.+?);?\s*$/.exec(line);
43
+ if (!match || !DESIGN_PROPERTIES.has(match[1]!)) return;
44
+ const value = match[2]!.replace(/;$/, "").trim();
45
+ if (STRUCTURAL.test(value.replace(/\s*!important$/, ""))) return;
46
+ if (/\d/.test(literalPart(value))) offenders.push(`${sheet.path}:${index + 1} ${match[1]}: ${value}`);
47
+ });
48
+ }
49
+ expect(offenders).toEqual([]);
50
+ });
51
+
52
+ it("reads every timing a script runs from a token, except the behaviour timers named here", () => {
53
+ const allowed = ["setInterval(tick, 1000)", "refreshValidation(), 250)"];
54
+ const offenders: string[] = [];
55
+ for (const file of code) {
56
+ file.text.split("\n").forEach((line, index) => {
57
+ if (!/set(Timeout|Interval)\(/.test(line) || !/\d{2,}/.test(line.replace(/\$\{[^}]*\}/g, ""))) return;
58
+ if (allowed.some((text) => line.includes(text))) return;
59
+ offenders.push(`${file.path}:${index + 1} ${line.trim()}`);
60
+ });
61
+ }
62
+ expect(offenders).toEqual([]);
63
+ });
64
+
65
+ it("keeps inline styles to data: a style attribute holds no literal value of its own", () => {
66
+ const offenders: string[] = [];
67
+ for (const file of code.filter((item) => item.path.endsWith(".astro"))) {
68
+ for (const match of file.text.matchAll(/style=\{`([^`]*)`\}/g)) {
69
+ const literal = match[1]!.replace(/\$\{[^}]*\}/g, "");
70
+ if (/\d/.test(literal)) offenders.push(`${file.path}: style=${match[0].slice(0, 70)}`);
71
+ }
72
+ }
73
+ expect(offenders).toEqual([]);
74
+ });
75
+
76
+ it("gives every motion value a script reads a token with a value", () => {
77
+ const names = new Set<string>();
78
+ for (const file of code) for (const match of file.text.matchAll(/motion(?:Ms|Value)\("(--motion-[\w-]+)"\)/g)) names.add(match[1]!);
79
+ expect(names.size).toBeGreaterThan(3);
80
+ const missing = [...names].filter((name) => !new RegExp(`${name}:\\s*[^;]+;`).test(TOKENS));
81
+ expect(missing).toEqual([]);
82
+ });
83
+
84
+ it("keeps colour-dependent tokens on the colour scheme, never at the page root", () => {
85
+ const scheme = /:root,\s*\.wc-scheme\s*\{([\s\S]*?)\n\}/.exec(TOKENS)![1]!;
86
+ const schemeVars = [...scheme.matchAll(/(--[\w-]+)\s*:/g)].map((match) => match[1]!);
87
+ const roots = [...TOKENS.matchAll(/^:root\s*\{\n([\s\S]*?)^\}/gm)].map((match) => match[1]!);
88
+ const offenders = roots.flatMap((block) =>
89
+ [...block.matchAll(/(--[\w-]+)\s*:\s*([^;]+);/g)]
90
+ .filter(([, , value]) => schemeVars.some((name) => new RegExp(`var\\(\\s*${name}\\s*[,)]`).test(value!)))
91
+ .map(([, name]) => name!),
92
+ );
93
+ expect(offenders).toEqual([]);
94
+ });
95
+ });
@@ -0,0 +1,180 @@
1
+ /**
2
+ * Every part of the theme is editable in Wocart Studio, and the definitions
3
+ * follow the SDK's own rules. The checks read the installed `@abcart/theme`
4
+ * validators (nothing invented here): the catalog, the manifest, every page
5
+ * document and the settings. On top of them, the rules an editor depends on:
6
+ * each field reaches the component that renders it, every select says what
7
+ * its options mean, every number and list has its bounds, every label and
8
+ * help text is in each language, every section has a preset to start from,
9
+ * and every preset is a valid section in every language.
10
+ */
11
+ import { describe, expect, it } from "vitest";
12
+ import { componentsOf, checkThemeSettings, themeManifest, validatePageData, validateThemeDefinition, validateThemeManifest, isInsertableOn, type ComponentDefinition, type FieldDefinition, type PageData, type ComponentInstance } from "@abcart/theme";
13
+ import { theme } from "../../src/theme/theme";
14
+ import { content } from "../../src/theme/content";
15
+ import { files } from "./source";
16
+ import { render } from "./render";
17
+
18
+ const LANGS = ["ar", "fr", "en"] as const;
19
+ const components = componentsOf(theme);
20
+ const byType = new Map(components.map((component) => [component.type, component]));
21
+ const isLocalized = (value: unknown): value is Record<string, string> => typeof value === "object" && value !== null;
22
+
23
+ /** Every field of a component, list items included. */
24
+ function allFields(fields: readonly FieldDefinition[] | undefined): FieldDefinition[] {
25
+ return (fields ?? []).flatMap((field) => [field, ...(field.kind === "list" ? allFields(field.fields) : [])]);
26
+ }
27
+
28
+ describe("the SDK's own checks", () => {
29
+ it("accepts the catalog, its manifest, every page document and the settings", () => {
30
+ expect(validateThemeDefinition(theme, { contentKeys: Object.keys(content.en) })).toEqual([]);
31
+ expect(validateThemeManifest(JSON.parse(JSON.stringify(themeManifest(theme)))).issues).toEqual([]);
32
+ for (const surface of theme.surfaces ?? []) expect(validatePageData(theme, surface.document as PageData).issues, surface.key).toEqual([]);
33
+ for (const area of theme.areas ?? []) expect(validatePageData(theme, area.document as PageData).issues, `area ${area.key}`).toEqual([]);
34
+ expect(checkThemeSettings(theme, {})).toEqual([]);
35
+ });
36
+ });
37
+
38
+ describe("every field an editor can change", () => {
39
+ it("is read by the component that renders it, or by the section's load", () => {
40
+ const sectionFiles = files.filter((file) => file.path.startsWith("theme/sections/") && file.path.endsWith(".ts"));
41
+ const componentFor = new Map<string, string>();
42
+ for (const file of sectionFiles) {
43
+ const imports = Object.fromEntries([...file.text.matchAll(/import (\w+)(?:, \{[^}]*\})? from "(@\/components\/[^"]+\.astro)"/g)].map((m) => [m[1]!, m[2]!]));
44
+ for (const m of file.text.matchAll(/type: "([a-z-]+)",\s*component: (\w+)/g)) if (imports[m[2]!]) componentFor.set(m[1]!, imports[m[2]!]!);
45
+ }
46
+ const read = (path: string) => files.find((file) => file.path === path.replace("@/", ""))?.text ?? "";
47
+ const reads = (path: string, seen = new Set<string>()): string => {
48
+ if (seen.has(path)) return "";
49
+ seen.add(path);
50
+ let text = read(path);
51
+ for (const m of text.matchAll(/import (\w+)(?:, \{[^}]*\})? from "(@\/components\/[^"]+\.astro)"/g)) if (!/\/(ui|shell)\//.test(m[2]!)) text += reads(m[2]!, seen);
52
+ return text;
53
+ };
54
+ const missing: string[] = [];
55
+ for (const component of components) {
56
+ const path = componentFor.get(component.type);
57
+ if (!path) { missing.push(`${component.type}: no component`); continue; }
58
+ const sectionText = sectionFiles.map((file) => file.text).join("\n");
59
+ const body = reads(path) + sectionText;
60
+ for (const field of allFields(component.fields)) {
61
+ if (!new RegExp(`\\b${field.key}\\b`).test(body)) missing.push(`${component.type}.${field.key}`);
62
+ }
63
+ }
64
+ expect(missing).toEqual([]);
65
+ });
66
+
67
+ it("says what each select's options mean, in every language", () => {
68
+ const gaps = components.flatMap((component) => allFields(component.fields).filter((field) => field.kind === "select" && !field.optionLabels).map((field) => `${component.type}.${field.key}`));
69
+ expect(gaps).toEqual([]);
70
+ });
71
+
72
+ it("bounds every number and every list, and titles each list item", () => {
73
+ const gaps: string[] = [];
74
+ for (const component of components) {
75
+ for (const field of allFields(component.fields)) {
76
+ if (field.kind === "number" && (field.min === undefined || field.max === undefined)) gaps.push(`${component.type}.${field.key} number bounds`);
77
+ if (field.kind === "list" && (field.max === undefined || !field.itemLabel)) gaps.push(`${component.type}.${field.key} list bounds or itemLabel`);
78
+ }
79
+ }
80
+ expect(gaps).toEqual([]);
81
+ });
82
+
83
+ it("has every label and every help text in each language the theme speaks", () => {
84
+ const gaps: string[] = [];
85
+ for (const component of components) {
86
+ for (const field of allFields(component.fields)) {
87
+ for (const [what, text] of [["label", field.label], ["help", field.description]] as const) {
88
+ if (text === undefined) continue;
89
+ if (!isLocalized(text)) { gaps.push(`${component.type}.${field.key} ${what} is not translatable`); continue; }
90
+ for (const lang of LANGS) if (!text[lang]) gaps.push(`${component.type}.${field.key} ${what} ${lang}`);
91
+ }
92
+ }
93
+ }
94
+ expect(gaps).toEqual([]);
95
+ });
96
+
97
+ it("shows a field only when the field it depends on exists", () => {
98
+ const gaps: string[] = [];
99
+ for (const component of components) {
100
+ const siblings = new Set(allFields(component.fields).map((field) => field.key));
101
+ for (const field of component.fields ?? []) {
102
+ if (!field.visibleIf) continue;
103
+ const condition = field.visibleIf as { field?: string };
104
+ if (!condition.field || !siblings.has(condition.field)) gaps.push(`${component.type}.${field.key} depends on ${condition.field}`);
105
+ }
106
+ }
107
+ expect(gaps).toEqual([]);
108
+ });
109
+ });
110
+
111
+ /** Sections with no preset an editor could start from, and why. A theme that has one of them lists it here. */
112
+ const NO_PRESET: Record<string, string> = {
113
+ "logo-list": "it shows the store's own logo images, which no preset can name",
114
+ };
115
+
116
+ describe("every section starts from a preset", () => {
117
+ const offered = (component: ComponentDefinition) => component.placement !== "block" && component.capabilities?.insertable !== false;
118
+ it("gives each section an editor can insert at least one preset, except those NO_PRESET names", () => {
119
+ const bare = components.filter((component) => offered(component) && (component.presets ?? []).length === 0).map((component) => component.type);
120
+ const expected = Object.keys(NO_PRESET).filter((type) => byType.has(type));
121
+ expect([...bare].sort()).toEqual(expected.sort());
122
+ });
123
+
124
+ it("makes every preset a valid section in every language", () => {
125
+ const failures: string[] = [];
126
+ for (const component of components) {
127
+ for (const preset of component.presets ?? []) {
128
+ for (const lang of LANGS) {
129
+ const instance = { id: "p1", type: component.type, props: { ...(preset.props ?? {}) } } as ComponentInstance;
130
+ const page = { version: 1, surface: "home", sections: [instance] } as unknown as PageData;
131
+ const issues = validatePageData(theme, page, { content: content[lang], locales: [lang] }).issues;
132
+ if (issues.length) failures.push(`${component.type}/${preset.key} (${lang}): ${issues[0]!.code}`);
133
+ }
134
+ }
135
+ }
136
+ expect(failures).toEqual([]);
137
+ });
138
+ });
139
+
140
+ describe("the rights a component declares", () => {
141
+ it("keeps a locked component to its own surface, and any other to the surfaces it allows", () => {
142
+ const surfaces = [...(theme.surfaces ?? []).map((surface) => surface.key), ...(theme.areas ?? []).map((area) => `area:${area.key}`)];
143
+ const outside: string[] = [];
144
+ for (const surface of theme.surfaces ?? []) {
145
+ for (const section of (surface.document as unknown as { sections?: ComponentInstance[] }).sections ?? []) {
146
+ const component = byType.get(section.type);
147
+ if (!component) { outside.push(`${surface.key}: unknown ${section.type}`); continue; }
148
+ if (component.capabilities?.surfaces && !component.capabilities.surfaces.includes(surface.key) && !isInsertableOn({ ...component, capabilities: { surfaces: component.capabilities.surfaces } }, surface.key)) outside.push(`${section.type} on ${surface.key}`);
149
+ }
150
+ }
151
+ expect(outside).toEqual([]);
152
+ expect(surfaces.length).toBeGreaterThan(0);
153
+ });
154
+ });
155
+
156
+ /** Sections that show the store's own collections or reviews: the test store has none, so a shopper sees the section hidden, which is right. The editor's preview still marks them. */
157
+ const EMPTY_WITHOUT_STORE_DATA = ["collection-cards", "testimonials"];
158
+
159
+ describe("every preset renders", () => {
160
+ it("renders each preset for a shopper and in the editor's preview, in every language, without a warning", async () => {
161
+ const failures: string[] = [];
162
+ for (const component of components) {
163
+ for (const preset of component.presets ?? []) {
164
+ const surface = component.capabilities?.surfaces?.[0] ?? "home";
165
+ for (const lang of LANGS) {
166
+ const document = { version: 1, surface, sections: [{ id: "p1", type: component.type, props: { ...(preset.props ?? {}) } }] };
167
+ for (const preview of [false, true]) {
168
+ const { html, issues } = await render(surface, document, { locale: lang, preview });
169
+ const label = `${component.type}/${preset.key} ${lang}${preview ? " preview" : ""}`;
170
+ if (issues.length) failures.push(`${label}: ${issues[0]}`);
171
+ if (html.length < 200 && !(preview === false && EMPTY_WITHOUT_STORE_DATA.includes(component.type))) failures.push(`${label}: nothing rendered`);
172
+ if (!preview && html.includes("wocart:")) failures.push(`${label}: an editor marker leaked to the shopper`);
173
+ if (preview && !html.includes(`id=p1 type=${component.type}`)) failures.push(`${label}: not marked for the editor`);
174
+ }
175
+ }
176
+ }
177
+ }
178
+ expect(failures).toEqual([]);
179
+ }, 120_000);
180
+ });
@@ -0,0 +1,91 @@
1
+ /**
2
+ * What the store answered, as the SDK reads it: real product answers (a
3
+ * product with sizes and two offers, one with quantity pricing) parsed by the
4
+ * SDK's own schemas, and a store double that serves them the way the client does.
5
+ */
6
+ import { ProductSchema, type LandingPage, type Product, type ProductList, type StoreConfig } from "@abcart/storefront";
7
+ import type { StoreClient } from "@abcart/storefront/server";
8
+ import shirtAnswer from "../fixtures/linen-shirt.json";
9
+ import toteAnswer from "../fixtures/canvas-tote.json";
10
+ import { buildStoreContext } from "../../src/lib/context";
11
+
12
+ export const shirt: Product = ProductSchema.parse(shirtAnswer);
13
+ const tote: Product = ProductSchema.parse(toteAnswer);
14
+ const asListed = ({ category: _category, variants: _variants, images: _images, quantityPricing: _pricing, offers: _offers, ...product }: Product): ProductList => ({ ...product, coverImage: null });
15
+ const catalog = [shirt, tote];
16
+
17
+ /** A published landing page selling the shirt, with two images and no layout of its own. */
18
+ export const landingPage: LandingPage = {
19
+ id: "fixture-landing",
20
+ slug: "lp-shirt",
21
+ name: "بذلة قطنية — عرض",
22
+ status: "published",
23
+ imageGap: 12,
24
+ metaTitle: null,
25
+ metaDescription: null,
26
+ publishedAt: "2026-10-01T00:00:00.000Z",
27
+ images: [1, 2].map((position) => ({ id: `img-${position}`, key: `landing/shirt-${position}.webp`, url: `https://media.example.test/landing/shirt-${position}.webp`, width: 1080, height: 1350, altText: null, position })),
28
+ product: shirt,
29
+ document: null,
30
+ tracking: { pixelId: null },
31
+ };
32
+
33
+ const pages = [{ id: "pg1", kind: "terms" as const, slug: "terms", locale: "ar", title: "الشروط", bodyHtml: "<p>نص الشروط.</p>", metaTitle: null, metaDescription: null }];
34
+
35
+ export function storeDouble(options: { empty?: boolean } = {}): StoreClient {
36
+ const products = options.empty ? [] : catalog;
37
+ return {
38
+ products: {
39
+ list: async () => products.map(asListed),
40
+ page: async () => ({ items: products.map(asListed), hasNext: false, total: products.length }),
41
+ get: async (handle: string) => products.find((product) => product.handle === handle) ?? null,
42
+ reviews: { list: async () => ({ rows: [], total: 0 }) },
43
+ },
44
+ collections: { get: async (handle: string) => (options.empty ? null : { handle, title: "الأكثر مبيعًا", description: null }) },
45
+ categories: { list: async () => (options.empty ? [] : [{ id: "c1", name: "ملابس", slug: "clothes", description: null, parentId: null, image: null, metaTitle: null, metaDescription: null, metaKeywords: null, position: 0, createdAt: "2026-01-01T00:00:00.000Z", updatedAt: "2026-01-01T00:00:00.000Z" }]) },
46
+ menus: { get: async () => null },
47
+ pageData: { get: async () => null },
48
+ pages: {
49
+ get: async (slug: string) => (options.empty ? null : (pages.find((page) => page.slug === slug) ?? null)),
50
+ landing: async (slug: string) => (options.empty || slug !== landingPage.slug ? null : landingPage),
51
+ },
52
+ } as unknown as StoreClient;
53
+ }
54
+
55
+ /** A store as its server answers: Arabic first, French and English published, its basket and reviews on. */
56
+ export function testConfig(locale = "ar"): StoreConfig {
57
+ return {
58
+ id: "store_test",
59
+ name: "متجر الاختبار",
60
+ domain: null,
61
+ logo: null,
62
+ lang: "ar",
63
+ locale,
64
+ locales: [
65
+ { code: "ar", nativeName: "العربية", direction: "rtl" },
66
+ { code: "fr", nativeName: "Français", direction: "ltr" },
67
+ { code: "en", nativeName: "English", direction: "ltr" },
68
+ ],
69
+ currency: "DZD",
70
+ currencySymbol: "دج",
71
+ metaTitle: null,
72
+ metaDescription: null,
73
+ ogImage: null,
74
+ media: { kind: "direct", origin: "https://media.example.test" },
75
+ reviewsEnabled: true,
76
+ cartEnabled: true,
77
+ freeShippingThreshold: null,
78
+ contentOverrides: {},
79
+ themeSettings: {},
80
+ checkoutForm: { address: "optional", notes: "optional", email: "optional", deliveryOptions: { home: true, stopDesk: true }, customFields: [] },
81
+ whatsapp: null,
82
+ pixelId: null,
83
+ pages: [{ id: "pg1", slug: "terms", title: "الشروط", kind: "terms", position: 1 }],
84
+ contact: { phone: null, email: null, address: null },
85
+ otpEnabled: false,
86
+ turnstileEnabled: false,
87
+ turnstileSiteKey: null,
88
+ };
89
+ }
90
+
91
+ export const storeContext = (locale = "ar", client = storeDouble(), overrides: Partial<StoreConfig> = {}) => buildStoreContext({ ...testConfig(locale), ...overrides }, locale, "/", client);
@@ -0,0 +1,54 @@
1
+ /**
2
+ * The footer and header show the store as its settings describe it: the logo
3
+ * uploaded in Settings (resized, in its own proportions) or the store's name,
4
+ * and the social pages the merchant added, each opening in a new tab that
5
+ * cannot reach back to the store.
6
+ */
7
+ import { describe, expect, it } from "vitest";
8
+ import { experimental_AstroContainer as AstroContainer } from "astro/container";
9
+ import Footer from "../../src/components/shell/Footer.astro";
10
+ import Header from "../../src/components/shell/Header.astro";
11
+ import { storeContext, storeDouble } from "./fixtures";
12
+
13
+ const logo = { key: "brand/logo.png", url: "https://media.example.test/brand/logo.png", width: 600, height: 150 };
14
+
15
+ async function render(component: typeof Footer, overrides: Parameters<typeof storeContext>[2] = {}) {
16
+ const container = await AstroContainer.create();
17
+ return container.renderToString(component, { props: {}, locals: { store: storeContext("ar", storeDouble(), overrides) } as unknown as App.Locals });
18
+ }
19
+
20
+ describe("the store's logo", () => {
21
+ for (const [place, component, height] of [["header", Header, 42], ["footer", Footer, 48]] as const) {
22
+ it(`shows in the ${place} in its own proportions, or the store's name without one`, async () => {
23
+ const withLogo = await render(component, { logo } as never);
24
+ expect(withLogo).toMatch(new RegExp(`<img[^>]*alt="متجر الاختبار"[^>]*width="${height * 4}"[^>]*height="${height}"`));
25
+ const without = await render(component, { logo: null } as never);
26
+ expect(without).not.toMatch(/<img[^>]*alt="متجر الاختبار"/);
27
+ expect(without).toContain(">متجر الاختبار</span>");
28
+ });
29
+ }
30
+ });
31
+
32
+ describe("the footer's social links", () => {
33
+ const social = (href: string, network = "instagram", label = "") => ({ id: `s-${network}`, props: { network, href, label } });
34
+
35
+ it("open each page the merchant added in a new tab, never leaving the store reachable", async () => {
36
+ const html = await render(Footer, { themeSettings: { socialLinks: [social("https://instagram.com/store"), social("https://tiktok.com/@store", "tiktok", "TikTok")] } } as never);
37
+ expect(html.match(/<a href="https:\/\/(instagram|tiktok)\.com[^"]*" target="_blank" rel="noopener noreferrer"/g)).toHaveLength(2);
38
+ });
39
+
40
+ it("skip a link without an address", async () => {
41
+ const html = await render(Footer, { themeSettings: { socialLinks: [social("")] } } as never);
42
+ expect(html).not.toContain("footer__social");
43
+ });
44
+ });
45
+
46
+ describe("the footer's contact column", () => {
47
+ it("shows only the ways to reach the store its settings hold, and no column without one", async () => {
48
+ const none = await render(Footer);
49
+ expect(none).not.toContain("footer__contact");
50
+ const html = await render(Footer, { contact: { phone: "0555 12 34 56", email: null, address: null } } as never);
51
+ expect(html).toContain('href="tel:0555123456"');
52
+ expect(html).not.toContain("mailto:");
53
+ });
54
+ });