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.
Files changed (35) hide show
  1. package/AGENTS.md +29 -0
  2. package/CHANGELOG.md +10 -0
  3. package/dist/__generated__/FreeDownloadFormMutation.graphql.d.ts +43 -0
  4. package/dist/__generated__/FreeDownloadFormMutation.graphql.js +98 -0
  5. package/dist/__generated__/FreeDownloadForm_Query.graphql.d.ts +46 -0
  6. package/dist/__generated__/FreeDownloadForm_Query.graphql.js +186 -0
  7. package/dist/__tests__/freeDownloadForm.test.js +222 -0
  8. package/dist/__tests__/i18nComponents.test.js +1 -1
  9. package/dist/__tests__/trackEvents.test.js +131 -0
  10. package/dist/__tests__/trackingPageViews.test.js +339 -0
  11. package/dist/__tests__/trackingRouteChanges.test.js +48 -2
  12. package/dist/components/FreeDownloadForm/FreeDownloadFormElement.d.ts +10 -0
  13. package/dist/components/FreeDownloadForm/FreeDownloadFormElement.js +17 -0
  14. package/dist/components/FreeDownloadForm/index.d.ts +21 -0
  15. package/dist/components/FreeDownloadForm/index.js +283 -0
  16. package/dist/components/FreeDownloadForm/index.server.d.ts +9 -0
  17. package/dist/components/FreeDownloadForm/index.server.js +22 -0
  18. package/dist/components/FreeDownloadForm/variables.d.ts +8 -0
  19. package/dist/components/FreeDownloadForm/variables.js +18 -0
  20. package/dist/components/Root/index.js +1 -0
  21. package/dist/components/Tracking/index.js +52 -34
  22. package/dist/components/Tracking/pageViews.d.ts +26 -0
  23. package/dist/components/Tracking/pageViews.js +94 -0
  24. package/dist/components/Tracking/routeChanges.d.ts +9 -1
  25. package/dist/components/Tracking/routeChanges.js +33 -9
  26. package/dist/components/Tracking/sendTrackEvent.d.ts +28 -0
  27. package/dist/components/Tracking/sendTrackEvent.js +68 -0
  28. package/dist/components/track.d.ts +21 -0
  29. package/dist/components/track.js +31 -0
  30. package/dist/fontdue.css +32 -0
  31. package/dist/i18n/de.js +17 -5
  32. package/dist/i18n/en.d.ts +11 -0
  33. package/dist/i18n/en.js +12 -0
  34. package/dist/version.js +1 -1
  35. package/package.json +6 -1
