fontdue-js 3.15.0 → 3.16.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/AGENTS.md +29 -0
- package/CHANGELOG.md +10 -0
- package/dist/__generated__/FreeDownloadFormMutation.graphql.d.ts +43 -0
- package/dist/__generated__/FreeDownloadFormMutation.graphql.js +98 -0
- package/dist/__generated__/FreeDownloadForm_Query.graphql.d.ts +46 -0
- package/dist/__generated__/FreeDownloadForm_Query.graphql.js +186 -0
- package/dist/__tests__/freeDownloadForm.test.js +222 -0
- package/dist/__tests__/i18nComponents.test.js +1 -1
- package/dist/__tests__/trackEvents.test.js +131 -0
- package/dist/__tests__/trackingPageViews.test.js +339 -0
- package/dist/__tests__/trackingRouteChanges.test.js +48 -2
- package/dist/components/FreeDownloadForm/FreeDownloadFormElement.d.ts +10 -0
- package/dist/components/FreeDownloadForm/FreeDownloadFormElement.js +17 -0
- package/dist/components/FreeDownloadForm/index.d.ts +21 -0
- package/dist/components/FreeDownloadForm/index.js +283 -0
- package/dist/components/FreeDownloadForm/index.server.d.ts +9 -0
- package/dist/components/FreeDownloadForm/index.server.js +22 -0
- package/dist/components/FreeDownloadForm/variables.d.ts +8 -0
- package/dist/components/FreeDownloadForm/variables.js +18 -0
- package/dist/components/Root/index.js +1 -0
- package/dist/components/Tracking/index.js +52 -34
- package/dist/components/Tracking/pageViews.d.ts +26 -0
- package/dist/components/Tracking/pageViews.js +94 -0
- package/dist/components/Tracking/routeChanges.d.ts +9 -1
- package/dist/components/Tracking/routeChanges.js +33 -9
- package/dist/components/Tracking/sendTrackEvent.d.ts +28 -0
- package/dist/components/Tracking/sendTrackEvent.js +68 -0
- package/dist/components/track.d.ts +21 -0
- package/dist/components/track.js +31 -0
- package/dist/fontdue.css +32 -0
- package/dist/i18n/de.js +17 -5
- package/dist/i18n/en.d.ts +11 -0
- package/dist/i18n/en.js +12 -0
- package/dist/version.js +1 -1
- package/package.json +6 -1
package/AGENTS.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Fontdue.js notes
|
|
2
|
+
|
|
3
|
+
Scoped guidance for `fontdue-js/` (the npm package) and `assets/fontdue/` (the CDN bundle). Read the root `AGENTS.md` first.
|
|
4
|
+
|
|
5
|
+
## 🌐 Fontdue.js (Client Library)
|
|
6
|
+
|
|
7
|
+
- **Purpose**: the JavaScript library tenant websites include to load Fontdue components (store modal, type testers, buy buttons…).
|
|
8
|
+
- **Two integration paths**:
|
|
9
|
+
- **Script tag (CDN)**: `assets/fontdue/index.tsx` is the entry point, bundled by Vite and served at `js.fontdue.com/fontdue.js` (and `fontdue.esm.js`). Tenants call `fontdue.initialize({ url: "...", config: {...} })`, which loads React and the `Root` component from `fontdue-js/src/components/Root` and renders `<fontdue-*>` web components.
|
|
10
|
+
- **npm package (React/Next.js)**: tenants install `fontdue-js` and wrap their app with `<FontdueProvider url="...">`. All GraphQL goes through the Relay environment in `fontdue-js/src/relay/environment.ts`.
|
|
11
|
+
- **🕐 One source, two release clocks – a `fontdue-js/src` change does NOT reach everyone at once.** The CDN entry imports `fontdue-js/src` *directly* (not the published package), so an edit there ships to **script-tag sites on the next app deploy**, with no npm publish involved, while **npm sites get it only after `npm publish` *and* the foundry upgrading**. So a backend feature needing a client change is already live for the script-tag estate the day it deploys and pending indefinitely for the rest – they are not "unreleased" together. Two consequences:
|
|
12
|
+
- Never describe such a feature as unconditionally available in the docs or *What's new*; name the npm version the npm path needs – but only once it has one. Until the feature is published, say the npm path needs an upgrade without naming a version, and let the `/release` skill fill the number in when it stamps the gate.
|
|
13
|
+
- It is exactly the case `Fontage.ClientVersions` `@features` + `<.client_upgrade_alert>` exist for (see *Client version telemetry*) – add the entry when you add the feature, not later, and write `:unreleased` rather than guessing a version.
|
|
14
|
+
|
|
15
|
+
For a rough sense of the split, `priv/pages/07-showcase.md` tags each foundry's integration (`tech_slug`): ~66 `html` (script tag) against ~30 `react`/`template` (npm). It's a curated marketing list rather than the customer table, so treat it as indicative only.
|
|
16
|
+
- **📝 Release notes belong to the `/release` skill – never write them in a feature PR.** That covers both `fontdue-js/CHANGELOG.md` (the skill adds the new version's section when it publishes to npm) and *What's new* (`priv/docs/guide/06-changelog/01-whats-new.md`, which it updates before each app release is cut). It writes them from each commit's diff and its Linear issue (for fontdue-js, everything since npm's `latest`), so a merged change gets picked up without a hand-written entry. A bullet added by hand ends up under whatever version heading is at the top of the file when the PR merges, and that version is usually already on npm: #1352's fix landed under 3.6.0, which had been published four hours earlier. Put user-facing wording in the Linear issue or PR description instead.
|
|
17
|
+
- **`fontdue-js/`** is the npm package source (Babel + Relay compiler; components, Relay operations, Redux state, hooks, utilities). **The source lives on npm only** – never link a GitHub URL for fontdue-js source or its changelog in docs, customer emails or Linear. `dist/` is gitignored and never pruned: `npm run build` only writes, so a *renamed* module leaves its old artifact resolvable and an un-updated import keeps compiling against stale code – if a published build behaves like pre-change code, diff `dist/` against `src/` before believing the source.
|
|
18
|
+
- **Tests**: `npm --prefix fontdue-js run test -- <filter>` (vitest; `npm --prefix … exec vitest` does not change cwd and resolves the wrong React). Mounted component tests use the checkout harness in `fontdue-js/src/__tests__/checkout/testUtils/` (mock Relay environment, Stripe and reCAPTCHA stubs). CI doesn't run this suite – run it yourself.
|
|
19
|
+
- **New `fontdue-*` request headers need the backend CORS allowlist** (`CORSPlug` in `lib/fontage_web/router.ex`, `:schema` and `:admin_schema` pipelines). The list is static, so an unlisted header fails every cross-origin browser fetch with "Request header field X is not allowed" while server-side and curl requests sail through – drive a real cross-origin browser to verify.
|
|
20
|
+
- **Tracking**: optionally sends events to `/api/track` and `/api/track/page`. Disabled by default; `tracking: { enabled: true }` opts in. The backend forwards to the tenant's destinations (see `../lib/fontage/analytics/AGENTS.md`).
|
|
21
|
+
- **Client version telemetry**: every fontdue-js GraphQL request sends `fontdue-client-version` (`fontdue-js/src/version.ts`). `FontageWeb.Plugs.RecordClientVersion` puts it on the request span (`fontdue.client.version`) and `Fontage.ClientVersions.record/2` keeps a per-tenant `client_versions` row. **When a backend change needs a newer fontdue-js** (a field the components read, a new widget), add the feature to `Fontage.ClientVersions` `@features` and put `<.client_upgrade_alert feature={:name} …>` (`FontageWeb.Admin.ClientVersionComponents`) on the admin page where it's configured; the site-admin page `/admin/client-versions` on the www host shows who still needs to upgrade. **Write `:unreleased`, never a version number** – a branch cannot know which publish it will land in, so any number it writes is a guess that goes stale the next time fontdue-js publishes without it (`font_packs: "3.7.0"` became a lie when 3.7.0 shipped with no packs). `:unreleased` is supported by nothing, so the alert shows until it really ships, and the `/release` skill stamps the real version – that step owns the number, along with the feature's tests and any docs sentence naming it. It stamps it **before cutting the release**, not at publish time: the gate is backend code, so stamping it with the publish leaves the alert wrong until the *following* app release.
|
|
22
|
+
- **Example apps are sibling checkouts under `~/code/fontdue/`**, not in this repo: `example-next-simple/` (single-tenant Next 15 RSC storefront – what the `/test-npm` "Next.js" context actually runs in; `fontdue-example-next/` is an empty husk), `fontdue-astro-example/` (`fontdue/example-astro`), `fontdue-rr7-example/` (`fontdue/example-react-router`), `fontdue-example-tanstack/`, and `next-template/` (private multi-tenant source that ejects via CI to the public `fontdue/example-next`; never hand-edit `example-next`, and nothing under `next-template/src/app` may carry FD-ids, PR links or internal codenames – `eject/check.sh` greps for them). Dependabot automerges patch/minor fontdue-js bumps in the example repos; verify the pins a day after a publish.
|
|
23
|
+
- **Testing changes across client contexts**: fontdue-js ships as one package consumed from very different rendering models – Next.js RSC (React 19), Astro islands (one small React reconciler per `<Component client:load>`), React Router 7 (full SSR + hydration) and the legacy `<script>` CDN bundle. Behaviour that works in one can silently break in another (per-island context fragmentation, RSC vs client boundaries, CJS named-import resolution under Vite, prop-types/Stripe/recaptcha CJS interop). For non-trivial changes – provider/context shape, new dependencies, query-loading/preload behaviour, the build pipeline – verify in **at least two** contexts before declaring success: `/test-npm` packs the package into an example, then `npm run dev` there and check the console + network tab (zero unexpected GraphQL fetches on hydration when a `preloadedQuery` is passed; no `Named export 'X' not found` SSR errors; no `does not provide an export named 'default'` browser errors). Drive the browser with the `claude-in-chrome` MCP (the extension on the user's real Chrome: create your own tab, never touch tabs you didn't create, never use the playwright MCP alongside it). The store/Relay-environment singleton in `fontdue-js/src/components/FontdueContextProvider/index.tsx` exists because Astro mounts a separate React tree per island – read its comment before adding a context provider that holds mutable state.
|
|
24
|
+
- **Exercising *branch* fontdue-js in a browser**: the `generaltype` dev storefront is the Next.js template consuming the *published* package, so `window.fontdue` doesn't exist there. Drop a scratch page in `assets/` (served by Vite at `/vite/assets/<name>.html`, HMR picks up `fontdue-js/src` edits) that imports `./fontdue/index.tsx` and calls `fontdue.initialize({ url: window.location.origin })` – same-origin GraphQL bypasses the CORS allowlist, which can never name a `--wt--` host. A `<fontdue-store-modal>` element must be in the DOM or buy-button clicks silently do nothing. Keep the page untracked.
|
|
25
|
+
- **User-facing docs**: `priv/docs/guide/` (on develop).
|
|
26
|
+
|
|
27
|
+
## Relay and TypeScript
|
|
28
|
+
|
|
29
|
+
- **React**: run `npm run relay` in `fontdue-js/` after updating fragments. **TypeScript**: `npm run build-ts` for type checking.
|
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
## 3.16.0
|
|
2
|
+
|
|
3
|
+
- Added `FreeDownloadForm` (`fontdue-js/FreeDownloadForm`), which emails a family’s free fonts to a customer for their name, email address and agreement to the license. Pass `collectionSlug` or `collectionId`; `loadFreeDownloadFormQuery` preloads it on the server.
|
|
4
|
+
- Added `fontdue-js/track`, with `useTrack()` and `track()`, for recording your own analytics events from your pages. Names Fontdue records itself, such as `Checkout Completed`, are refused.
|
|
5
|
+
|
|
6
|
+
## 3.15.1
|
|
7
|
+
|
|
8
|
+
- Fixed page views being recorded two to four times for one page when `tracking` is enabled, as happened under React StrictMode, when `FontdueProvider` remounted, or with more than one provider on a page. Each page load and each navigation now counts once.
|
|
9
|
+
- Changed the German text for checkout from “Kasse” to “Checkout”, with “Weiter zur Zahlung” on the button that continues to payment.
|
|
10
|
+
|
|
1
11
|
## 3.15.0
|
|
2
12
|
|
|
3
13
|
- Added a `locale` option, such as `"de"`, to `FontdueProvider`, `createFontdueFetch` and the server config in `fontdue-js/server`, and to `runWithFontdue` (plus a new `runWithLocale`) in `fontdue-js/server/middleware`. Components then load the foundry’s content in that language and show their own text in it – English and German so far – and without a `locale` nothing changes. In Next.js, set it per page as well as on the layout’s provider, since a soft navigation re-renders the page without the layout.
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @generated SignedSource<<7455698bb861bf49a70c0c636c0ea8d6>>
|
|
3
|
+
* @lightSyntaxTransform
|
|
4
|
+
* @nogrep
|
|
5
|
+
*/
|
|
6
|
+
import { ConcreteRequest } from 'relay-runtime';
|
|
7
|
+
export type CreateFreeOrderInput = {
|
|
8
|
+
collectionId: string;
|
|
9
|
+
email: string;
|
|
10
|
+
licenseAgreed: boolean;
|
|
11
|
+
name: string;
|
|
12
|
+
newsletterOptIn?: boolean | null;
|
|
13
|
+
newsletterOptInLabel?: string | null;
|
|
14
|
+
recaptchaToken?: string | null;
|
|
15
|
+
tracking?: OrderTrackingInput | null;
|
|
16
|
+
};
|
|
17
|
+
export type OrderTrackingInput = {
|
|
18
|
+
analyticsConsent?: boolean | null;
|
|
19
|
+
anonymousId?: string | null;
|
|
20
|
+
fbc?: string | null;
|
|
21
|
+
fbp?: string | null;
|
|
22
|
+
url?: string | null;
|
|
23
|
+
};
|
|
24
|
+
export type FreeDownloadFormMutation$variables = {
|
|
25
|
+
input: CreateFreeOrderInput;
|
|
26
|
+
};
|
|
27
|
+
export type FreeDownloadFormMutation$data = {
|
|
28
|
+
readonly createFreeOrder: {
|
|
29
|
+
readonly errors: {
|
|
30
|
+
readonly email: ReadonlyArray<string | null> | null;
|
|
31
|
+
readonly licenseAgreed: ReadonlyArray<string | null> | null;
|
|
32
|
+
readonly name: ReadonlyArray<string | null> | null;
|
|
33
|
+
readonly newsletterOptIn: ReadonlyArray<string | null> | null;
|
|
34
|
+
} | null;
|
|
35
|
+
readonly success: boolean;
|
|
36
|
+
} | null;
|
|
37
|
+
};
|
|
38
|
+
export type FreeDownloadFormMutation = {
|
|
39
|
+
response: FreeDownloadFormMutation$data;
|
|
40
|
+
variables: FreeDownloadFormMutation$variables;
|
|
41
|
+
};
|
|
42
|
+
declare const node: ConcreteRequest;
|
|
43
|
+
export default node;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @generated SignedSource<<7455698bb861bf49a70c0c636c0ea8d6>>
|
|
3
|
+
* @lightSyntaxTransform
|
|
4
|
+
* @nogrep
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/* tslint:disable */
|
|
8
|
+
/* eslint-disable */
|
|
9
|
+
// @ts-nocheck
|
|
10
|
+
|
|
11
|
+
const node = function () {
|
|
12
|
+
var v0 = [{
|
|
13
|
+
"defaultValue": null,
|
|
14
|
+
"kind": "LocalArgument",
|
|
15
|
+
"name": "input"
|
|
16
|
+
}],
|
|
17
|
+
v1 = [{
|
|
18
|
+
"alias": null,
|
|
19
|
+
"args": [{
|
|
20
|
+
"kind": "Variable",
|
|
21
|
+
"name": "input",
|
|
22
|
+
"variableName": "input"
|
|
23
|
+
}],
|
|
24
|
+
"concreteType": "CreateFreeOrderPayload",
|
|
25
|
+
"kind": "LinkedField",
|
|
26
|
+
"name": "createFreeOrder",
|
|
27
|
+
"plural": false,
|
|
28
|
+
"selections": [{
|
|
29
|
+
"alias": null,
|
|
30
|
+
"args": null,
|
|
31
|
+
"kind": "ScalarField",
|
|
32
|
+
"name": "success",
|
|
33
|
+
"storageKey": null
|
|
34
|
+
}, {
|
|
35
|
+
"alias": null,
|
|
36
|
+
"args": null,
|
|
37
|
+
"concreteType": "CreateFreeOrderErrors",
|
|
38
|
+
"kind": "LinkedField",
|
|
39
|
+
"name": "errors",
|
|
40
|
+
"plural": false,
|
|
41
|
+
"selections": [{
|
|
42
|
+
"alias": null,
|
|
43
|
+
"args": null,
|
|
44
|
+
"kind": "ScalarField",
|
|
45
|
+
"name": "name",
|
|
46
|
+
"storageKey": null
|
|
47
|
+
}, {
|
|
48
|
+
"alias": null,
|
|
49
|
+
"args": null,
|
|
50
|
+
"kind": "ScalarField",
|
|
51
|
+
"name": "email",
|
|
52
|
+
"storageKey": null
|
|
53
|
+
}, {
|
|
54
|
+
"alias": null,
|
|
55
|
+
"args": null,
|
|
56
|
+
"kind": "ScalarField",
|
|
57
|
+
"name": "licenseAgreed",
|
|
58
|
+
"storageKey": null
|
|
59
|
+
}, {
|
|
60
|
+
"alias": null,
|
|
61
|
+
"args": null,
|
|
62
|
+
"kind": "ScalarField",
|
|
63
|
+
"name": "newsletterOptIn",
|
|
64
|
+
"storageKey": null
|
|
65
|
+
}],
|
|
66
|
+
"storageKey": null
|
|
67
|
+
}],
|
|
68
|
+
"storageKey": null
|
|
69
|
+
}];
|
|
70
|
+
return {
|
|
71
|
+
"fragment": {
|
|
72
|
+
"argumentDefinitions": v0 /*: any*/,
|
|
73
|
+
"kind": "Fragment",
|
|
74
|
+
"metadata": null,
|
|
75
|
+
"name": "FreeDownloadFormMutation",
|
|
76
|
+
"selections": v1 /*: any*/,
|
|
77
|
+
"type": "RootMutationType",
|
|
78
|
+
"abstractKey": null
|
|
79
|
+
},
|
|
80
|
+
"kind": "Request",
|
|
81
|
+
"operation": {
|
|
82
|
+
"argumentDefinitions": v0 /*: any*/,
|
|
83
|
+
"kind": "Operation",
|
|
84
|
+
"name": "FreeDownloadFormMutation",
|
|
85
|
+
"selections": v1 /*: any*/
|
|
86
|
+
},
|
|
87
|
+
"params": {
|
|
88
|
+
"cacheID": "64aa2147178b606ff10ddf9a6523c6aa",
|
|
89
|
+
"id": null,
|
|
90
|
+
"metadata": {},
|
|
91
|
+
"name": "FreeDownloadFormMutation",
|
|
92
|
+
"operationKind": "mutation",
|
|
93
|
+
"text": "mutation FreeDownloadFormMutation(\n $input: CreateFreeOrderInput!\n) {\n createFreeOrder(input: $input) {\n success\n errors {\n name\n email\n licenseAgreed\n newsletterOptIn\n }\n }\n}\n"
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
}();
|
|
97
|
+
node.hash = "ec63092778be13d53040086da58031ff";
|
|
98
|
+
export default node;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @generated SignedSource<<6c87dc28449d7373e95743c02de42ae8>>
|
|
3
|
+
* @lightSyntaxTransform
|
|
4
|
+
* @nogrep
|
|
5
|
+
*/
|
|
6
|
+
import { ConcreteRequest } from 'relay-runtime';
|
|
7
|
+
export type FreeDownloadNewsletter = "OPTIONAL" | "REQUIRED" | "%future added value";
|
|
8
|
+
export type FreeDownloadForm_Query$variables = {
|
|
9
|
+
collectionId?: string | null;
|
|
10
|
+
collectionSlug?: string | null;
|
|
11
|
+
};
|
|
12
|
+
export type FreeDownloadForm_Query$data = {
|
|
13
|
+
readonly viewer: {
|
|
14
|
+
readonly freeDownload: {
|
|
15
|
+
readonly fontCollection: {
|
|
16
|
+
readonly id: string;
|
|
17
|
+
readonly name: string;
|
|
18
|
+
};
|
|
19
|
+
readonly items: ReadonlyArray<{
|
|
20
|
+
readonly fontStyles: ReadonlyArray<{
|
|
21
|
+
readonly id: string;
|
|
22
|
+
readonly name: string;
|
|
23
|
+
}>;
|
|
24
|
+
readonly name: string;
|
|
25
|
+
}>;
|
|
26
|
+
readonly licenses: ReadonlyArray<{
|
|
27
|
+
readonly id: string;
|
|
28
|
+
readonly name: string | null;
|
|
29
|
+
readonly url: string | null;
|
|
30
|
+
}>;
|
|
31
|
+
readonly newsletter: FreeDownloadNewsletter;
|
|
32
|
+
readonly wholeCollection: boolean;
|
|
33
|
+
} | null;
|
|
34
|
+
readonly settings: {
|
|
35
|
+
readonly newsletterOptInLabel: string | null;
|
|
36
|
+
readonly recaptchaEnabled: boolean;
|
|
37
|
+
readonly recaptchaSiteKey: string | null;
|
|
38
|
+
} | null;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
export type FreeDownloadForm_Query = {
|
|
42
|
+
response: FreeDownloadForm_Query$data;
|
|
43
|
+
variables: FreeDownloadForm_Query$variables;
|
|
44
|
+
};
|
|
45
|
+
declare const node: ConcreteRequest;
|
|
46
|
+
export default node;
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @generated SignedSource<<6c87dc28449d7373e95743c02de42ae8>>
|
|
3
|
+
* @lightSyntaxTransform
|
|
4
|
+
* @nogrep
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/* tslint:disable */
|
|
8
|
+
/* eslint-disable */
|
|
9
|
+
// @ts-nocheck
|
|
10
|
+
|
|
11
|
+
const node = function () {
|
|
12
|
+
var v0 = [{
|
|
13
|
+
"defaultValue": null,
|
|
14
|
+
"kind": "LocalArgument",
|
|
15
|
+
"name": "collectionId"
|
|
16
|
+
}, {
|
|
17
|
+
"defaultValue": null,
|
|
18
|
+
"kind": "LocalArgument",
|
|
19
|
+
"name": "collectionSlug"
|
|
20
|
+
}],
|
|
21
|
+
v1 = {
|
|
22
|
+
"alias": null,
|
|
23
|
+
"args": null,
|
|
24
|
+
"concreteType": "Settings",
|
|
25
|
+
"kind": "LinkedField",
|
|
26
|
+
"name": "settings",
|
|
27
|
+
"plural": false,
|
|
28
|
+
"selections": [{
|
|
29
|
+
"alias": null,
|
|
30
|
+
"args": [{
|
|
31
|
+
"kind": "Literal",
|
|
32
|
+
"name": "format",
|
|
33
|
+
"value": "HTML"
|
|
34
|
+
}],
|
|
35
|
+
"kind": "ScalarField",
|
|
36
|
+
"name": "newsletterOptInLabel",
|
|
37
|
+
"storageKey": "newsletterOptInLabel(format:\"HTML\")"
|
|
38
|
+
}, {
|
|
39
|
+
"alias": null,
|
|
40
|
+
"args": null,
|
|
41
|
+
"kind": "ScalarField",
|
|
42
|
+
"name": "recaptchaEnabled",
|
|
43
|
+
"storageKey": null
|
|
44
|
+
}, {
|
|
45
|
+
"alias": null,
|
|
46
|
+
"args": null,
|
|
47
|
+
"kind": "ScalarField",
|
|
48
|
+
"name": "recaptchaSiteKey",
|
|
49
|
+
"storageKey": null
|
|
50
|
+
}],
|
|
51
|
+
"storageKey": null
|
|
52
|
+
},
|
|
53
|
+
v2 = {
|
|
54
|
+
"alias": null,
|
|
55
|
+
"args": null,
|
|
56
|
+
"kind": "ScalarField",
|
|
57
|
+
"name": "id",
|
|
58
|
+
"storageKey": null
|
|
59
|
+
},
|
|
60
|
+
v3 = {
|
|
61
|
+
"alias": null,
|
|
62
|
+
"args": null,
|
|
63
|
+
"kind": "ScalarField",
|
|
64
|
+
"name": "name",
|
|
65
|
+
"storageKey": null
|
|
66
|
+
},
|
|
67
|
+
v4 = [v2 /*: any*/, v3 /*: any*/],
|
|
68
|
+
v5 = {
|
|
69
|
+
"alias": null,
|
|
70
|
+
"args": [{
|
|
71
|
+
"kind": "Variable",
|
|
72
|
+
"name": "collectionId",
|
|
73
|
+
"variableName": "collectionId"
|
|
74
|
+
}, {
|
|
75
|
+
"kind": "Variable",
|
|
76
|
+
"name": "collectionSlug",
|
|
77
|
+
"variableName": "collectionSlug"
|
|
78
|
+
}],
|
|
79
|
+
"concreteType": "FreeDownload",
|
|
80
|
+
"kind": "LinkedField",
|
|
81
|
+
"name": "freeDownload",
|
|
82
|
+
"plural": false,
|
|
83
|
+
"selections": [{
|
|
84
|
+
"alias": null,
|
|
85
|
+
"args": null,
|
|
86
|
+
"concreteType": "FontCollection",
|
|
87
|
+
"kind": "LinkedField",
|
|
88
|
+
"name": "fontCollection",
|
|
89
|
+
"plural": false,
|
|
90
|
+
"selections": v4 /*: any*/,
|
|
91
|
+
"storageKey": null
|
|
92
|
+
}, {
|
|
93
|
+
"alias": null,
|
|
94
|
+
"args": null,
|
|
95
|
+
"kind": "ScalarField",
|
|
96
|
+
"name": "wholeCollection",
|
|
97
|
+
"storageKey": null
|
|
98
|
+
}, {
|
|
99
|
+
"alias": null,
|
|
100
|
+
"args": null,
|
|
101
|
+
"kind": "ScalarField",
|
|
102
|
+
"name": "newsletter",
|
|
103
|
+
"storageKey": null
|
|
104
|
+
}, {
|
|
105
|
+
"alias": null,
|
|
106
|
+
"args": null,
|
|
107
|
+
"concreteType": "FreeDownloadItem",
|
|
108
|
+
"kind": "LinkedField",
|
|
109
|
+
"name": "items",
|
|
110
|
+
"plural": true,
|
|
111
|
+
"selections": [v3 /*: any*/, {
|
|
112
|
+
"alias": null,
|
|
113
|
+
"args": null,
|
|
114
|
+
"concreteType": "FontStyle",
|
|
115
|
+
"kind": "LinkedField",
|
|
116
|
+
"name": "fontStyles",
|
|
117
|
+
"plural": true,
|
|
118
|
+
"selections": v4 /*: any*/,
|
|
119
|
+
"storageKey": null
|
|
120
|
+
}],
|
|
121
|
+
"storageKey": null
|
|
122
|
+
}, {
|
|
123
|
+
"alias": null,
|
|
124
|
+
"args": null,
|
|
125
|
+
"concreteType": "License",
|
|
126
|
+
"kind": "LinkedField",
|
|
127
|
+
"name": "licenses",
|
|
128
|
+
"plural": true,
|
|
129
|
+
"selections": [v2 /*: any*/, v3 /*: any*/, {
|
|
130
|
+
"alias": null,
|
|
131
|
+
"args": null,
|
|
132
|
+
"kind": "ScalarField",
|
|
133
|
+
"name": "url",
|
|
134
|
+
"storageKey": null
|
|
135
|
+
}],
|
|
136
|
+
"storageKey": null
|
|
137
|
+
}],
|
|
138
|
+
"storageKey": null
|
|
139
|
+
};
|
|
140
|
+
return {
|
|
141
|
+
"fragment": {
|
|
142
|
+
"argumentDefinitions": v0 /*: any*/,
|
|
143
|
+
"kind": "Fragment",
|
|
144
|
+
"metadata": null,
|
|
145
|
+
"name": "FreeDownloadForm_Query",
|
|
146
|
+
"selections": [{
|
|
147
|
+
"alias": null,
|
|
148
|
+
"args": null,
|
|
149
|
+
"concreteType": "Viewer",
|
|
150
|
+
"kind": "LinkedField",
|
|
151
|
+
"name": "viewer",
|
|
152
|
+
"plural": false,
|
|
153
|
+
"selections": [v1 /*: any*/, v5 /*: any*/],
|
|
154
|
+
"storageKey": null
|
|
155
|
+
}],
|
|
156
|
+
"type": "RootQueryType",
|
|
157
|
+
"abstractKey": null
|
|
158
|
+
},
|
|
159
|
+
"kind": "Request",
|
|
160
|
+
"operation": {
|
|
161
|
+
"argumentDefinitions": v0 /*: any*/,
|
|
162
|
+
"kind": "Operation",
|
|
163
|
+
"name": "FreeDownloadForm_Query",
|
|
164
|
+
"selections": [{
|
|
165
|
+
"alias": null,
|
|
166
|
+
"args": null,
|
|
167
|
+
"concreteType": "Viewer",
|
|
168
|
+
"kind": "LinkedField",
|
|
169
|
+
"name": "viewer",
|
|
170
|
+
"plural": false,
|
|
171
|
+
"selections": [v1 /*: any*/, v5 /*: any*/, v2 /*: any*/],
|
|
172
|
+
"storageKey": null
|
|
173
|
+
}]
|
|
174
|
+
},
|
|
175
|
+
"params": {
|
|
176
|
+
"cacheID": "9ea7f80d5f619cb9e1b8eab77e5fd958",
|
|
177
|
+
"id": null,
|
|
178
|
+
"metadata": {},
|
|
179
|
+
"name": "FreeDownloadForm_Query",
|
|
180
|
+
"operationKind": "query",
|
|
181
|
+
"text": "query FreeDownloadForm_Query(\n $collectionId: ID\n $collectionSlug: String\n) {\n viewer {\n settings {\n newsletterOptInLabel(format: HTML)\n recaptchaEnabled\n recaptchaSiteKey\n }\n freeDownload(collectionId: $collectionId, collectionSlug: $collectionSlug) {\n fontCollection {\n id\n name\n }\n wholeCollection\n newsletter\n items {\n name\n fontStyles {\n id\n name\n }\n }\n licenses {\n id\n name\n url\n }\n }\n id\n }\n}\n"
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
}();
|
|
185
|
+
node.hash = "db8a8700fc4dd6730be1e38ac3289d20";
|
|
186
|
+
export default node;
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
|
|
3
|
+
// The free download form (`<fontdue-free-download-form>`): a collection's
|
|
4
|
+
// free fonts for a name, an email and the licence agreement, delivered by
|
|
5
|
+
// email as an order of their own (`createFreeOrder`).
|
|
6
|
+
|
|
7
|
+
import React, { act } from 'react';
|
|
8
|
+
import { createRoot } from 'react-dom/client';
|
|
9
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
10
|
+
const {
|
|
11
|
+
queryRef,
|
|
12
|
+
commitMutation
|
|
13
|
+
} = vi.hoisted(() => ({
|
|
14
|
+
queryRef: {
|
|
15
|
+
data: null,
|
|
16
|
+
variables: null
|
|
17
|
+
},
|
|
18
|
+
commitMutation: vi.fn()
|
|
19
|
+
}));
|
|
20
|
+
vi.mock('react-relay', () => ({
|
|
21
|
+
graphql: () => null,
|
|
22
|
+
commitMutation,
|
|
23
|
+
useRelayEnvironment: () => ({}),
|
|
24
|
+
usePreloadedQuery: () => queryRef.data,
|
|
25
|
+
useLazyLoadQuery: (_query, variables) => {
|
|
26
|
+
queryRef.variables = variables;
|
|
27
|
+
return queryRef.data;
|
|
28
|
+
}
|
|
29
|
+
}));
|
|
30
|
+
vi.mock('../components/FontdueContextProvider/index.js', () => ({
|
|
31
|
+
EnsureFontdueContext: _ref => {
|
|
32
|
+
let {
|
|
33
|
+
children
|
|
34
|
+
} = _ref;
|
|
35
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, children);
|
|
36
|
+
},
|
|
37
|
+
LazyQueryBoundary: _ref2 => {
|
|
38
|
+
let {
|
|
39
|
+
children
|
|
40
|
+
} = _ref2;
|
|
41
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, children);
|
|
42
|
+
}
|
|
43
|
+
}));
|
|
44
|
+
import FreeDownloadForm from '../components/FreeDownloadForm/index.js';
|
|
45
|
+
globalThis.IS_REACT_ACT_ENVIRONMENT = true;
|
|
46
|
+
const COLLECTION_ID = 'Rm9udENvbGxlY3Rpb246MQ==';
|
|
47
|
+
const viewer = function () {
|
|
48
|
+
let {
|
|
49
|
+
wholeCollection = true,
|
|
50
|
+
newsletter = 'OPTIONAL',
|
|
51
|
+
newsletterOptInLabel = 'Send me news',
|
|
52
|
+
freeDownload = true
|
|
53
|
+
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
54
|
+
return {
|
|
55
|
+
viewer: {
|
|
56
|
+
settings: {
|
|
57
|
+
newsletterOptInLabel,
|
|
58
|
+
recaptchaEnabled: false,
|
|
59
|
+
recaptchaSiteKey: null
|
|
60
|
+
},
|
|
61
|
+
freeDownload: freeDownload ? {
|
|
62
|
+
fontCollection: {
|
|
63
|
+
id: COLLECTION_ID,
|
|
64
|
+
name: 'Authentic Sans'
|
|
65
|
+
},
|
|
66
|
+
wholeCollection,
|
|
67
|
+
newsletter,
|
|
68
|
+
items: wholeCollection ? [{
|
|
69
|
+
name: 'Authentic Sans',
|
|
70
|
+
fontStyles: [{
|
|
71
|
+
id: 's1',
|
|
72
|
+
name: 'Regular'
|
|
73
|
+
}, {
|
|
74
|
+
id: 's2',
|
|
75
|
+
name: 'Bold'
|
|
76
|
+
}]
|
|
77
|
+
}] : [{
|
|
78
|
+
name: 'Regular',
|
|
79
|
+
fontStyles: [{
|
|
80
|
+
id: 's1',
|
|
81
|
+
name: 'Regular'
|
|
82
|
+
}]
|
|
83
|
+
}],
|
|
84
|
+
licenses: [{
|
|
85
|
+
id: 'l1',
|
|
86
|
+
name: 'WTFPL',
|
|
87
|
+
url: 'https://example.test/licenses/wtfpl'
|
|
88
|
+
}]
|
|
89
|
+
} : null
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
let container;
|
|
94
|
+
let root;
|
|
95
|
+
beforeEach(() => {
|
|
96
|
+
commitMutation.mockReset();
|
|
97
|
+
container = document.createElement('div');
|
|
98
|
+
document.body.append(container);
|
|
99
|
+
root = createRoot(container);
|
|
100
|
+
});
|
|
101
|
+
afterEach(() => {
|
|
102
|
+
act(() => root.unmount());
|
|
103
|
+
container.remove();
|
|
104
|
+
});
|
|
105
|
+
const render = function () {
|
|
106
|
+
let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
|
|
107
|
+
collectionSlug: 'authentic-sans'
|
|
108
|
+
};
|
|
109
|
+
return act(() => root.render( /*#__PURE__*/React.createElement(FreeDownloadForm, props)));
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
// React tracks an input's value itself, so set it through the native setter.
|
|
113
|
+
const type = (input, value) => act(() => {
|
|
114
|
+
Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value').set.call(input, value);
|
|
115
|
+
input.dispatchEvent(new Event('input', {
|
|
116
|
+
bubbles: true
|
|
117
|
+
}));
|
|
118
|
+
});
|
|
119
|
+
const fill = () => {
|
|
120
|
+
const [name, email] = [...container.querySelectorAll('input:not([type="checkbox"])')];
|
|
121
|
+
type(name, 'Ada Lovelace');
|
|
122
|
+
type(email, 'ada@example.com');
|
|
123
|
+
};
|
|
124
|
+
const checkbox = selector => container.querySelector(`${selector} input[type="checkbox"]`);
|
|
125
|
+
const button = () => container.querySelector('button[type="submit"]');
|
|
126
|
+
const submit = () => act(() => {
|
|
127
|
+
container.querySelector('form').dispatchEvent(new Event('submit', {
|
|
128
|
+
bubbles: true,
|
|
129
|
+
cancelable: true
|
|
130
|
+
}));
|
|
131
|
+
});
|
|
132
|
+
describe('FreeDownloadForm', () => {
|
|
133
|
+
it('asks for the collection by slug and links the licence', () => {
|
|
134
|
+
queryRef.data = viewer();
|
|
135
|
+
render();
|
|
136
|
+
expect(queryRef.variables).toEqual({
|
|
137
|
+
collectionId: null,
|
|
138
|
+
collectionSlug: 'authentic-sans'
|
|
139
|
+
});
|
|
140
|
+
const link = container.querySelector('.free-download__agreement a');
|
|
141
|
+
expect(link.textContent).toBe('WTFPL');
|
|
142
|
+
expect(link.href).toBe('https://example.test/licenses/wtfpl');
|
|
143
|
+
expect(container.querySelector('.free-download__styles')).toBeNull();
|
|
144
|
+
});
|
|
145
|
+
it('names the free styles when only some are free', () => {
|
|
146
|
+
queryRef.data = viewer({
|
|
147
|
+
wholeCollection: false
|
|
148
|
+
});
|
|
149
|
+
render();
|
|
150
|
+
expect(container.querySelector('.free-download__styles').textContent).toBe('Free styles: Regular');
|
|
151
|
+
});
|
|
152
|
+
it('says so when nothing is free', () => {
|
|
153
|
+
queryRef.data = viewer({
|
|
154
|
+
freeDownload: false
|
|
155
|
+
});
|
|
156
|
+
render();
|
|
157
|
+
expect(container.querySelector('form')).toBeNull();
|
|
158
|
+
expect(container.textContent).toContain('aren’t available as a free download');
|
|
159
|
+
});
|
|
160
|
+
it('sends the order and ends on “check your email”', () => {
|
|
161
|
+
queryRef.data = viewer();
|
|
162
|
+
render();
|
|
163
|
+
fill();
|
|
164
|
+
act(() => checkbox('.free-download__agreement').click());
|
|
165
|
+
act(() => checkbox('.free-download__newsletter-opt-in').click());
|
|
166
|
+
expect(button().disabled).toBe(false);
|
|
167
|
+
submit();
|
|
168
|
+
expect(commitMutation).toHaveBeenCalledTimes(1);
|
|
169
|
+
const {
|
|
170
|
+
variables,
|
|
171
|
+
onCompleted
|
|
172
|
+
} = commitMutation.mock.calls[0][1];
|
|
173
|
+
expect(variables.input).toMatchObject({
|
|
174
|
+
collectionId: COLLECTION_ID,
|
|
175
|
+
name: 'Ada Lovelace',
|
|
176
|
+
email: 'ada@example.com',
|
|
177
|
+
licenseAgreed: true,
|
|
178
|
+
newsletterOptIn: true,
|
|
179
|
+
newsletterOptInLabel: 'Send me news'
|
|
180
|
+
});
|
|
181
|
+
act(() => onCompleted({
|
|
182
|
+
createFreeOrder: {
|
|
183
|
+
success: true,
|
|
184
|
+
errors: null
|
|
185
|
+
}
|
|
186
|
+
}, null));
|
|
187
|
+
expect(container.textContent).toContain('Check your email – we’ve sent the download link to ada@example.com.');
|
|
188
|
+
});
|
|
189
|
+
it('holds the download until the newsletter is ticked when the store requires it', () => {
|
|
190
|
+
queryRef.data = viewer({
|
|
191
|
+
newsletter: 'REQUIRED',
|
|
192
|
+
newsletterOptInLabel: null
|
|
193
|
+
});
|
|
194
|
+
render();
|
|
195
|
+
fill();
|
|
196
|
+
act(() => checkbox('.free-download__agreement').click());
|
|
197
|
+
expect(container.querySelector('.free-download__newsletter-opt-in').textContent).toContain('Sign me up for the newsletter (required to download)');
|
|
198
|
+
expect(button().disabled).toBe(true);
|
|
199
|
+
act(() => checkbox('.free-download__newsletter-opt-in').click());
|
|
200
|
+
expect(button().disabled).toBe(false);
|
|
201
|
+
});
|
|
202
|
+
it('shows the server’s field errors', () => {
|
|
203
|
+
queryRef.data = viewer();
|
|
204
|
+
render();
|
|
205
|
+
fill();
|
|
206
|
+
act(() => checkbox('.free-download__agreement').click());
|
|
207
|
+
submit();
|
|
208
|
+
const {
|
|
209
|
+
onCompleted
|
|
210
|
+
} = commitMutation.mock.calls[0][1];
|
|
211
|
+
act(() => onCompleted({
|
|
212
|
+
createFreeOrder: {
|
|
213
|
+
success: false,
|
|
214
|
+
errors: {
|
|
215
|
+
email: ['isn’t a valid email address']
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}, null));
|
|
219
|
+
expect(container.querySelector('.free-download__errors').textContent).toBe('isn’t a valid email address');
|
|
220
|
+
expect(container.querySelector('form')).not.toBeNull();
|
|
221
|
+
});
|
|
222
|
+
});
|
|
@@ -225,7 +225,7 @@ describe('cart', () => {
|
|
|
225
225
|
}));
|
|
226
226
|
expect(html).toContain('>Zwischensumme<');
|
|
227
227
|
expect(html).toContain('>Gesamt</div>');
|
|
228
|
-
expect(html).toContain('Wird
|
|
228
|
+
expect(html).toContain('Wird im Checkout berechnet');
|
|
229
229
|
expect(html).toContain('data-label="Subtotal"');
|
|
230
230
|
});
|
|
231
231
|
it('renders the totals in English with no locale, as before', () => {
|