fontdue-js 3.14.0 → 3.15.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 (226) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/__generated__/CartOrderCompleteOrderMutation.graphql.d.ts +1 -1
  3. package/dist/__generated__/CartOrderCompleteOrderMutation.graphql.js +3 -3
  4. package/dist/__generated__/CartOrderRemoveDiscountMutation.graphql.d.ts +1 -1
  5. package/dist/__generated__/CartOrderRemoveDiscountMutation.graphql.js +3 -3
  6. package/dist/__generated__/CartOrderUpdateMutation.graphql.d.ts +1 -1
  7. package/dist/__generated__/CartOrderUpdateMutation.graphql.js +3 -3
  8. package/dist/__generated__/CartQuery.graphql.d.ts +1 -1
  9. package/dist/__generated__/CartQuery.graphql.js +3 -3
  10. package/dist/__generated__/CartStateUpdateMutation.graphql.d.ts +5 -1
  11. package/dist/__generated__/CartStateUpdateMutation.graphql.js +132 -117
  12. package/dist/__generated__/CartState_order.graphql.d.ts +4 -1
  13. package/dist/__generated__/CartState_order.graphql.js +11 -2
  14. package/dist/__generated__/CheckoutUpdateCustomerMutation.graphql.d.ts +1 -1
  15. package/dist/__generated__/CheckoutUpdateCustomerMutation.graphql.js +3 -3
  16. package/dist/__generated__/CheckoutUpdateOrderMutation.graphql.d.ts +1 -1
  17. package/dist/__generated__/CheckoutUpdateOrderMutation.graphql.js +3 -3
  18. package/dist/__generated__/FamilyList_node.graphql.d.ts +3 -1
  19. package/dist/__generated__/FamilyList_node.graphql.js +8 -2
  20. package/dist/__generated__/FontFamiliesQuery.graphql.d.ts +1 -1
  21. package/dist/__generated__/FontFamiliesQuery.graphql.js +5 -5
  22. package/dist/__generated__/PrecartAddToCartMutation.graphql.d.ts +1 -1
  23. package/dist/__generated__/PrecartAddToCartMutation.graphql.js +3 -3
  24. package/dist/__generated__/StoreModalCartQuery.graphql.d.ts +1 -1
  25. package/dist/__generated__/StoreModalCartQuery.graphql.js +69 -69
  26. package/dist/__generated__/StoreModalFamily_collection.graphql.d.ts +2 -1
  27. package/dist/__generated__/StoreModalFamily_collection.graphql.js +16 -15
  28. package/dist/__generated__/StoreModalIndexItem_fontCollection.graphql.d.ts +19 -1
  29. package/dist/__generated__/StoreModalIndexItem_fontCollection.graphql.js +39 -4
  30. package/dist/__generated__/StoreModalIndexPaginationQuery.graphql.d.ts +1 -1
  31. package/dist/__generated__/StoreModalIndexPaginationQuery.graphql.js +40 -5
  32. package/dist/__generated__/StoreModalIndexQuery.graphql.d.ts +1 -1
  33. package/dist/__generated__/StoreModalIndexQuery.graphql.js +40 -5
  34. package/dist/__generated__/StoreModalProductContent_collection.graphql.d.ts +19 -1
  35. package/dist/__generated__/StoreModalProductContent_collection.graphql.js +46 -11
  36. package/dist/__generated__/StoreModalProductQuery.graphql.d.ts +1 -1
  37. package/dist/__generated__/StoreModalProductQuery.graphql.js +198 -167
  38. package/dist/__generated__/StoreModalProductRefetchQuery.graphql.d.ts +1 -1
  39. package/dist/__generated__/StoreModalProductRefetchQuery.graphql.js +171 -140
  40. package/dist/__generated__/StoreModalProductSlugQuery.graphql.d.ts +1 -1
  41. package/dist/__generated__/StoreModalProductSlugQuery.graphql.js +201 -170
  42. package/dist/__generated__/StripeProviderCreateCheckoutSessionMutation.graphql.d.ts +5 -2
  43. package/dist/__generated__/StripeProviderCreateCheckoutSessionMutation.graphql.js +41 -22
  44. package/dist/__generated__/TestFontsFormUpdateCustomerMutation.graphql.d.ts +1 -1
  45. package/dist/__generated__/TestFontsFormUpdateCustomerMutation.graphql.js +3 -3
  46. package/dist/__generated__/TypeTesterStandaloneChangedStylesQuery.graphql.d.ts +1 -1
  47. package/dist/__generated__/TypeTesterStandaloneChangedStylesQuery.graphql.js +9 -3
  48. package/dist/__generated__/TypeTesterStandaloneQuery.graphql.d.ts +1 -1
  49. package/dist/__generated__/TypeTesterStandaloneQuery.graphql.js +9 -3
  50. package/dist/__generated__/TypeTester_fontStyle.graphql.d.ts +3 -1
  51. package/dist/__generated__/TypeTester_fontStyle.graphql.js +8 -2
  52. package/dist/__generated__/TypeTestersChangedStylesQuery.graphql.d.ts +1 -1
  53. package/dist/__generated__/TypeTestersChangedStylesQuery.graphql.js +9 -3
  54. package/dist/__generated__/TypeTestersIDQuery.graphql.d.ts +1 -1
  55. package/dist/__generated__/TypeTestersIDQuery.graphql.js +39 -39
  56. package/dist/__generated__/TypeTestersRefetchQuery.graphql.d.ts +1 -1
  57. package/dist/__generated__/TypeTestersRefetchQuery.graphql.js +37 -37
  58. package/dist/__generated__/TypeTestersSlugQuery.graphql.d.ts +1 -1
  59. package/dist/__generated__/TypeTestersSlugQuery.graphql.js +39 -39
  60. package/dist/__tests__/cartDiscountRemoved.test.js +195 -0
  61. package/dist/__tests__/characterViewerCollapse.test.js +199 -0
  62. package/dist/__tests__/characterViewerStyleSelect.test.js +52 -0
  63. package/dist/__tests__/checkoutReturn.test.js +66 -0
  64. package/dist/__tests__/familyStyleCounts.test.js +71 -0
  65. package/dist/__tests__/i18n.test.js +171 -0
  66. package/dist/__tests__/i18nComponents.test.js +408 -0
  67. package/dist/__tests__/localeEnvironments.test.js +275 -0
  68. package/dist/__tests__/localeMiddleware.test.js +68 -0
  69. package/dist/__tests__/localeTransport.test.js +209 -0
  70. package/dist/__tests__/recaptchaLocale.test.js +62 -0
  71. package/dist/__tests__/serverEntryLocale.test.js +124 -0
  72. package/dist/__tests__/storeModalIndexUnlisted.test.js +69 -11
  73. package/dist/__tests__/useSerializablePreloadedQuery.test.js +4 -3
  74. package/dist/components/AddToCartBanner/index.js +8 -2
  75. package/dist/components/BuyButton/index.d.ts +1 -0
  76. package/dist/components/BuyButton/index.js +8 -2
  77. package/dist/components/BuyButton/index.server.d.ts +1 -0
  78. package/dist/components/BuyButton/index.server.js +8 -0
  79. package/dist/components/BuyingOptions/index.js +3 -1
  80. package/dist/components/Cart/AddressFields.js +5 -3
  81. package/dist/components/Cart/CartCouponNotice.d.ts +7 -0
  82. package/dist/components/Cart/CartCouponNotice.js +21 -0
  83. package/dist/components/Cart/CartItem/CartItemAdditionalLicenses.js +3 -1
  84. package/dist/components/Cart/CartItem/CartItemLicense.js +3 -1
  85. package/dist/components/Cart/CartItem/CartItemProduct.js +6 -3
  86. package/dist/components/Cart/CartItem/VariableTextInput.js +7 -3
  87. package/dist/components/Cart/CartItem/index.js +5 -1
  88. package/dist/components/Cart/CartOrder.js +27 -17
  89. package/dist/components/Cart/CartState.d.ts +1 -0
  90. package/dist/components/Cart/CartState.js +18 -3
  91. package/dist/components/Cart/CartTotals.js +17 -9
  92. package/dist/components/Cart/Checkout.js +18 -15
  93. package/dist/components/Cart/CouponCodeInput.js +5 -3
  94. package/dist/components/Cart/CustomerFields.js +6 -4
  95. package/dist/components/Cart/EmptyCart.js +4 -2
  96. package/dist/components/Cart/IdentityBox.js +6 -2
  97. package/dist/components/Cart/ShareCart.js +8 -6
  98. package/dist/components/Cart/checkoutReturn.d.ts +17 -0
  99. package/dist/components/Cart/checkoutReturn.js +38 -0
  100. package/dist/components/CartButton/index.d.ts +2 -1
  101. package/dist/components/CartButton/index.js +6 -2
  102. package/dist/components/CharacterViewer/StyleSelect.js +6 -2
  103. package/dist/components/CharacterViewer/collapse.d.ts +10 -0
  104. package/dist/components/CharacterViewer/collapse.js +39 -0
  105. package/dist/components/CharacterViewer/index.d.ts +4 -0
  106. package/dist/components/CharacterViewer/index.js +78 -24
  107. package/dist/components/CharacterViewer/index.server.d.ts +1 -0
  108. package/dist/components/CharacterViewer/index.server.js +4 -0
  109. package/dist/components/ConfigContext.d.ts +14 -10
  110. package/dist/components/ConfigContext.js +12 -7
  111. package/dist/components/ConsentBanner/index.js +6 -5
  112. package/dist/components/CookieNotification/index.js +11 -5
  113. package/dist/components/CouponText/index.js +15 -7
  114. package/dist/components/CustomerLoginForm/index.js +14 -9
  115. package/dist/components/CustomerSignIn/CustomerSignInElement.d.ts +1 -1
  116. package/dist/components/CustomerSignIn/CustomerSignInElement.js +8 -2
  117. package/dist/components/CustomerSignIn/index.d.ts +6 -1
  118. package/dist/components/CustomerSignIn/index.js +27 -15
  119. package/dist/components/Family/FamilyList.js +5 -2
  120. package/dist/components/Family/index.js +21 -12
  121. package/dist/components/FeatureTester/FeatureTesters.d.ts +2 -1
  122. package/dist/components/FeatureTester/FeatureTesters.js +4 -1
  123. package/dist/components/FeatureTester/FeatureTesters.server.js +4 -0
  124. package/dist/components/FeatureTester/index.d.ts +1 -0
  125. package/dist/components/FeatureTester/index.js +3 -1
  126. package/dist/components/FeatureTester/index.server.js +2 -0
  127. package/dist/components/FontdueContextProvider/index.d.ts +12 -2
  128. package/dist/components/FontdueContextProvider/index.js +85 -11
  129. package/dist/components/FontdueProvider/index.js +7 -1
  130. package/dist/components/FontdueProvider/index.server.js +21 -3
  131. package/dist/components/LocaleContext.d.ts +9 -0
  132. package/dist/components/LocaleContext.js +20 -0
  133. package/dist/components/NewsletterSignup/index.d.ts +2 -1
  134. package/dist/components/NewsletterSignup/index.js +20 -11
  135. package/dist/components/NewsletterSignup/index.server.d.ts +1 -0
  136. package/dist/components/NewsletterSignup/index.server.js +3 -1
  137. package/dist/components/NodePasswordForm/index.d.ts +6 -1
  138. package/dist/components/NodePasswordForm/index.js +14 -6
  139. package/dist/components/OrderVariableSelection/index.js +7 -5
  140. package/dist/components/Precart/License.js +4 -2
  141. package/dist/components/Precart/index.js +15 -12
  142. package/dist/components/Price/index.d.ts +1 -0
  143. package/dist/components/Price/index.js +15 -5
  144. package/dist/components/Root/index.js +2 -1
  145. package/dist/components/Select/index.d.ts +1 -1
  146. package/dist/components/Select/index.js +4 -1
  147. package/dist/components/SelectButton/index.js +3 -1
  148. package/dist/components/SpecimenLink/index.js +3 -1
  149. package/dist/components/StoreModal/StoreModalCart.js +6 -0
  150. package/dist/components/StoreModal/StoreModalContainer.js +14 -12
  151. package/dist/components/StoreModal/StoreModalDownload.js +3 -1
  152. package/dist/components/StoreModal/StoreModalFamily.js +16 -7
  153. package/dist/components/StoreModal/StoreModalFamilyButton.js +14 -9
  154. package/dist/components/StoreModal/StoreModalIndexItem.js +21 -10
  155. package/dist/components/StoreModal/StoreModalIndexPackItem.js +8 -3
  156. package/dist/components/StoreModal/StoreModalPackButton.js +5 -2
  157. package/dist/components/StoreModal/StoreModalProduct.js +14 -5
  158. package/dist/components/StoreModal/index.d.ts +1 -0
  159. package/dist/components/StoreModal/index.js +4 -2
  160. package/dist/components/StoreModal/offered.d.ts +31 -0
  161. package/dist/components/StoreModal/offered.js +21 -0
  162. package/dist/components/StoreModal/types.d.ts +9 -0
  163. package/dist/components/StoreModalProductLicenseSelection/LicenseVariableElement.js +3 -1
  164. package/dist/components/StoreModalProductLicenseSelection/StoreModalProductLicense.js +5 -1
  165. package/dist/components/StoreModalProductSummary/index.js +37 -23
  166. package/dist/components/StripeProvider/index.js +18 -5
  167. package/dist/components/TestFontsForm/index.d.ts +2 -1
  168. package/dist/components/TestFontsForm/index.js +28 -16
  169. package/dist/components/TestFontsForm/index.server.d.ts +1 -0
  170. package/dist/components/TestFontsForm/index.server.js +3 -1
  171. package/dist/components/TestModeBanner/index.js +3 -1
  172. package/dist/components/TypeTester/TypeTesterEditAll.js +3 -1
  173. package/dist/components/TypeTester/TypeTesterFeaturesButton.js +4 -2
  174. package/dist/components/TypeTester/TypeTesterStandalone.d.ts +1 -0
  175. package/dist/components/TypeTester/TypeTesterStandalone.js +6 -2
  176. package/dist/components/TypeTester/TypeTesterStandalone.server.js +2 -0
  177. package/dist/components/TypeTester/TypeTesterStyleSelect.js +5 -3
  178. package/dist/components/TypeTester/TypeTesterStyleSelectData.js +3 -1
  179. package/dist/components/TypeTester/TypeTesterToolbar.js +12 -6
  180. package/dist/components/TypeTester/index.js +7 -2
  181. package/dist/components/TypeTesters/index.d.ts +2 -1
  182. package/dist/components/TypeTesters/index.js +3 -1
  183. package/dist/components/TypeTesters/index.server.d.ts +1 -0
  184. package/dist/components/TypeTesters/index.server.js +4 -0
  185. package/dist/components/elements/EmptyCart/index.js +4 -2
  186. package/dist/components/elements/StoreModalCartLayout/index.d.ts +1 -0
  187. package/dist/components/elements/StoreModalCartLayout/index.js +2 -1
  188. package/dist/components/elements/StoreModalContainer/index.js +4 -2
  189. package/dist/components/elements/StoreModalDownloadLayout/index.js +3 -1
  190. package/dist/components/elements/StoreModalIndexItem/index.js +3 -1
  191. package/dist/components/elements/StoreModalIndexLoadMore/index.js +3 -1
  192. package/dist/components/elements/StoreModalLicenseeIsBillingIdentityElement.js +4 -2
  193. package/dist/components/elements/StoreModalLoadingScreen/index.js +7 -3
  194. package/dist/components/elements/StoreModalUnifiedCheckout.js +44 -27
  195. package/dist/fontdue.css +58 -0
  196. package/dist/hooks/useRecaptchaTimeout.d.ts +1 -1
  197. package/dist/hooks/useRecaptchaTimeout.js +4 -2
  198. package/dist/i18n/de.d.ts +3 -0
  199. package/dist/i18n/de.js +279 -0
  200. package/dist/i18n/en.d.ts +212 -0
  201. package/dist/i18n/en.js +261 -0
  202. package/dist/i18n/index.d.ts +42 -0
  203. package/dist/i18n/index.js +115 -0
  204. package/dist/i18n/types.d.ts +28 -0
  205. package/dist/i18n/types.js +1 -0
  206. package/dist/i18n/useT.d.ts +15 -0
  207. package/dist/i18n/useT.js +21 -0
  208. package/dist/locale.d.ts +20 -0
  209. package/dist/locale.js +52 -0
  210. package/dist/next/tenant.d.ts +3 -1
  211. package/dist/next/tenant.js +11 -2
  212. package/dist/relay/environment.d.ts +8 -2
  213. package/dist/relay/environment.js +65 -15
  214. package/dist/relay/loadSerializableQuery.d.ts +17 -0
  215. package/dist/relay/loadSerializableQuery.js +14 -2
  216. package/dist/relay/serverConfig.d.ts +9 -0
  217. package/dist/relay/serverConfig.js +16 -0
  218. package/dist/relay/useSerializablePreloadedQuery.js +27 -6
  219. package/dist/server/index.d.ts +11 -0
  220. package/dist/server/index.js +7 -0
  221. package/dist/server/middleware.d.ts +19 -1
  222. package/dist/server/middleware.js +56 -13
  223. package/dist/utils.d.ts +0 -1
  224. package/dist/utils.js +0 -5
  225. package/dist/version.js +1 -1
  226. package/package.json +1 -1