@@ -0,0 +1,131 @@
1
+ // @vitest-environment happy-dom
2
+ // @vitest-environment-options { "url": "https://store.example.com/contests?ref=app" }
3
+
4
+ // A foundry's own events (`fontdue.track()` / `useTrack()`): they carry the
5
+ // same identity as the page's page views – the cookieless anonymous ID while
6
+ // consent is pending, the signed-in customer's token – and never break the
7
+ // page when the server refuses one.
8
+
9
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
10
+ import { sendTrackEvent } from '../components/Tracking/sendTrackEvent.js';
11
+ import { setClientAnonymousId, setConsent } from '../components/ConsentBanner/consent.js';
12
+ import { resetTokenStore, setTokens } from '../auth/tokenStore.js';
13
+ const URL = 'https://fontdue.example.com';
14
+ function stubFetch() {
15
+ let response = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
16
+ ok: true
17
+ };
18
+ const fetchMock = vi.fn().mockResolvedValue(response);
19
+ vi.stubGlobal('fetch', fetchMock);
20
+ return fetchMock;
21
+ }
22
+ function sent(fetchMock) {
23
+ expect(fetchMock).toHaveBeenCalledTimes(1);
24
+ const [url, init] = fetchMock.mock.calls[0];
25
+ return {
26
+ url,
27
+ init,
28
+ body: JSON.parse(init.body)
29
+ };
30
+ }
31
+ beforeEach(() => {
32
+ document.cookie = '_fontdue_cc=;path=/;max-age=0';
33
+ document.title = 'Contests';
34
+ localStorage.clear();
35
+ resetTokenStore();
36
+ });
37
+ afterEach(() => {
38
+ vi.unstubAllGlobals();
39
+ vi.restoreAllMocks();
40
+ });
41
+ describe('sendTrackEvent', () => {
42
+ it('posts the event with the page it happened on', async () => {
43
+ const fetchMock = stubFetch();
44
+ await sendTrackEvent(URL, 'Contest Entered', {
45
+ contest: 'summer'
46
+ });
47
+ const {
48
+ url,
49
+ init,
50
+ body
51
+ } = sent(fetchMock);
52
+ expect(url).toBe(`${URL}/api/track`);
53
+ expect(init.method).toBe('POST');
54
+ expect(init.credentials).toBe('include');
55
+ // A click that navigates away must still deliver its event.
56
+ expect(init.keepalive).toBe(true);
57
+ expect(body.event).toBe('Contest Entered');
58
+ expect(body.properties).toEqual({
59
+ contest: 'summer'
60
+ });
61
+ expect(body.context.page).toEqual({
62
+ url: 'https://store.example.com/contests?ref=app',
63
+ path: '/contests',
64
+ title: 'Contests',
65
+ referrer: '',
66
+ search: '?ref=app'
67
+ });
68
+ expect(body.user_id).toBeUndefined();
69
+ expect(init.headers.Authorization).toBeUndefined();
70
+ });
71
+ it('names the customer a page passes in userId', async () => {
72
+ const fetchMock = stubFetch();
73
+ await sendTrackEvent(URL, 'Contest Entered', {}, {
74
+ userId: 'Q3VzdG9tZXI6MQ=='
75
+ });
76
+ expect(sent(fetchMock).body.user_id).toBe('Q3VzdG9tZXI6MQ==');
77
+ });
78
+ it('sends a signed-in customer’s token', async () => {
79
+ setTokens({
80
+ accessToken: 'access-1',
81
+ refreshToken: 'refresh-1'
82
+ }, URL);
83
+ const fetchMock = stubFetch();
84
+ await sendTrackEvent(URL, 'Contest Entered');
85
+ expect(sent(fetchMock).init.headers.Authorization).toBe('Bearer access-1');
86
+ });
87
+ it('never sends another Fontdue site’s token', async () => {
88
+ setTokens({
89
+ accessToken: 'access-1',
90
+ refreshToken: 'refresh-1'
91
+ }, 'https://other.example.com');
92
+ const fetchMock = stubFetch();
93
+ await sendTrackEvent(URL, 'Contest Entered');
94
+ expect(sent(fetchMock).init.headers.Authorization).toBeUndefined();
95
+ });
96
+ it('sends the cookieless anonymous ID only while consent is pending', async () => {
97
+ setClientAnonymousId('client-anon-1');
98
+ let fetchMock = stubFetch();
99
+ await sendTrackEvent(URL, 'Contest Entered');
100
+ expect(sent(fetchMock).body.anonymous_id).toBe('client-anon-1');
101
+ setConsent(['necessary', 'analytics']);
102
+ fetchMock = stubFetch();
103
+ await sendTrackEvent(URL, 'Contest Entered');
104
+ expect(sent(fetchMock).body.anonymous_id).toBeUndefined();
105
+ });
106
+ it('warns with the server’s reason when it refuses the event', async () => {
107
+ const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
108
+ stubFetch({
109
+ ok: false,
110
+ status: 422,
111
+ json: () => Promise.resolve({
112
+ success: false,
113
+ error: '“Purchase” is recorded by Fontdue itself'
114
+ })
115
+ });
116
+ await expect(sendTrackEvent(URL, 'Purchase')).resolves.toBeUndefined();
117
+ expect(warn).toHaveBeenCalledWith('fontdue track: “Purchase” was not recorded – “Purchase” is recorded by Fontdue itself');
118
+ });
119
+ it('never throws when the request fails', async () => {
120
+ vi.spyOn(console, 'debug').mockImplementation(() => {});
121
+ vi.stubGlobal('fetch', vi.fn().mockRejectedValue(new TypeError('Failed to fetch')));
122
+ await expect(sendTrackEvent(URL, 'Contest Entered')).resolves.toBeUndefined();
123
+ });
124
+ it('sends nothing before Fontdue knows its URL', async () => {
125
+ const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
126
+ const fetchMock = stubFetch();
127
+ await sendTrackEvent('', 'Contest Entered');
128
+ expect(fetchMock).not.toHaveBeenCalled();
129
+ expect(warn).toHaveBeenCalled();
130
+ });
131
+ });
@@ -0,0 +1,339 @@
1
+ // @vitest-environment happy-dom
2
+
3
+ // One page view per navigation, end to end through `<FontdueProvider>`: the
4
+ // entry view the Tracking component sends on mount and the views it sends for
5
+ // client-side navigation must not double up however React mounts it –
6
+ // StrictMode's mount/unmount/mount, a remount of the provider, or more than one
7
+ // provider on the page. Each test loads the provider fresh (`vi.resetModules`)
8
+ // so module-level tracking state starts clean, the way it does on a page load.
9
+
10
+ import React, { StrictMode, act } from 'react';
11
+ import { createRoot } from 'react-dom/client';
12
+ import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';
13
+ const {
14
+ serverTracking,
15
+ query
16
+ } = vi.hoisted(() => ({
17
+ serverTracking: {
18
+ enabled: true,
19
+ consentRequired: false
20
+ },
21
+ // Set to make the provider's query suspend on its next render.
22
+ query: {
23
+ pending: null
24
+ }
25
+ }));
26
+
27
+ // The provider's query and fragments are stubbed: every fragment reads as the
28
+ // server's tracking config, which is all ServerConfigProvider needs.
29
+ vi.mock('react-relay', async importActual => {
30
+ // react-relay is CommonJS: its named exports sit under `default` here.
31
+ const actual = await importActual();
32
+ return {
33
+ ...actual,
34
+ ...actual.default,
35
+ graphql: () => ({}),
36
+ useLazyLoadQuery: () => {
37
+ if (query.pending) throw query.pending;
38
+ return {
39
+ viewer: {}
40
+ };
41
+ },
42
+ useFragment: () => ({
43
+ fontdueConfig: {
44
+ tracking: {
45
+ ...serverTracking
46
+ }
47
+ }
48
+ })
49
+ };
50
+ });
51
+
52
+ // The other aux UI the provider mounts beside Tracking has nothing to do with
53
+ // page views.
54
+ vi.mock('../components/ThemeConfig/index.js', () => ({
55
+ default: () => null
56
+ }));
57
+ vi.mock('../components/TestModeBanner/index.js', () => ({
58
+ default: () => null
59
+ }));
60
+ vi.mock('../components/ConsentBanner/index.js', () => ({
61
+ default: () => null
62
+ }));
63
+ vi.mock('../components/FontdueAdminToolbar/index.js', () => ({
64
+ default: () => null
65
+ }));
66
+ const API = 'https://api.foundry.test';
67
+ // happy-dom's document lives at localhost; history refuses other origins.
68
+ const ORIGIN = window.location.origin;
69
+ let fetchMock;
70
+ let roots = [];
71
+ // History as the page had it before any provider wrapped it, for moving the
72
+ // URL without telling the trackers (a browser's back button does that).
73
+ let originalReplaceState;
74
+
75
+ /** Paths of every page view posted so far, in order. */
76
+ function pageViews() {
77
+ return fetchMock.mock.calls.filter(_ref => {
78
+ let [url] = _ref;
79
+ return String(url).endsWith('/api/track/page');
80
+ }).map(_ref2 => {
81
+ let [, init] = _ref2;
82
+ return JSON.parse(init.body).properties.path;
83
+ });
84
+ }
85
+
86
+ /** Let the trackers' deferred URL checks and any lazy imports settle. */
87
+ async function settle() {
88
+ await act(async () => {
89
+ await new Promise(resolve => setTimeout(resolve, 20));
90
+ });
91
+ }
92
+ async function loadProvider() {
93
+ const {
94
+ default: FontdueProvider
95
+ } = await import('../components/FontdueProvider/index.js');
96
+ return FontdueProvider;
97
+ }
98
+ async function mount(FontdueProvider) {
99
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
100
+ const container = document.createElement('div');
101
+ document.body.appendChild(container);
102
+ const root = createRoot(container);
103
+ roots.push(root);
104
+ await render(root, FontdueProvider, options);
105
+ return root;
106
+ }
107
+ async function render(root, FontdueProvider) {
108
+ let {
109
+ strict = true,
110
+ config = {}
111
+ } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
112
+ const tree = /*#__PURE__*/React.createElement(FontdueProvider, {
113
+ url: API,
114
+ config: config
115
+ }, null);
116
+ await act(async () => {
117
+ root.render(strict ? /*#__PURE__*/React.createElement(StrictMode, null, tree) : tree);
118
+ });
119
+ await settle();
120
+ }
121
+ async function unmount(root) {
122
+ await act(async () => {
123
+ root.unmount();
124
+ });
125
+ roots = roots.filter(r => r !== root);
126
+ }
127
+
128
+ /** A router navigation: push the new URL, then rewrite the entry in place. */
129
+ async function navigate(path) {
130
+ await act(async () => {
131
+ history.pushState({}, '', `${ORIGIN}${path}`);
132
+ // Next's App Router rewrites the current entry with its own state after
133
+ // committing a navigation (and on every later tree update).
134
+ history.replaceState({
135
+ __NA: true
136
+ }, '', `${ORIGIN}${path}`);
137
+ });
138
+ await settle();
139
+ }
140
+
141
+ /** Back/forward: the browser moves the URL, then fires popstate. */
142
+ async function popstate(path) {
143
+ await act(async () => {
144
+ originalReplaceState.call(history, {}, '', `${ORIGIN}${path}`);
145
+ window.dispatchEvent(new PopStateEvent('popstate'));
146
+ });
147
+ await settle();
148
+ }
149
+
150
+ // Transform the lazily imported Tracking module up front, so the first test's
151
+ // mount doesn't outlast `settle` while it compiles.
152
+ beforeAll(async () => {
153
+ await import('../components/Tracking/index.js');
154
+ });
155
+ beforeEach(() => {
156
+ vi.resetModules();
157
+ serverTracking.enabled = true;
158
+ serverTracking.consentRequired = false;
159
+ query.pending = null;
160
+ document.cookie = '_fontdue_cc=; max-age=0; path=/';
161
+ fetchMock = vi.fn(async () => ({
162
+ json: async () => ({
163
+ anonymous_id: 'anon-1'
164
+ })
165
+ }));
166
+ vi.stubGlobal('fetch', fetchMock);
167
+ originalReplaceState = History.prototype.replaceState;
168
+ originalReplaceState.call(history, {}, '', `${ORIGIN}/?gclid=abc`);
169
+ });
170
+ afterEach(async () => {
171
+ for (const root of [...roots]) await unmount(root);
172
+ // Drop any wrapper a tracker left on the instance, so the next test starts
173
+ // from the prototype's methods.
174
+ delete history.pushState;
175
+ delete history.replaceState;
176
+ vi.unstubAllGlobals();
177
+ });
178
+ describe('page views through FontdueProvider', () => {
179
+ it('sends one entry page view under StrictMode', async () => {
180
+ const FontdueProvider = await loadProvider();
181
+ await mount(FontdueProvider);
182
+ expect(pageViews()).toEqual(['/']);
183
+ });
184
+ it('ignores the router rewriting the entry URL in place', async () => {
185
+ const FontdueProvider = await loadProvider();
186
+ await mount(FontdueProvider);
187
+ await act(async () => {
188
+ history.replaceState({
189
+ __NA: true
190
+ }, '', window.location.href);
191
+ });
192
+ await settle();
193
+ expect(pageViews()).toEqual(['/']);
194
+ });
195
+ it('sends one page view per client-side navigation, back and forward included', async () => {
196
+ const FontdueProvider = await loadProvider();
197
+ await mount(FontdueProvider);
198
+ await navigate('/typefaces/boxal');
199
+ await navigate('/test-fonts');
200
+ await popstate('/typefaces/boxal');
201
+ expect(pageViews()).toEqual(['/', '/typefaces/boxal', '/test-fonts', '/typefaces/boxal']);
202
+ });
203
+ it('counts a return to the entry page after navigating away', async () => {
204
+ const FontdueProvider = await loadProvider();
205
+ await mount(FontdueProvider);
206
+ await navigate('/typefaces/boxal');
207
+ await navigate('/');
208
+ expect(pageViews()).toEqual(['/', '/typefaces/boxal', '/']);
209
+ });
210
+ it('does not count the entry again when the provider remounts on the same page', async () => {
211
+ // A remount – a Suspense or Activity boundary revealing the provider again,
212
+ // a parent changing its key – is not a new page view.
213
+ const FontdueProvider = await loadProvider();
214
+ const root = await mount(FontdueProvider);
215
+ await unmount(root);
216
+ await mount(FontdueProvider);
217
+ expect(pageViews()).toEqual(['/']);
218
+ });
219
+ it('does not count the entry again when the provider query suspends again', async () => {
220
+ // Tracking is lazy-loaded inside the provider's Suspense boundary. A
221
+ // re-render that suspends again hides the committed tree behind the
222
+ // fallback until the data arrives; that must not read as a new entry.
223
+ const FontdueProvider = await loadProvider();
224
+ const root = await mount(FontdueProvider);
225
+ let resolve;
226
+ query.pending = new Promise(r => resolve = r);
227
+ await render(root, FontdueProvider, {
228
+ config: {
229
+ typeTester: {}
230
+ }
231
+ });
232
+ query.pending = null;
233
+ await act(async () => resolve());
234
+ await settle();
235
+ expect(pageViews()).toEqual(['/']);
236
+ });
237
+ it('counts a navigation once when the provider remounts with it', async () => {
238
+ // A provider rendered by a page rather than the layout unmounts and mounts
239
+ // again with the navigation that replaces the page, while the history
240
+ // write that announced it is still waiting to be checked.
241
+ const FontdueProvider = await loadProvider();
242
+ const root = await mount(FontdueProvider, {
243
+ strict: false
244
+ });
245
+ await act(async () => {
246
+ history.pushState({}, '', `${ORIGIN}/typefaces/boxal`);
247
+ root.unmount();
248
+ });
249
+ roots = roots.filter(r => r !== root);
250
+ await mount(FontdueProvider, {
251
+ strict: false
252
+ });
253
+ expect(pageViews()).toEqual(['/', '/typefaces/boxal']);
254
+ });
255
+ it('counts each view once with two providers on the page', async () => {
256
+ const FontdueProvider = await loadProvider();
257
+ await mount(FontdueProvider);
258
+ await mount(FontdueProvider);
259
+ await navigate('/typefaces/boxal');
260
+ expect(pageViews()).toEqual(['/', '/typefaces/boxal']);
261
+ });
262
+ it('keeps tracking the next navigation after one of two providers unmounts', async () => {
263
+ const FontdueProvider = await loadProvider();
264
+ const first = await mount(FontdueProvider);
265
+ await mount(FontdueProvider);
266
+ await unmount(first);
267
+ await navigate('/typefaces/boxal');
268
+ expect(pageViews()).toEqual(['/', '/typefaces/boxal']);
269
+ });
270
+ it('stops tracking navigation once every provider has unmounted', async () => {
271
+ const FontdueProvider = await loadProvider();
272
+ const root = await mount(FontdueProvider);
273
+ await unmount(root);
274
+ await navigate('/typefaces/boxal');
275
+ expect(pageViews()).toEqual(['/']);
276
+ });
277
+ it('sends one cookieless entry view with one client anonymous id under StrictMode', async () => {
278
+ var _consent$getEntryAttr;
279
+ serverTracking.consentRequired = true;
280
+ const FontdueProvider = await loadProvider();
281
+ await mount(FontdueProvider);
282
+ const entryBodies = fetchMock.mock.calls.filter(_ref3 => {
283
+ let [url] = _ref3;
284
+ return String(url).endsWith('/api/track/page');
285
+ }).map(_ref4 => {
286
+ let [, init] = _ref4;
287
+ return JSON.parse(init.body);
288
+ });
289
+ expect(entryBodies).toHaveLength(1);
290
+ const consent = await import('../components/ConsentBanner/consent.js');
291
+ expect(entryBodies[0].anonymous_id).toBe(consent.getClientAnonymousId());
292
+ expect((_consent$getEntryAttr = consent.getEntryAttribution()) === null || _consent$getEntryAttr === void 0 ? void 0 : _consent$getEntryAttr.properties.path).toBe('/');
293
+ });
294
+ });
295
+ describe('the Segment SDK page call for the entry', () => {
296
+ function segmentStub() {
297
+ const analytics = {
298
+ setAnonymousId: vi.fn(async () => {}),
299
+ page: vi.fn(async () => {})
300
+ };
301
+ const load = vi.fn(() => analytics);
302
+ return {
303
+ analytics,
304
+ load,
305
+ config: {
306
+ tracking: {
307
+ segment: {
308
+ analytics: load
309
+ }
310
+ }
311
+ }
312
+ };
313
+ }
314
+ it('goes out once under StrictMode', async () => {
315
+ const segment = segmentStub();
316
+ const FontdueProvider = await loadProvider();
317
+ await mount(FontdueProvider, {
318
+ config: segment.config
319
+ });
320
+ expect(segment.load).toHaveBeenCalledTimes(1);
321
+ expect(segment.analytics.page).toHaveBeenCalledTimes(1);
322
+ expect(segment.analytics.setAnonymousId).toHaveBeenCalledWith('anon-1');
323
+ });
324
+ it('goes out once when consent is granted after a StrictMode mount', async () => {
325
+ serverTracking.consentRequired = true;
326
+ const segment = segmentStub();
327
+ const FontdueProvider = await loadProvider();
328
+ await mount(FontdueProvider, {
329
+ config: segment.config
330
+ });
331
+ expect(segment.analytics.page).not.toHaveBeenCalled();
332
+ const consent = await import('../components/ConsentBanner/consent.js');
333
+ await act(async () => {
334
+ consent.setConsent(['analytics']);
335
+ });
336
+ await settle();
337
+ expect(segment.analytics.page).toHaveBeenCalledTimes(1);
338
+ });
339
+ });
@@ -6,6 +6,7 @@ import { trackRouteChanges } from '../components/Tracking/routeChanges.js';
6
6
  // synchronously so each call's effect can be asserted in order.
