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.
- package/CHANGELOG.md +9 -0
- package/dist/__generated__/CartOrderCompleteOrderMutation.graphql.d.ts +1 -1
- package/dist/__generated__/CartOrderCompleteOrderMutation.graphql.js +3 -3
- package/dist/__generated__/CartOrderRemoveDiscountMutation.graphql.d.ts +1 -1
- package/dist/__generated__/CartOrderRemoveDiscountMutation.graphql.js +3 -3
- package/dist/__generated__/CartOrderUpdateMutation.graphql.d.ts +1 -1
- package/dist/__generated__/CartOrderUpdateMutation.graphql.js +3 -3
- package/dist/__generated__/CartQuery.graphql.d.ts +1 -1
- package/dist/__generated__/CartQuery.graphql.js +3 -3
- package/dist/__generated__/CartStateUpdateMutation.graphql.d.ts +5 -1
- package/dist/__generated__/CartStateUpdateMutation.graphql.js +132 -117
- package/dist/__generated__/CartState_order.graphql.d.ts +4 -1
- package/dist/__generated__/CartState_order.graphql.js +11 -2
- package/dist/__generated__/CheckoutUpdateCustomerMutation.graphql.d.ts +1 -1
- package/dist/__generated__/CheckoutUpdateCustomerMutation.graphql.js +3 -3
- package/dist/__generated__/CheckoutUpdateOrderMutation.graphql.d.ts +1 -1
- package/dist/__generated__/CheckoutUpdateOrderMutation.graphql.js +3 -3
- package/dist/__generated__/FamilyList_node.graphql.d.ts +3 -1
- package/dist/__generated__/FamilyList_node.graphql.js +8 -2
- package/dist/__generated__/FontFamiliesQuery.graphql.d.ts +1 -1
- package/dist/__generated__/FontFamiliesQuery.graphql.js +5 -5
- package/dist/__generated__/PrecartAddToCartMutation.graphql.d.ts +1 -1
- package/dist/__generated__/PrecartAddToCartMutation.graphql.js +3 -3
- package/dist/__generated__/StoreModalCartQuery.graphql.d.ts +1 -1
- package/dist/__generated__/StoreModalCartQuery.graphql.js +69 -69
- package/dist/__generated__/StoreModalFamily_collection.graphql.d.ts +2 -1
- package/dist/__generated__/StoreModalFamily_collection.graphql.js +16 -15
- package/dist/__generated__/StoreModalIndexItem_fontCollection.graphql.d.ts +19 -1
- package/dist/__generated__/StoreModalIndexItem_fontCollection.graphql.js +39 -4
- package/dist/__generated__/StoreModalIndexPaginationQuery.graphql.d.ts +1 -1
- package/dist/__generated__/StoreModalIndexPaginationQuery.graphql.js +40 -5
- package/dist/__generated__/StoreModalIndexQuery.graphql.d.ts +1 -1
- package/dist/__generated__/StoreModalIndexQuery.graphql.js +40 -5
- package/dist/__generated__/StoreModalProductContent_collection.graphql.d.ts +19 -1
- package/dist/__generated__/StoreModalProductContent_collection.graphql.js +46 -11
- package/dist/__generated__/StoreModalProductQuery.graphql.d.ts +1 -1
- package/dist/__generated__/StoreModalProductQuery.graphql.js +198 -167
- package/dist/__generated__/StoreModalProductRefetchQuery.graphql.d.ts +1 -1
- package/dist/__generated__/StoreModalProductRefetchQuery.graphql.js +171 -140
- package/dist/__generated__/StoreModalProductSlugQuery.graphql.d.ts +1 -1
- package/dist/__generated__/StoreModalProductSlugQuery.graphql.js +201 -170
- package/dist/__generated__/StripeProviderCreateCheckoutSessionMutation.graphql.d.ts +5 -2
- package/dist/__generated__/StripeProviderCreateCheckoutSessionMutation.graphql.js +41 -22
- package/dist/__generated__/TestFontsFormUpdateCustomerMutation.graphql.d.ts +1 -1
- package/dist/__generated__/TestFontsFormUpdateCustomerMutation.graphql.js +3 -3
- package/dist/__generated__/TypeTesterStandaloneChangedStylesQuery.graphql.d.ts +1 -1
- package/dist/__generated__/TypeTesterStandaloneChangedStylesQuery.graphql.js +9 -3
- package/dist/__generated__/TypeTesterStandaloneQuery.graphql.d.ts +1 -1
- package/dist/__generated__/TypeTesterStandaloneQuery.graphql.js +9 -3
- package/dist/__generated__/TypeTester_fontStyle.graphql.d.ts +3 -1
- package/dist/__generated__/TypeTester_fontStyle.graphql.js +8 -2
- package/dist/__generated__/TypeTestersChangedStylesQuery.graphql.d.ts +1 -1
- package/dist/__generated__/TypeTestersChangedStylesQuery.graphql.js +9 -3
- package/dist/__generated__/TypeTestersIDQuery.graphql.d.ts +1 -1
- package/dist/__generated__/TypeTestersIDQuery.graphql.js +39 -39
- package/dist/__generated__/TypeTestersRefetchQuery.graphql.d.ts +1 -1
- package/dist/__generated__/TypeTestersRefetchQuery.graphql.js +37 -37
- package/dist/__generated__/TypeTestersSlugQuery.graphql.d.ts +1 -1
- package/dist/__generated__/TypeTestersSlugQuery.graphql.js +39 -39
- package/dist/__tests__/cartDiscountRemoved.test.js +195 -0
- package/dist/__tests__/characterViewerCollapse.test.js +199 -0
- package/dist/__tests__/characterViewerStyleSelect.test.js +52 -0
- package/dist/__tests__/checkoutReturn.test.js +66 -0
- package/dist/__tests__/familyStyleCounts.test.js +71 -0
- package/dist/__tests__/i18n.test.js +171 -0
- package/dist/__tests__/i18nComponents.test.js +408 -0
- package/dist/__tests__/localeEnvironments.test.js +275 -0
- package/dist/__tests__/localeMiddleware.test.js +68 -0
- package/dist/__tests__/localeTransport.test.js +209 -0
- package/dist/__tests__/recaptchaLocale.test.js +62 -0
- package/dist/__tests__/serverEntryLocale.test.js +124 -0
- package/dist/__tests__/storeModalIndexUnlisted.test.js +69 -11
- package/dist/__tests__/useSerializablePreloadedQuery.test.js +4 -3
- package/dist/components/AddToCartBanner/index.js +8 -2
- package/dist/components/BuyButton/index.d.ts +1 -0
- package/dist/components/BuyButton/index.js +8 -2
- package/dist/components/BuyButton/index.server.d.ts +1 -0
- package/dist/components/BuyButton/index.server.js +8 -0
- package/dist/components/BuyingOptions/index.js +3 -1
- package/dist/components/Cart/AddressFields.js +5 -3
- package/dist/components/Cart/CartCouponNotice.d.ts +7 -0
- package/dist/components/Cart/CartCouponNotice.js +21 -0
- package/dist/components/Cart/CartItem/CartItemAdditionalLicenses.js +3 -1
- package/dist/components/Cart/CartItem/CartItemLicense.js +3 -1
- package/dist/components/Cart/CartItem/CartItemProduct.js +6 -3
- package/dist/components/Cart/CartItem/VariableTextInput.js +7 -3
- package/dist/components/Cart/CartItem/index.js +5 -1
- package/dist/components/Cart/CartOrder.js +27 -17
- package/dist/components/Cart/CartState.d.ts +1 -0
- package/dist/components/Cart/CartState.js +18 -3
- package/dist/components/Cart/CartTotals.js +17 -9
- package/dist/components/Cart/Checkout.js +18 -15
- package/dist/components/Cart/CouponCodeInput.js +5 -3
- package/dist/components/Cart/CustomerFields.js +6 -4
- package/dist/components/Cart/EmptyCart.js +4 -2
- package/dist/components/Cart/IdentityBox.js +6 -2
- package/dist/components/Cart/ShareCart.js +8 -6
- package/dist/components/Cart/checkoutReturn.d.ts +17 -0
- package/dist/components/Cart/checkoutReturn.js +38 -0
- package/dist/components/CartButton/index.d.ts +2 -1
- package/dist/components/CartButton/index.js +6 -2
- package/dist/components/CharacterViewer/StyleSelect.js +6 -2
- package/dist/components/CharacterViewer/collapse.d.ts +10 -0
- package/dist/components/CharacterViewer/collapse.js +39 -0
- package/dist/components/CharacterViewer/index.d.ts +4 -0
- package/dist/components/CharacterViewer/index.js +78 -24
- package/dist/components/CharacterViewer/index.server.d.ts +1 -0
- package/dist/components/CharacterViewer/index.server.js +4 -0
- package/dist/components/ConfigContext.d.ts +14 -10
- package/dist/components/ConfigContext.js +12 -7
- package/dist/components/ConsentBanner/index.js +6 -5
- package/dist/components/CookieNotification/index.js +11 -5
- package/dist/components/CouponText/index.js +15 -7
- package/dist/components/CustomerLoginForm/index.js +14 -9
- package/dist/components/CustomerSignIn/CustomerSignInElement.d.ts +1 -1
- package/dist/components/CustomerSignIn/CustomerSignInElement.js +8 -2
- package/dist/components/CustomerSignIn/index.d.ts +6 -1
- package/dist/components/CustomerSignIn/index.js +27 -15
- package/dist/components/Family/FamilyList.js +5 -2
- package/dist/components/Family/index.js +21 -12
- package/dist/components/FeatureTester/FeatureTesters.d.ts +2 -1
- package/dist/components/FeatureTester/FeatureTesters.js +4 -1
- package/dist/components/FeatureTester/FeatureTesters.server.js +4 -0
- package/dist/components/FeatureTester/index.d.ts +1 -0
- package/dist/components/FeatureTester/index.js +3 -1
- package/dist/components/FeatureTester/index.server.js +2 -0
- package/dist/components/FontdueContextProvider/index.d.ts +12 -2
- package/dist/components/FontdueContextProvider/index.js +85 -11
- package/dist/components/FontdueProvider/index.js +7 -1
- package/dist/components/FontdueProvider/index.server.js +21 -3
- package/dist/components/LocaleContext.d.ts +9 -0
- package/dist/components/LocaleContext.js +20 -0
- package/dist/components/NewsletterSignup/index.d.ts +2 -1
- package/dist/components/NewsletterSignup/index.js +20 -11
- package/dist/components/NewsletterSignup/index.server.d.ts +1 -0
- package/dist/components/NewsletterSignup/index.server.js +3 -1
- package/dist/components/NodePasswordForm/index.d.ts +6 -1
- package/dist/components/NodePasswordForm/index.js +14 -6
- package/dist/components/OrderVariableSelection/index.js +7 -5
- package/dist/components/Precart/License.js +4 -2
- package/dist/components/Precart/index.js +15 -12
- package/dist/components/Price/index.d.ts +1 -0
- package/dist/components/Price/index.js +15 -5
- package/dist/components/Root/index.js +2 -1
- package/dist/components/Select/index.d.ts +1 -1
- package/dist/components/Select/index.js +4 -1
- package/dist/components/SelectButton/index.js +3 -1
- package/dist/components/SpecimenLink/index.js +3 -1
- package/dist/components/StoreModal/StoreModalCart.js +6 -0
- package/dist/components/StoreModal/StoreModalContainer.js +14 -12
- package/dist/components/StoreModal/StoreModalDownload.js +3 -1
- package/dist/components/StoreModal/StoreModalFamily.js +16 -7
- package/dist/components/StoreModal/StoreModalFamilyButton.js +14 -9
- package/dist/components/StoreModal/StoreModalIndexItem.js +21 -10
- package/dist/components/StoreModal/StoreModalIndexPackItem.js +8 -3
- package/dist/components/StoreModal/StoreModalPackButton.js +5 -2
- package/dist/components/StoreModal/StoreModalProduct.js +14 -5
- package/dist/components/StoreModal/index.d.ts +1 -0
- package/dist/components/StoreModal/index.js +4 -2
- package/dist/components/StoreModal/offered.d.ts +31 -0
- package/dist/components/StoreModal/offered.js +21 -0
- package/dist/components/StoreModal/types.d.ts +9 -0
- package/dist/components/StoreModalProductLicenseSelection/LicenseVariableElement.js +3 -1
- package/dist/components/StoreModalProductLicenseSelection/StoreModalProductLicense.js +5 -1
- package/dist/components/StoreModalProductSummary/index.js +37 -23
- package/dist/components/StripeProvider/index.js +18 -5
- package/dist/components/TestFontsForm/index.d.ts +2 -1
- package/dist/components/TestFontsForm/index.js +28 -16
- package/dist/components/TestFontsForm/index.server.d.ts +1 -0
- package/dist/components/TestFontsForm/index.server.js +3 -1
- package/dist/components/TestModeBanner/index.js +3 -1
- package/dist/components/TypeTester/TypeTesterEditAll.js +3 -1
- package/dist/components/TypeTester/TypeTesterFeaturesButton.js +4 -2
- package/dist/components/TypeTester/TypeTesterStandalone.d.ts +1 -0
- package/dist/components/TypeTester/TypeTesterStandalone.js +6 -2
- package/dist/components/TypeTester/TypeTesterStandalone.server.js +2 -0
- package/dist/components/TypeTester/TypeTesterStyleSelect.js +5 -3
- package/dist/components/TypeTester/TypeTesterStyleSelectData.js +3 -1
- package/dist/components/TypeTester/TypeTesterToolbar.js +12 -6
- package/dist/components/TypeTester/index.js +7 -2
- package/dist/components/TypeTesters/index.d.ts +2 -1
- package/dist/components/TypeTesters/index.js +3 -1
- package/dist/components/TypeTesters/index.server.d.ts +1 -0
- package/dist/components/TypeTesters/index.server.js +4 -0
- package/dist/components/elements/EmptyCart/index.js +4 -2
- package/dist/components/elements/StoreModalCartLayout/index.d.ts +1 -0
- package/dist/components/elements/StoreModalCartLayout/index.js +2 -1
- package/dist/components/elements/StoreModalContainer/index.js +4 -2
- package/dist/components/elements/StoreModalDownloadLayout/index.js +3 -1
- package/dist/components/elements/StoreModalIndexItem/index.js +3 -1
- package/dist/components/elements/StoreModalIndexLoadMore/index.js +3 -1
- package/dist/components/elements/StoreModalLicenseeIsBillingIdentityElement.js +4 -2
- package/dist/components/elements/StoreModalLoadingScreen/index.js +7 -3
- package/dist/components/elements/StoreModalUnifiedCheckout.js +44 -27
- package/dist/fontdue.css +58 -0
- package/dist/hooks/useRecaptchaTimeout.d.ts +1 -1
- package/dist/hooks/useRecaptchaTimeout.js +4 -2
- package/dist/i18n/de.d.ts +3 -0
- package/dist/i18n/de.js +279 -0
- package/dist/i18n/en.d.ts +212 -0
- package/dist/i18n/en.js +261 -0
- package/dist/i18n/index.d.ts +42 -0
- package/dist/i18n/index.js +115 -0
- package/dist/i18n/types.d.ts +28 -0
- package/dist/i18n/types.js +1 -0
- package/dist/i18n/useT.d.ts +15 -0
- package/dist/i18n/useT.js +21 -0
- package/dist/locale.d.ts +20 -0
- package/dist/locale.js +52 -0
- package/dist/next/tenant.d.ts +3 -1
- package/dist/next/tenant.js +11 -2
- package/dist/relay/environment.d.ts +8 -2
- package/dist/relay/environment.js +65 -15
- package/dist/relay/loadSerializableQuery.d.ts +17 -0
- package/dist/relay/loadSerializableQuery.js +14 -2
- package/dist/relay/serverConfig.d.ts +9 -0
- package/dist/relay/serverConfig.js +16 -0
- package/dist/relay/useSerializablePreloadedQuery.js +27 -6
- package/dist/server/index.d.ts +11 -0
- package/dist/server/index.js +7 -0
- package/dist/server/middleware.d.ts +19 -1
- package/dist/server/middleware.js +56 -13
- package/dist/utils.d.ts +0 -1
- package/dist/utils.js +0 -5
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
|
|
3
|
+
// Unlisted only means a style can't be bought on its own. It is still part of
|
|
4
|
+
// the family, so the glyph viewer keeps it in its menu (FD-1273).
|
|
5
|
+
|
|
6
|
+
import React from 'react';
|
|
7
|
+
import { renderToStaticMarkup } from 'react-dom/server';
|
|
8
|
+
import { describe, expect, it } from 'vitest';
|
|
9
|
+
import StyleSelect from '../components/CharacterViewer/StyleSelect.js';
|
|
10
|
+
const options = function (fontStyles) {
|
|
11
|
+
let isVariableFont = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
12
|
+
const html = renderToStaticMarkup( /*#__PURE__*/React.createElement(StyleSelect, {
|
|
13
|
+
collections: [{
|
|
14
|
+
name: 'Sans',
|
|
15
|
+
isVariableFont,
|
|
16
|
+
fontStyles
|
|
17
|
+
}],
|
|
18
|
+
value: {
|
|
19
|
+
fontStyleId: 'style:1',
|
|
20
|
+
variableSettings: null
|
|
21
|
+
},
|
|
22
|
+
onChange: () => {}
|
|
23
|
+
}));
|
|
24
|
+
return [...html.matchAll(/<option[^>]*>([^<]*)</g)].map(match => match[1]);
|
|
25
|
+
};
|
|
26
|
+
describe('CharacterViewer StyleSelect', () => {
|
|
27
|
+
it('lists an unlisted style with the rest of its family', () => {
|
|
28
|
+
const styles = [{
|
|
29
|
+
id: 'style:1',
|
|
30
|
+
name: 'Regular',
|
|
31
|
+
visibility: 'VISIBLE'
|
|
32
|
+
}, {
|
|
33
|
+
id: 'style:2',
|
|
34
|
+
name: 'Thin',
|
|
35
|
+
visibility: 'UNLISTED'
|
|
36
|
+
}];
|
|
37
|
+
expect(options(styles)).toEqual(['Sans Regular', 'Sans Thin']);
|
|
38
|
+
});
|
|
39
|
+
it('lists the named instances of an unlisted variable style', () => {
|
|
40
|
+
const styles = [{
|
|
41
|
+
id: 'style:1',
|
|
42
|
+
name: 'Variable',
|
|
43
|
+
visibility: 'UNLISTED',
|
|
44
|
+
variableInstances: [{
|
|
45
|
+
name: 'Light'
|
|
46
|
+
}, {
|
|
47
|
+
name: 'Bold'
|
|
48
|
+
}]
|
|
49
|
+
}];
|
|
50
|
+
expect(options(styles, true)).toEqual(['Sans Light', 'Sans Bold']);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// `storeModal.returnUrl` as checkout hands it to the order page that payment
|
|
2
|
+
// returns to, for that page's link back.
|
|
3
|
+
|
|
4
|
+
import { describe, expect, it } from 'vitest';
|
|
5
|
+
import { checkoutReturnParams, withCheckoutReturn } from '../components/Cart/checkoutReturn.js';
|
|
6
|
+
const page = 'https://ornaments.example.com/draw?tool=box';
|
|
7
|
+
const completeUrl = 'https://store.example.com/orders/1';
|
|
8
|
+
describe('checkoutReturnParams', () => {
|
|
9
|
+
it('is null when the site sets no return URL', () => {
|
|
10
|
+
expect(checkoutReturnParams(undefined, page)).toEqual({
|
|
11
|
+
returnUrl: null,
|
|
12
|
+
returnLabel: null
|
|
13
|
+
});
|
|
14
|
+
expect(checkoutReturnParams({
|
|
15
|
+
returnLabel: 'Back'
|
|
16
|
+
}, page)).toEqual({
|
|
17
|
+
returnUrl: null,
|
|
18
|
+
returnLabel: null
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
it('keeps an absolute URL as given, with its label', () => {
|
|
22
|
+
expect(checkoutReturnParams({
|
|
23
|
+
returnUrl: 'https://ornaments.example.com/',
|
|
24
|
+
returnLabel: 'Back to Ornaments'
|
|
25
|
+
}, page)).toEqual({
|
|
26
|
+
returnUrl: 'https://ornaments.example.com/',
|
|
27
|
+
returnLabel: 'Back to Ornaments'
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
it('resolves a relative URL against the page the store modal is on', () => {
|
|
31
|
+
expect(checkoutReturnParams({
|
|
32
|
+
returnUrl: '/'
|
|
33
|
+
}, page)).toEqual({
|
|
34
|
+
returnUrl: 'https://ornaments.example.com/',
|
|
35
|
+
returnLabel: null
|
|
36
|
+
});
|
|
37
|
+
expect(checkoutReturnParams({
|
|
38
|
+
returnUrl: '?from=checkout'
|
|
39
|
+
}, page).returnUrl).toBe('https://ornaments.example.com/draw?from=checkout');
|
|
40
|
+
});
|
|
41
|
+
it('is null rather than throwing for a value that is no URL', () => {
|
|
42
|
+
expect(checkoutReturnParams({
|
|
43
|
+
returnUrl: 'http://[bad'
|
|
44
|
+
}, page).returnUrl).toBeNull();
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
describe('withCheckoutReturn', () => {
|
|
48
|
+
it('leaves the order page URL alone when the site sets no return URL', () => {
|
|
49
|
+
expect(withCheckoutReturn(completeUrl, undefined, page)).toBe(completeUrl);
|
|
50
|
+
});
|
|
51
|
+
it('carries the return URL and label as query parameters', () => {
|
|
52
|
+
const url = new URL(withCheckoutReturn(completeUrl, {
|
|
53
|
+
returnUrl: '/?purchased=1',
|
|
54
|
+
returnLabel: 'Back to Ornaments'
|
|
55
|
+
}, page));
|
|
56
|
+
expect(url.origin + url.pathname).toBe(completeUrl);
|
|
57
|
+
expect(url.searchParams.get('return_url')).toBe('https://ornaments.example.com/?purchased=1');
|
|
58
|
+
expect(url.searchParams.get('return_label')).toBe('Back to Ornaments');
|
|
59
|
+
});
|
|
60
|
+
it('omits the label when the site sets none', () => {
|
|
61
|
+
const url = new URL(withCheckoutReturn(completeUrl, {
|
|
62
|
+
returnUrl: '/'
|
|
63
|
+
}, page));
|
|
64
|
+
expect(url.searchParams.has('return_label')).toBe(false);
|
|
65
|
+
});
|
|
66
|
+
});
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
|
|
3
|
+
// A family's counts describe the family, so an unlisted style stays in them
|
|
4
|
+
// even though it has no row of its own (FD-1273).
|
|
5
|
+
|
|
6
|
+
import React from 'react';
|
|
7
|
+
import { renderToStaticMarkup } from 'react-dom/server';
|
|
8
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
9
|
+
|
|
10
|
+
// The fragment reader hands back the data it was given.
|
|
11
|
+
vi.mock('react-relay', () => ({
|
|
12
|
+
graphql: () => null,
|
|
13
|
+
useFragment: (_fragment, key) => key
|
|
14
|
+
}));
|
|
15
|
+
vi.mock('react-redux', () => ({
|
|
16
|
+
useSelector: () => false
|
|
17
|
+
}));
|
|
18
|
+
vi.mock('../components/SelectButton/index.js', () => ({
|
|
19
|
+
default: () => null
|
|
20
|
+
}));
|
|
21
|
+
vi.mock('../components/SKUPrice/index.js', () => ({
|
|
22
|
+
default: () => null
|
|
23
|
+
}));
|
|
24
|
+
vi.mock('../components/Family/FamilyList.js', () => ({
|
|
25
|
+
default: () => null
|
|
26
|
+
}));
|
|
27
|
+
import Family from '../components/Family/index.js';
|
|
28
|
+
const variableStyle = visibility => ({
|
|
29
|
+
visibility,
|
|
30
|
+
variableAxes: [{
|
|
31
|
+
name: 'wght'
|
|
32
|
+
}, {
|
|
33
|
+
name: 'wdth'
|
|
34
|
+
}],
|
|
35
|
+
variableInstances: [{
|
|
36
|
+
name: 'Light'
|
|
37
|
+
}, {
|
|
38
|
+
name: 'Bold'
|
|
39
|
+
}, {
|
|
40
|
+
name: 'Black'
|
|
41
|
+
}]
|
|
42
|
+
});
|
|
43
|
+
const family = function (fontStyles) {
|
|
44
|
+
let overrides = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
45
|
+
return {
|
|
46
|
+
sku: null,
|
|
47
|
+
name: 'Sans',
|
|
48
|
+
collectionType: 'family',
|
|
49
|
+
totalStyles: fontStyles.length,
|
|
50
|
+
isVariableFont: true,
|
|
51
|
+
fontStyles,
|
|
52
|
+
families: [],
|
|
53
|
+
...overrides
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
const counts = node => {
|
|
57
|
+
const html = renderToStaticMarkup( /*#__PURE__*/React.createElement(Family, {
|
|
58
|
+
node: node
|
|
59
|
+
}));
|
|
60
|
+
return [...html.matchAll(/font-family-block__count">([^<]*)</g)].map(match => match[1]);
|
|
61
|
+
};
|
|
62
|
+
describe('Family counts', () => {
|
|
63
|
+
it('counts an unlisted variable style in its axes and named instances', () => {
|
|
64
|
+
const node = family([variableStyle('VISIBLE'), variableStyle('UNLISTED')]);
|
|
65
|
+
expect(counts(node)).toEqual(['2 fonts', '4\xa0variable axes', '6 named instances']);
|
|
66
|
+
});
|
|
67
|
+
it('keeps its counts when every style is unlisted', () => {
|
|
68
|
+
const node = family([variableStyle('UNLISTED')]);
|
|
69
|
+
expect(counts(node)).toEqual(['1 font', '2\xa0variable axes', '3 named instances']);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
// The UI string catalogues (src/i18n): every language has exactly the English
|
|
2
|
+
// keys in the same shapes, a locale resolves to the closest catalogue, and
|
|
3
|
+
// `t()` interpolates and picks plural forms with Intl.PluralRules.
|
|
4
|
+
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import { renderToStaticMarkup } from 'react-dom/server';
|
|
7
|
+
import { describe, expect, it } from 'vitest';
|
|
8
|
+
import en from '../i18n/en.js';
|
|
9
|
+
import de from '../i18n/de.js';
|
|
10
|
+
import { resolveLanguage, SUPPORTED_LANGUAGES, translate, translatorFor } from '../i18n/index.js';
|
|
11
|
+
const shape = message => typeof message === 'string' ? 'string' : Object.keys(message).sort().join(',');
|
|
12
|
+
const placeholders = message => {
|
|
13
|
+
const texts = typeof message === 'string' ? [message] : Object.values(message);
|
|
14
|
+
return [...new Set(texts.flatMap(text => String(text).match(/\{\w+\}/g) ?? []))].sort();
|
|
15
|
+
};
|
|
16
|
+
describe('catalogues', () => {
|
|
17
|
+
it('ships English and German', () => {
|
|
18
|
+
expect(SUPPORTED_LANGUAGES).toEqual(['en', 'de']);
|
|
19
|
+
});
|
|
20
|
+
it('German has exactly the English keys (the Catalogue type enforces this too)', () => {
|
|
21
|
+
expect(Object.keys(de).sort()).toEqual(Object.keys(en).sort());
|
|
22
|
+
});
|
|
23
|
+
it('each German message has the English shape', () => {
|
|
24
|
+
for (const key of Object.keys(en)) {
|
|
25
|
+
expect(typeof de[key], key).toBe(typeof en[key]);
|
|
26
|
+
if (typeof en[key] !== 'string') {
|
|
27
|
+
expect(de[key].other, key).toBeTruthy();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
it('each German message keeps the English placeholders, except where documented', () => {
|
|
32
|
+
// German capitalises nouns, so it shows the variable's name as entered
|
|
33
|
+
// rather than the lowercased one English needs mid-sentence.
|
|
34
|
+
const exceptions = {
|
|
35
|
+
'productSummary.selectVariable': ['{name}']
|
|
36
|
+
};
|
|
37
|
+
for (const key of Object.keys(en)) {
|
|
38
|
+
expect(placeholders(de[key]), key).toEqual(exceptions[key] ?? placeholders(en[key]));
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
it('has no empty messages', () => {
|
|
42
|
+
for (const catalogue of [en, de]) {
|
|
43
|
+
for (const [key, message] of Object.entries(catalogue)) {
|
|
44
|
+
expect(shape(message), key).not.toBe('');
|
|
45
|
+
const texts = typeof message === 'string' ? [message] : Object.values(message);
|
|
46
|
+
for (const text of texts) expect(String(text).trim(), key).not.toBe('');
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
it('German uses no straight quotes or em dashes (house style)', () => {
|
|
51
|
+
for (const [key, message] of Object.entries(de)) {
|
|
52
|
+
const texts = typeof message === 'string' ? [message] : Object.values(message);
|
|
53
|
+
for (const text of texts) {
|
|
54
|
+
expect(String(text), key).not.toMatch(/["'—]/);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
describe('resolveLanguage', () => {
|
|
60
|
+
it('is English when no locale is set', () => {
|
|
61
|
+
expect(resolveLanguage(undefined)).toBe('en');
|
|
62
|
+
expect(resolveLanguage(null)).toBe('en');
|
|
63
|
+
expect(resolveLanguage('')).toBe('en');
|
|
64
|
+
expect(resolveLanguage(' ')).toBe('en');
|
|
65
|
+
});
|
|
66
|
+
it('falls back from a region to its language', () => {
|
|
67
|
+
expect(resolveLanguage('de')).toBe('de');
|
|
68
|
+
expect(resolveLanguage('de-AT')).toBe('de');
|
|
69
|
+
expect(resolveLanguage('de_CH')).toBe('de');
|
|
70
|
+
expect(resolveLanguage('DE-de')).toBe('de');
|
|
71
|
+
});
|
|
72
|
+
it('falls back to English for a language without a catalogue', () => {
|
|
73
|
+
expect(resolveLanguage('fr')).toBe('en');
|
|
74
|
+
expect(resolveLanguage('pt-BR')).toBe('en');
|
|
75
|
+
expect(resolveLanguage('en-GB')).toBe('en');
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
describe('translate', () => {
|
|
79
|
+
it('returns the English message with no locale', () => {
|
|
80
|
+
expect(translate(undefined, 'productSummary.addToCart')).toBe('Add to cart');
|
|
81
|
+
expect(translate('fr', 'productSummary.addToCart')).toBe('Add to cart');
|
|
82
|
+
});
|
|
83
|
+
it('returns the German message for de and its regions', () => {
|
|
84
|
+
expect(translate('de', 'productSummary.addToCart')).toBe('In den Warenkorb');
|
|
85
|
+
expect(translate('de-AT', 'storeModal.cart')).toBe('Warenkorb');
|
|
86
|
+
});
|
|
87
|
+
it('interpolates named parameters', () => {
|
|
88
|
+
expect(translate(undefined, 'buyButton.label', {
|
|
89
|
+
name: 'Helvetica'
|
|
90
|
+
})).toBe('Buy Helvetica');
|
|
91
|
+
expect(translate('de', 'buyButton.label', {
|
|
92
|
+
name: 'Helvetica'
|
|
93
|
+
})).toBe('Helvetica kaufen');
|
|
94
|
+
expect(translate(undefined, 'signIn.signedInAs', {
|
|
95
|
+
name: 'a@example.com'
|
|
96
|
+
})).toBe('Signed in as a@example.com.');
|
|
97
|
+
});
|
|
98
|
+
it('leaves an unknown placeholder alone and never re-reads a parameter', () => {
|
|
99
|
+
expect(translate(undefined, 'buyButton.label')).toBe('Buy {name}');
|
|
100
|
+
expect(translate(undefined, 'buyButton.label', {
|
|
101
|
+
name: '{name} $& $1'
|
|
102
|
+
})).toBe('Buy {name} $& $1');
|
|
103
|
+
});
|
|
104
|
+
it('picks English plural forms', () => {
|
|
105
|
+
expect(translate(undefined, 'common.styleCount', {
|
|
106
|
+
count: 0
|
|
107
|
+
})).toBe('0 styles');
|
|
108
|
+
expect(translate(undefined, 'common.styleCount', {
|
|
109
|
+
count: 1
|
|
110
|
+
})).toBe('1 style');
|
|
111
|
+
expect(translate(undefined, 'common.styleCount', {
|
|
112
|
+
count: 2
|
|
113
|
+
})).toBe('2 styles');
|
|
114
|
+
expect(translate(undefined, 'common.variableFontCount', {
|
|
115
|
+
count: 12
|
|
116
|
+
})).toBe('12 variable fonts');
|
|
117
|
+
});
|
|
118
|
+
it('picks German plural forms', () => {
|
|
119
|
+
expect(translate('de', 'common.styleCount', {
|
|
120
|
+
count: 0
|
|
121
|
+
})).toBe('0 Schnitte');
|
|
122
|
+
expect(translate('de', 'common.styleCount', {
|
|
123
|
+
count: 1
|
|
124
|
+
})).toBe('1 Schnitt');
|
|
125
|
+
expect(translate('de', 'common.styleCount', {
|
|
126
|
+
count: 5
|
|
127
|
+
})).toBe('5 Schnitte');
|
|
128
|
+
expect(translate('de', 'family.namedInstanceCount', {
|
|
129
|
+
count: 1
|
|
130
|
+
})).toBe('1 benannte Instanz');
|
|
131
|
+
});
|
|
132
|
+
it('keeps the strings pluralize() used to build, byte for byte', () => {
|
|
133
|
+
// pluralize(n, 'variable axis', 'variable axes') joined the plural with a
|
|
134
|
+
// no-break space and the singular with a plain one.
|
|
135
|
+
expect(translate(undefined, 'family.variableAxisCount', {
|
|
136
|
+
count: 1
|
|
137
|
+
})).toBe('1 variable axis');
|
|
138
|
+
expect(translate(undefined, 'family.variableAxisCount', {
|
|
139
|
+
count: 3
|
|
140
|
+
})).toBe('3 variable axes');
|
|
141
|
+
expect(translate(undefined, 'common.fontCount', {
|
|
142
|
+
count: 1
|
|
143
|
+
})).toBe('1 font');
|
|
144
|
+
expect(translate(undefined, 'common.fontCount', {
|
|
145
|
+
count: 4
|
|
146
|
+
})).toBe('4 fonts');
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
describe('translatorFor', () => {
|
|
150
|
+
it('is the same function for the same locale', () => {
|
|
151
|
+
expect(translatorFor('de')).toBe(translatorFor('de'));
|
|
152
|
+
expect(translatorFor(undefined)).toBe(translatorFor(undefined));
|
|
153
|
+
expect(translatorFor('de')).not.toBe(translatorFor(undefined));
|
|
154
|
+
});
|
|
155
|
+
it('knows its language and locale', () => {
|
|
156
|
+
expect(translatorFor('de-AT').language).toBe('de');
|
|
157
|
+
expect(translatorFor('de-AT').locale).toBe('de-AT');
|
|
158
|
+
expect(translatorFor(undefined).language).toBe('en');
|
|
159
|
+
expect(translatorFor(undefined).locale).toBeUndefined();
|
|
160
|
+
});
|
|
161
|
+
it('rich() puts React nodes where the language puts the placeholder', () => {
|
|
162
|
+
const link = /*#__PURE__*/React.createElement('a', {
|
|
163
|
+
href: '/x'
|
|
164
|
+
}, 'here');
|
|
165
|
+
const render = locale => renderToStaticMarkup( /*#__PURE__*/React.createElement('p', null, translatorFor(locale).rich('testFonts.downloadFallback', {
|
|
166
|
+
link
|
|
167
|
+
})));
|
|
168
|
+
expect(render(undefined)).toBe('<p>If it didn’t start, click <a href="/x">here</a>.</p>');
|
|
169
|
+
expect(render('de')).toBe('<p>Falls nicht, klicken Sie <a href="/x">here</a>.</p>');
|
|
170
|
+
});
|
|
171
|
+
});
|