@@ -0,0 +1,408 @@
1
+ // @vitest-environment happy-dom
2
+
3
+ // fontdue-js UI text in the page's language: with `locale="de"` the store
4
+ // modal, cart, checkout, sign-in, test fonts form and type tester render their
5
+ // fixed text from the German catalogue; with no locale they render exactly the
6
+ // English they always did. Label props and config labels still win over the
7
+ // catalogue in every language.
8
+
9
+ import React, { act } from 'react';
10
+ import { createRoot } from 'react-dom/client';
11
+ import { renderToStaticMarkup } from 'react-dom/server';
12
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
13
+ const {
14
+ stateRef,
15
+ queryRef
16
+ } = vi.hoisted(() => ({
17
+ stateRef: {
18
+ current: null
19
+ },
20
+ queryRef: {
21
+ data: null
22
+ }
23
+ }));
24
+
25
+ // Fragments hand back the data they're given; queries return `queryRef.data`.
26
+ vi.mock('react-relay', () => ({
27
+ graphql: () => null,
28
+ commitMutation: vi.fn(),
29
+ fetchQuery: vi.fn(),
30
+ useFragment: (_fragment, key) => key,
31
+ useMutation: () => [vi.fn(), false],
32
+ useRelayEnvironment: () => ({}),
33
+ useLazyLoadQuery: () => queryRef.data,
34
+ usePreloadedQuery: () => queryRef.data
35
+ }));
36
+
37
+ // CartTotals takes its `graphql` tag from relay-runtime.
38
+ vi.mock('relay-runtime', async importOriginal => ({
39
+ ...(await importOriginal()),
40
+ graphql: () => null
41
+ }));
42
+ vi.mock('react-redux', async importOriginal => ({
43
+ ...(await importOriginal()),
44
+ useDispatch: () => vi.fn(),
45
+ useSelector: selector => selector(stateRef.current)
46
+ }));
47
+ vi.mock('../components/FontdueContextProvider/index.js', () => ({
48
+ EnsureFontdueContext: _ref => {
49
+ let {
50
+ children
51
+ } = _ref;
52
+ return /*#__PURE__*/React.createElement(React.Fragment, null, children);
53
+ },
54
+ LazyQueryBoundary: _ref2 => {
55
+ let {
56
+ children
57
+ } = _ref2;
58
+ return /*#__PURE__*/React.createElement(React.Fragment, null, children);
59
+ }
60
+ }));
61
+ import LocaleContext from '../components/LocaleContext.js';
62
+ import ConfigContext, { makeConfig } from '../components/ConfigContext.js';
63
+ import { createDefaultStore } from '../reducer.js';
64
+ import { useT } from '../i18n/useT.js';
65
+ import StoreModalContainerElement from '../components/elements/StoreModalContainer/index.js';
66
+ import StoreModalPackButton from '../components/StoreModal/StoreModalPackButton.js';
67
+ import StoreModalIndexPackItem from '../components/StoreModal/StoreModalIndexPackItem.js';
68
+ import StoreModalLicenseeIsBillingIdentityElement from '../components/elements/StoreModalLicenseeIsBillingIdentityElement.js';
69
+ import EmptyCartElement from '../components/elements/EmptyCart/index.js';
70
+ import CartTotals from '../components/Cart/CartTotals.js';
71
+ import Checkout from '../components/Cart/Checkout.js';
72
+ import CheckoutSteps from '../components/Cart/CheckoutSteps.js';
73
+ import CustomerSignIn from '../components/CustomerSignIn/index.js';
74
+ import TestFontsForm from '../components/TestFontsForm/index.js';
75
+ import TypeTesterEditAll from '../components/TypeTester/TypeTesterEditAll.js';
76
+ import Select from '../components/Select/index.js';
77
+ globalThis.IS_REACT_ACT_ENVIRONMENT = true;
78
+ const inLocale = (locale, node) => /*#__PURE__*/React.createElement(LocaleContext.Provider, {
79
+ value: locale
80
+ }, node);
81
+ const markup = (locale, node) => renderToStaticMarkup(inLocale(locale, node));
82
+ let container;
83
+ let root;
84
+ beforeEach(() => {
85
+ stateRef.current = createDefaultStore(undefined).getState();
86
+ container = document.createElement('div');
87
+ document.body.append(container);
88
+ root = createRoot(container);
89
+ });
90
+ afterEach(() => {
91
+ act(() => root.unmount());
92
+ container.remove();
93
+ });
94
+ const mount = async (locale, node) => {
95
+ await act(async () => root.render(inLocale(locale, node)));
96
+ return container;
97
+ };
98
+ describe('useT', () => {
99
+ function Probe() {
100
+ const t = useT();
101
+ return /*#__PURE__*/React.createElement("span", null, t('productSummary.addToCart'), " / ", t('common.styleCount', {
102
+ count: 2
103
+ }));
104
+ }
105
+ it('is English with no locale', () => {
106
+ expect(markup(undefined, /*#__PURE__*/React.createElement(Probe, null))).toBe('<span>Add to cart / 2 styles</span>');
107
+ });
108
+ it('follows the surrounding locale', () => {
109
+ expect(markup('de', /*#__PURE__*/React.createElement(Probe, null))).toBe('<span>In den Warenkorb / 2 Schnitte</span>');
110
+ expect(markup('de-CH', /*#__PURE__*/React.createElement(Probe, null))).toBe('<span>In den Warenkorb / 2 Schnitte</span>');
111
+ });
112
+ it('is English for a language without a catalogue', () => {
113
+ expect(markup('fr', /*#__PURE__*/React.createElement(Probe, null))).toBe('<span>Add to cart / 2 styles</span>');
114
+ });
115
+ it('is English outside any provider', () => {
116
+ expect(renderToStaticMarkup( /*#__PURE__*/React.createElement(Probe, null))).toBe('<span>Add to cart / 2 styles</span>');
117
+ });
118
+ });
119
+ describe('store modal', () => {
120
+ const container = locale => markup(locale, /*#__PURE__*/React.createElement(StoreModalContainerElement, {
121
+ orderItemCount: 1,
122
+ showCartButton: true,
123
+ routeName: "product",
124
+ fonts: {
125
+ regular: null,
126
+ bold: null
127
+ }
128
+ }, {
129
+ backText: 'Back',
130
+ pageTitle: 'Title',
131
+ body: null
132
+ }));
133
+ it('labels the cart and close buttons in the page language', () => {
134
+ expect(container(undefined)).toContain('aria-label="Cart"');
135
+ expect(container(undefined)).toContain('aria-label="Close"');
136
+ expect(container('de')).toContain('aria-label="Warenkorb"');
137
+ expect(container('de')).toContain('aria-label="Schließen"');
138
+ });
139
+ const pack = {
140
+ id: 'pack',
141
+ name: 'Basics',
142
+ sku: {
143
+ id: 'pack-sku',
144
+ price: {
145
+ amount: 15000,
146
+ currency: 'USD'
147
+ }
148
+ },
149
+ featureStyle: null,
150
+ totalStyles: 3,
151
+ totalStylesPrice: {
152
+ amount: 30000,
153
+ currency: 'USD'
154
+ }
155
+ };
156
+ it('counts styles with plural messages', () => {
157
+ const button = locale => markup(locale, /*#__PURE__*/React.createElement(StoreModalPackButton, {
158
+ pack: pack,
159
+ onSelectSku: () => {}
160
+ }));
161
+ expect(button()).toContain('>3 styles<');
162
+ expect(button('de')).toContain('>3 Schnitte<');
163
+ expect(markup('de', /*#__PURE__*/React.createElement(StoreModalPackButton, {
164
+ pack: {
165
+ ...pack,
166
+ totalStyles: 1
167
+ },
168
+ onSelectSku: () => {}
169
+ }))).toContain('>1 Schnitt<');
170
+ });
171
+ it('labels a pack on the index', () => {
172
+ expect(markup(undefined, /*#__PURE__*/React.createElement(StoreModalIndexPackItem, {
173
+ pack: pack
174
+ }))).toContain('Font pack • 3 styles');
175
+ expect(markup('de', /*#__PURE__*/React.createElement(StoreModalIndexPackItem, {
176
+ pack: pack
177
+ }))).toContain('Font-Paket • 3 Schnitte');
178
+ expect(markup('de', /*#__PURE__*/React.createElement(StoreModalIndexPackItem, {
179
+ pack: pack
180
+ }))).toContain('>Kaufen<');
181
+ });
182
+ it('defaults the licensee choices, and a foundry label still wins', () => {
183
+ const element = (locale, selfLabel) => markup(locale, /*#__PURE__*/React.createElement(StoreModalLicenseeIsBillingIdentityElement, {
184
+ disabled: false,
185
+ value: null,
186
+ onChange: () => {}
187
+ }, {
188
+ label: 'Who is the licensee?',
189
+ selfLabel
190
+ }));
191
+ expect(element(undefined)).toContain('Yourself');
192
+ expect(element(undefined)).toContain('Your client');
193
+ expect(element('de')).toContain('Sie selbst');
194
+ expect(element('de')).toContain('Ihr Kunde');
195
+ expect(element('de', 'Für mich')).toContain('Für mich');
196
+ expect(element('de', 'Für mich')).not.toContain('Sie selbst');
197
+ });
198
+ });
199
+ describe('cart', () => {
200
+ const order = {
201
+ subtotal: {
202
+ amount: 10000,
203
+ currency: 'EUR'
204
+ },
205
+ discount: null,
206
+ discountedSubtotal: {
207
+ amount: 10000,
208
+ currency: 'EUR'
209
+ },
210
+ total: {
211
+ amount: 10000,
212
+ currency: 'EUR'
213
+ },
214
+ taxRate: null,
215
+ taxes: null,
216
+ taxName: null,
217
+ taxNotApplicable: false,
218
+ taxNotApplicableReason: null,
219
+ gstIncluded: false
220
+ };
221
+ it('renders the totals in German, keeping the English data-label hooks', () => {
222
+ const html = markup('de', /*#__PURE__*/React.createElement(CartTotals, {
223
+ order: order,
224
+ taxSystem: "stripe"
225
+ }));
226
+ expect(html).toContain('>Zwischensumme<');
227
+ expect(html).toContain('>Gesamt</div>');
228
+ expect(html).toContain('Wird an der Kasse berechnet');
229
+ expect(html).toContain('data-label="Subtotal"');
230
+ });
231
+ it('renders the totals in English with no locale, as before', () => {
232
+ const html = markup(undefined, /*#__PURE__*/React.createElement(CartTotals, {
233
+ order: order,
234
+ taxSystem: "stripe"
235
+ }));
236
+ expect(html).toContain('<div class="cart__price-block__label">Subtotal</div>');
237
+ expect(html).toContain('Calculated at checkout');
238
+ expect(html).toContain('data-label="Subtotal"');
239
+ expect(html).toMatch(/cart__price-block__label">\s*Total\s*<\/div>/);
240
+ });
241
+ it('says a tax doesn’t apply in the page language', () => {
242
+ const exempt = {
243
+ ...order,
244
+ taxNotApplicable: true
245
+ };
246
+ expect(markup(undefined, /*#__PURE__*/React.createElement(CartTotals, {
247
+ order: exempt
248
+ }))).toContain('VAT not applicable');
249
+ expect(markup('de', /*#__PURE__*/React.createElement(CartTotals, {
250
+ order: exempt
251
+ }))).toContain('USt. entfällt');
252
+ });
253
+ it('renders the empty cart in German', () => {
254
+ const html = markup('de', /*#__PURE__*/React.createElement(ConfigContext.Provider, {
255
+ value: makeConfig()
256
+ }, /*#__PURE__*/React.createElement(EmptyCartElement, null)));
257
+ expect(html).toContain('Ihr Warenkorb ist leer.');
258
+ expect(html).toContain('Weiter einkaufen');
259
+ });
260
+ });
261
+ describe('checkout', () => {
262
+ const viewer = {
263
+ country: 'DE',
264
+ settings: {
265
+ uiFontName: 'Test',
266
+ newsletterOptInLabel: null
267
+ },
268
+ themeConfig: {
269
+ customProperties: null
270
+ }
271
+ };
272
+ const checkout = (locale, saveText) => mount(locale, /*#__PURE__*/React.createElement(Checkout, {
273
+ order: null,
274
+ viewer: viewer,
275
+ checkoutStep: CheckoutSteps.Customer,
276
+ setCheckoutStep: () => {},
277
+ onScrollToTop: () => {},
278
+ onComplete: () => {},
279
+ onCancel: () => {},
280
+ skipPaymentMethod: true,
281
+ saveText: saveText
282
+ }));
283
+ it('renders the contact step in German', async () => {
284
+ const html = (await checkout('de')).innerHTML;
285
+ expect(html).toContain('Kontaktdaten');
286
+ expect(html).toContain('Ihr Name');
287
+ expect(html).toContain('E-Mail *');
288
+ expect(html).toContain('Abbrechen');
289
+ expect(html).toContain('Weiter');
290
+ });
291
+ it('renders the contact step in English with no locale', async () => {
292
+ const html = (await checkout(undefined)).innerHTML;
293
+ expect(html).toContain('Contact information');
294
+ expect(html).toContain('Your name');
295
+ expect(html).toContain('Cancel');
296
+ expect(html).toContain('Next');
297
+ });
298
+ it('keeps a save label passed in', async () => {
299
+ const html = (await checkout('de', 'Bestellen')).innerHTML;
300
+ expect(html).toContain('Bestellen');
301
+ expect(html).not.toContain('Weiter');
302
+ });
303
+ });
304
+ describe('customer sign-in', () => {
305
+ it('renders in German', async () => {
306
+ const html = (await mount('de', /*#__PURE__*/React.createElement(CustomerSignIn, null))).innerHTML;
307
+ expect(html).toContain('Code per E-Mail senden');
308
+ expect(html).toContain('Ihre E-Mail-Adresse');
309
+ });
310
+ it('keeps a label passed in', async () => {
311
+ const html = (await mount('de', /*#__PURE__*/React.createElement(CustomerSignIn, {
312
+ requestLabel: "Send it"
313
+ }))).innerHTML;
314
+ expect(html).toContain('Send it');
315
+ expect(html).not.toContain('Code per E-Mail senden');
316
+ });
317
+ it('renders in English with no locale', async () => {
318
+ const html = (await mount(undefined, /*#__PURE__*/React.createElement(CustomerSignIn, null))).innerHTML;
319
+ expect(html).toContain('Email me a code');
320
+ expect(html).toContain('Your email');
321
+ });
322
+ });
323
+ describe('test fonts form', () => {
324
+ beforeEach(() => {
325
+ queryRef.data = {
326
+ viewer: {
327
+ settings: {
328
+ eulaAgreementLabel: 'I agree',
329
+ newsletterOptInLabel: null,
330
+ recaptchaEnabled: false,
331
+ recaptchaSiteKey: null
332
+ },
333
+ fontdueConfig: {
334
+ testFonts: {
335
+ familySelection: 'all',
336
+ familyGrouping: 'flat'
337
+ }
338
+ },
339
+ testFonts: {
340
+ archiveUrl: 'https://example.test/archive',
341
+ families: []
342
+ }
343
+ }
344
+ };
345
+ });
346
+ const form = function (locale) {
347
+ let props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
348
+ return mount(locale, /*#__PURE__*/React.createElement(ConfigContext.Provider, {
349
+ value: makeConfig()
350
+ }, /*#__PURE__*/React.createElement(TestFontsForm, props)));
351
+ };
352
+ it('renders in German', async () => {
353
+ const html = (await form('de')).innerHTML;
354
+ expect(html).toContain('Testschriften herunterladen');
355
+ expect(html).toContain('Ihr Name');
356
+ });
357
+ it('keeps the download label passed in', async () => {
358
+ const html = (await form('de', {
359
+ downloadLabel: 'Holen'
360
+ })).innerHTML;
361
+ expect(html).toContain('Holen');
362
+ expect(html).not.toContain('Testschriften herunterladen');
363
+ });
364
+ it('renders in English with no locale', async () => {
365
+ expect((await form(undefined)).innerHTML).toContain('Download test fonts');
366
+ });
367
+ });
368
+ describe('type tester', () => {
369
+ it('no longer bakes English labels into the config', () => {
370
+ var _config$lineHeight, _config$letterSpacing;
371
+ const config = makeConfig({
372
+ typeTester: {
373
+ lineHeight: {},
374
+ letterSpacing: {}
375
+ }
376
+ }).typeTester;
377
+ expect(config.selectButtonLabel).toBeUndefined();
378
+ expect(config.openTypeFeatures.buttonLabel).toBeUndefined();
379
+ expect(config.size.label).toBeUndefined();
380
+ expect((_config$lineHeight = config.lineHeight) === null || _config$lineHeight === void 0 ? void 0 : _config$lineHeight.label).toBeUndefined();
381
+ expect((_config$letterSpacing = config.letterSpacing) === null || _config$letterSpacing === void 0 ? void 0 : _config$letterSpacing.label).toBeUndefined();
382
+ // A label a site sets, or `false` to hide one, is kept.
383
+ const set = makeConfig({
384
+ typeTester: {
385
+ size: {
386
+ label: false
387
+ },
388
+ selectButtonLabel: 'Pick'
389
+ }
390
+ });
391
+ expect(set.typeTester.size.label).toBe(false);
392
+ expect(set.typeTester.selectButtonLabel).toBe('Pick');
393
+ });
394
+ it('renders “Affect all styles” in the page language', () => {
395
+ expect(markup(undefined, /*#__PURE__*/React.createElement(TypeTesterEditAll, null))).toContain('Affect all styles');
396
+ expect(markup('de', /*#__PURE__*/React.createElement(TypeTesterEditAll, null))).toContain('Alle Schnitte ändern');
397
+ });
398
+ it('defaults a select box’s placeholder, and an explicit one wins', () => {
399
+ const select = (locale, nullText) => markup(locale, /*#__PURE__*/React.createElement(Select, {
400
+ value: null,
401
+ options: [],
402
+ nullText: nullText
403
+ }));
404
+ expect(select(undefined)).toContain('Select</option>');
405
+ expect(select('de')).toContain('Auswählen</option>');
406
+ expect(select('de', 'Custom')).toContain('Custom</option>');
407
+ });
408
+ });
@@ -0,0 +1,275 @@
1
+ // @vitest-environment happy-dom
2
+ import React from 'react';
3
+ import { renderToString } from 'react-dom/server';
4
+ import { useRelayEnvironment } from 'react-relay';
5
+ import { afterEach, describe, expect, it, vi } from 'vitest';
6
+
7
+ // The provider pulls in modules that declare `graphql` tagged queries at load
8
+ // time; without the Relay Babel transform the tag throws, so stub it — nothing
9
+ // rendered here runs a query.
10
+ vi.mock('react-relay', async importActual => {
11
+ const actual = await importActual();
12
+ return {
13
+ ...actual,
14
+ ...actual.default,
15
+ graphql: () => ({})
16
+ };
17
+ });
18
+ import { createNetworkFetch, responseCacheFor, useCurrentEnvironment } from '../relay/environment.js';
19
+ import FontdueContextProvider, { EnsureFontdueContext } from '../components/FontdueContextProvider/index.js';
20
+ import { useLocale } from '../components/LocaleContext.js';
21
+ import useSerializablePreloadedQuery from '../relay/useSerializablePreloadedQuery.js';
22
+ import { Price } from '../components/Price/index.js';
23
+ import { LOCALE_HEADER } from '../locale.js';
24
+
25
+ // One page, one language: Relay normalises records by id, so a German and an
26
+ // English `FontCollection:1` must never share a store. Each locale gets its own
27
+ // client environment (shared by every island in that locale), and a preload
28
+ // lands in the environment for the language it was fetched in.
29
+
30
+ afterEach(() => {
31
+ vi.unstubAllGlobals();
32
+ vi.restoreAllMocks();
33
+ });
34
+ function Probe(_ref) {
35
+ let {
36
+ seen
37
+ } = _ref;
38
+ seen.push({
39
+ environment: useRelayEnvironment(),
40
+ locale: useLocale()
41
+ });
42
+ return null;
43
+ }
44
+ describe('client Relay environments', () => {
45
+ it('shares one environment per locale and never across locales', () => {
46
+ const de = useCurrentEnvironment({
47
+ locale: 'de'
48
+ });
49
+ expect(useCurrentEnvironment({
50
+ locale: 'de'
51
+ })).toBe(de);
52
+ expect(useCurrentEnvironment({
53
+ locale: ' de '
54
+ })).toBe(de);
55
+ const none = useCurrentEnvironment({});
56
+ expect(useCurrentEnvironment({
57
+ locale: ''
58
+ })).toBe(none);
59
+ expect(none).not.toBe(de);
60
+ expect(useCurrentEnvironment({
61
+ locale: 'en'
62
+ })).not.toBe(none);
63
+
64
+ // Each has its own response cache, keyed by query + variables only.
65
+ expect(responseCacheFor(de)).not.toBeNull();
66
+ expect(responseCacheFor(de)).not.toBe(responseCacheFor(none));
67
+ });
68
+ it('sends the locale from the browser only when one is configured', async () => {
69
+ const fetchMock = vi.fn(async (_url, _init) => ({
70
+ ok: true,
71
+ status: 200,
72
+ json: async () => ({
73
+ data: {
74
+ viewer: {
75
+ id: '1'
76
+ }
77
+ }
78
+ })
79
+ }));
80
+ vi.stubGlobal('fetch', fetchMock);
81
+ const request = {
82
+ name: 'TestQuery',
83
+ text: 'query TestQuery { viewer { id } }'
84
+ };
85
+ await createNetworkFetch({
86
+ url: 'https://acme.fontdue.com'
87
+ })(request, {});
88
+ await createNetworkFetch({
89
+ url: 'https://acme.fontdue.com',
90
+ locale: 'de'
91
+ })(request, {});
92
+ const headers = call => fetchMock.mock.calls[call][1].headers;
93
+ expect(headers(0)).not.toHaveProperty(LOCALE_HEADER);
94
+ expect(headers(1)[LOCALE_HEADER]).toBe('de');
95
+ });
96
+ });
97
+ describe('locale in the component tree', () => {
98
+ it('useLocale is undefined with no provider, and normalised under one', () => {
99
+ let bare = 'unset';
100
+ function LocaleOnly() {
101
+ bare = useLocale();
102
+ return null;
103
+ }
104
+ renderToString( /*#__PURE__*/React.createElement(LocaleOnly, null));
105
+ expect(bare).toBeUndefined();
106
+ const seen = [];
107
+ renderToString( /*#__PURE__*/React.createElement(FontdueContextProvider, {
108
+ locale: " de "
109
+ }, /*#__PURE__*/React.createElement(Probe, {
110
+ seen: seen
111
+ })));
112
+ renderToString( /*#__PURE__*/React.createElement(FontdueContextProvider, {
113
+ locale: ""
114
+ }, /*#__PURE__*/React.createElement(Probe, {
115
+ seen: seen
116
+ })));
117
+ expect(seen.map(s => s.locale)).toEqual(['de', undefined]);
118
+ expect(seen[0].environment).toBe(useCurrentEnvironment({
119
+ locale: 'de'
120
+ }));
121
+ expect(seen[1].environment).toBe(useCurrentEnvironment({}));
122
+ });
123
+ it('a standalone island renders against its own locale', () => {
124
+ const seen = [];
125
+ renderToString( /*#__PURE__*/React.createElement(EnsureFontdueContext, {
126
+ locale: "de"
127
+ }, /*#__PURE__*/React.createElement(Probe, {
128
+ seen: seen
129
+ })));
130
+ expect(seen[0]).toEqual({
131
+ environment: useCurrentEnvironment({
132
+ locale: 'de'
133
+ }),
134
+ locale: 'de'
135
+ });
136
+ });
137
+ it('a component in another language switches environment; one without inherits', () => {
138
+ const seen = [];
139
+ renderToString( /*#__PURE__*/React.createElement(FontdueContextProvider, {
140
+ locale: "en"
141
+ }, /*#__PURE__*/React.createElement(Probe, {
142
+ seen: seen
143
+ }), /*#__PURE__*/React.createElement(EnsureFontdueContext, {
144
+ locale: "de"
145
+ }, /*#__PURE__*/React.createElement(Probe, {
146
+ seen: seen
147
+ })), /*#__PURE__*/React.createElement(EnsureFontdueContext, null, /*#__PURE__*/React.createElement(Probe, {
148
+ seen: seen
149
+ }))));
150
+ const en = useCurrentEnvironment({
151
+ locale: 'en'
152
+ });
153
+ const de = useCurrentEnvironment({
154
+ locale: 'de'
155
+ });
156
+ expect(seen).toEqual([{
157
+ environment: en,
158
+ locale: 'en'
159
+ }, {
160
+ environment: de,
161
+ locale: 'de'
162
+ }, {
163
+ environment: en,
164
+ locale: 'en'
165
+ }]);
166
+ });
167
+ });
168
+ describe('preloaded payloads', () => {
169
+ const params = {
170
+ name: 'LocalePreloadQuery',
171
+ cacheID: 'locale-preload-query',
172
+ text: 'query LocalePreloadQuery { viewer { id } }',
173
+ operationKind: 'query'
174
+ };
175
+ function PreloadProbe(_ref2) {
176
+ let {
177
+ preload
178
+ } = _ref2;
179
+ useSerializablePreloadedQuery(preload);
180
+ return null;
181
+ }
182
+ it("land in the environment for the preload's own locale", () => {
183
+ var _get;
184
+ const preload = {
185
+ params,
186
+ variables: {},
187
+ response: {
188
+ data: {
189
+ viewer: {
190
+ id: 'German'
191
+ }
192
+ }
193
+ },
194
+ locale: 'de'
195
+ };
196
+
197
+ // What a self-wrapping component does with a preload: its locale defaults
198
+ // to the preload's, even under a default-language provider.
199
+ renderToString( /*#__PURE__*/React.createElement(FontdueContextProvider, null, /*#__PURE__*/React.createElement(EnsureFontdueContext, {
200
+ locale: preload.locale
201
+ }, /*#__PURE__*/React.createElement(PreloadProbe, {
202
+ preload: preload
203
+ }))));
204
+ const de = useCurrentEnvironment({
205
+ locale: 'de'
206
+ });
207
+ const none = useCurrentEnvironment({});
208
+ expect((_get = responseCacheFor(de).get(params.cacheID, {})) === null || _get === void 0 ? void 0 : _get.data).toEqual({
209
+ viewer: {
210
+ id: 'German'
211
+ }
212
+ });
213
+ expect(responseCacheFor(none).get(params.cacheID, {})).toBeNull();
214
+ });
215
+ it('warn when rendered under a different locale', () => {
216
+ const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
217
+ const preload = {
218
+ params: {
219
+ ...params,
220
+ cacheID: 'locale-mismatch'
221
+ },
222
+ variables: {},
223
+ response: {
224
+ data: {
225
+ viewer: {
226
+ id: '1'
227
+ }
228
+ }
229
+ },
230
+ locale: 'de'
231
+ };
232
+ renderToString( /*#__PURE__*/React.createElement(FontdueContextProvider, {
233
+ locale: "fr"
234
+ }, /*#__PURE__*/React.createElement(PreloadProbe, {
235
+ preload: preload
236
+ })));
237
+ expect(warn).toHaveBeenCalledWith(expect.stringContaining('preloaded in "de"'));
238
+ });
239
+ });
240
+
241
+ // The browser half of the server test in localeTransport.test.tsx: with a
242
+ // locale configured both sides format the same, whatever the browser's language.
243
+ describe('Price in the browser', () => {
244
+ const twelveEuros = {
245
+ amount: 1200,
246
+ currency: 'EUR'
247
+ };
248
+ const format = locale => new Intl.NumberFormat(locale, {
249
+ style: 'currency',
250
+ currency: 'EUR',
251
+ currencyDisplay: 'symbol',
252
+ minimumFractionDigits: 2
253
+ }).format(12);
254
+ it('uses the configured locale over the browser language', () => {
255
+ Object.defineProperty(window.navigator, 'language', {
256
+ value: 'en-US',
257
+ configurable: true
258
+ });
259
+ const html = renderToString( /*#__PURE__*/React.createElement(FontdueContextProvider, {
260
+ locale: "de"
261
+ }, /*#__PURE__*/React.createElement(Price, {
262
+ price: twelveEuros
263
+ })));
264
+ expect(html).toContain(format('de'));
265
+ });
266
+ it('falls back to the browser language without one', () => {
267
+ Object.defineProperty(window.navigator, 'language', {
268
+ value: 'en-US',
269
+ configurable: true
270
+ });
271
+ expect(renderToString( /*#__PURE__*/React.createElement(Price, {
272
+ price: twelveEuros
273
+ }))).toContain(format('en-US'));
274
+ });
275
+ });