7
7
  function setup() {
8
8
  let startUrl = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'https://foundry.test/fonts';
9
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
9
10
  let url = startUrl;
10
11
  const listeners = {};
11
12
  const history = {
@@ -26,9 +27,10 @@ function setup() {
26
27
  window: windowLike,
27
28
  currentUrl: () => url,
28
29
  onNavigate,
29
- defer: callback => {
30
+ defer: options.defer ?? (callback => {
30
31
  callback();
31
- }
32
+ }),
33
+ claim: options.claim
32
34
  });
33
35
  return {
34
36
  history,
@@ -107,4 +109,48 @@ describe('trackRouteChanges', () => {
107
109
  t.navigate('https://foundry.test/cart');
108
110
  expect(t.onNavigate).not.toHaveBeenCalled();
109
111
  });
112
+ it('drops a check still pending when cleanup runs', () => {
113
+ // A provider can unmount in the same commit as the navigation it was told
114
+ // about; its deferred check must not report that navigation afterwards.
115
+ const pending = [];
116
+ const t = setup('https://foundry.test/fonts', {
117
+ defer: callback => pending.push(callback)
118
+ });
119
+ t.navigate('https://foundry.test/cart');
120
+ t.cleanup();
121
+ pending.forEach(callback => callback());
122
+ expect(t.onNavigate).not.toHaveBeenCalled();
123
+ });
124
+ it('leaves a wrapper added after its own in place on cleanup', () => {
125
+ const t = setup();
126
+ const ours = t.history.pushState;
127
+ const laterWrapper = vi.fn(function () {
128
+ return ours(...arguments);
129
+ });
130
+ t.history.pushState = laterWrapper;
131
+ t.cleanup();
132
+
133
+ // Restoring the original would silently unhook whoever wrapped us.
134
+ expect(t.history.pushState).toBe(laterWrapper);
135
+ t.navigate('https://foundry.test/cart');
136
+ expect(laterWrapper).toHaveBeenCalledTimes(1);
137
+ expect(t.onNavigate).not.toHaveBeenCalled();
138
+ });
139
+ it('asks a shared claim whether each URL is new', () => {
140
+ // The Tracking component shares one claim across every watcher and the
141
+ // entry page view, so a URL another one already reported isn't repeated.
142
+ const claimed = new Set(['https://foundry.test/fonts', 'https://foundry.test/cart']);
143
+ const claim = vi.fn(url => {
144
+ if (claimed.has(url)) return false;
145
+ claimed.add(url);
146
+ return true;
147
+ });
148
+ const t = setup('https://foundry.test/fonts', {
149
+ claim
150
+ });
151
+ t.navigate('https://foundry.test/cart');
152
+ t.navigate('https://foundry.test/about');
153
+ expect(claim).toHaveBeenCalledWith('https://foundry.test/cart');
154
+ expect(t.onNavigate).toHaveBeenCalledTimes(1);
155
+ });
110
156
  });
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+ interface FreeDownloadFormElement_props {
3
+ collectionId?: string;
4
+ collectionSlug?: string;
5
+ agreementLabel?: string;
6
+ downloadLabel?: string;
7
+ newsletterCheckboxChecked?: string;
8
+ }
9
+ declare const FreeDownloadFormElement: ({ newsletterCheckboxChecked, ...props }: FreeDownloadFormElement_props) => React.JSX.Element;
10
+ export default FreeDownloadFormElement;
@@ -0,0 +1,17 @@
1
+ function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
2
+ import React from 'react';
3
+ import FreeDownloadForm from './index.js';
4
+
5
+ // `<fontdue-free-download-form collection-slug="…">`: attributes arrive as
6
+ // camelCased strings.
7
+
8
+ const FreeDownloadFormElement = _ref => {
9
+ let {
10
+ newsletterCheckboxChecked,
11
+ ...props
12
+ } = _ref;
13
+ return /*#__PURE__*/React.createElement(FreeDownloadForm, _extends({}, props, {
14
+ newsletterCheckboxChecked: newsletterCheckboxChecked === 'true'
15
+ }));
16
+ };
17
+ export default FreeDownloadFormElement;
@@ -0,0 +1,21 @@
1
+ import React from 'react';
2
+ import { FreeDownloadForm_Query } from '../../__generated__/FreeDownloadForm_Query.graphql.js';
3
+ import { SerializablePreloadedQuery, type LoadQueryOptions } from '../../relay/loadSerializableQuery.js';
4
+ import { Config } from '../ConfigContext.js';
5
+ import { FreeDownloadFormCollectionProps } from './variables.js';
6
+ export interface FreeDownloadForm_props extends FreeDownloadFormCollectionProps {
7
+ agreementLabel?: string;
8
+ downloadLabel?: string;
9
+ newsletterCheckboxChecked?: boolean;
10
+ }
11
+ export type FreeDownloadFormPreloadedQuery = SerializablePreloadedQuery<FreeDownloadForm_Query>;
12
+ export declare function loadFreeDownloadFormQuery(variables: FreeDownloadFormCollectionProps, options?: LoadQueryOptions): Promise<FreeDownloadFormPreloadedQuery>;
13
+ export declare function FreeDownloadFormPreloadedQueryRenderer({ preloadedQuery, ...rest }: FreeDownloadForm_props & {
14
+ preloadedQuery: FreeDownloadFormPreloadedQuery;
15
+ }): React.JSX.Element;
16
+ export type FreeDownloadForm_unifiedProps = FreeDownloadForm_props & {
17
+ preloadedQuery?: FreeDownloadFormPreloadedQuery;
18
+ config?: Config;
19
+ locale?: string;
20
+ };
21
+ export default function FreeDownloadForm({ config, locale, ...props }: FreeDownloadForm_unifiedProps): React.JSX.Element;