@startsimpli/integrations 0.2.49 → 0.2.51
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/package.json +3 -3
- package/src/comms/__tests__/announcement-composer.test.tsx +56 -0
- package/src/comms/__tests__/customer-emails-page.test.tsx +49 -5
- package/src/comms/__tests__/email-viewer.test.tsx +233 -0
- package/src/comms/__tests__/fixtures.ts +1 -0
- package/src/comms/__tests__/recipient-local-send.test.tsx +358 -0
- package/src/comms/components/AnnouncementComposer.tsx +51 -1
- package/src/comms/components/DefaultTimeZoneSetting.tsx +67 -0
- package/src/comms/components/DraftReview.tsx +12 -9
- package/src/comms/components/EmailPreview.tsx +155 -12
- package/src/comms/components/EmailPreviewPage.tsx +161 -0
- package/src/comms/components/SchedulePicker.tsx +90 -18
- package/src/comms/components/ScheduledSends.tsx +98 -10
- package/src/comms/components/SendLog.tsx +4 -2
- package/src/comms/components/SequenceSettings.tsx +3 -7
- package/src/comms/components/_shared.tsx +8 -0
- package/src/comms/components/index.ts +2 -0
- package/src/comms/components/pages/CustomerEmailsPage.tsx +20 -1
- package/src/comms/hooks/index.ts +29 -2
- package/src/comms/types/index.ts +62 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@startsimpli/integrations",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.51",
|
|
4
4
|
"description": "Provider-agnostic types, API clients, hooks, and UI primitives for email + calendar integrations across StartSimpli apps, plus foundry customer email (subpath ./comms).",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"types": "./src/index.ts",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"react": ">=18.0.0",
|
|
36
36
|
"@tanstack/react-query": ">=5.0.0",
|
|
37
37
|
"@startsimpli/llm": ">=0.4.0",
|
|
38
|
-
"@startsimpli/ui": "^0.4.
|
|
38
|
+
"@startsimpli/ui": "^0.4.164"
|
|
39
39
|
},
|
|
40
40
|
"peerDependenciesMeta": {
|
|
41
41
|
"react": {
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"typescript": "^6.0.0",
|
|
66
66
|
"vitest": "^3.0.0",
|
|
67
67
|
"@startsimpli/llm": "0.4.25",
|
|
68
|
-
"@startsimpli/ui": "0.4.
|
|
68
|
+
"@startsimpli/ui": "0.4.164"
|
|
69
69
|
},
|
|
70
70
|
"scripts": {
|
|
71
71
|
"type-check": "tsc --noEmit",
|
|
@@ -18,6 +18,7 @@ import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
|
|
18
18
|
import { http, HttpResponse } from 'msw';
|
|
19
19
|
import { setupServer } from 'msw/node';
|
|
20
20
|
|
|
21
|
+
import { DraftItem } from '../components/DraftReview';
|
|
21
22
|
import { CustomerEmailsPage } from '../components/pages/CustomerEmailsPage';
|
|
22
23
|
import { createCommsApi, setApiBase } from '../api/index';
|
|
23
24
|
import type { Draft } from '../types/index';
|
|
@@ -45,6 +46,11 @@ const server = setupServer(
|
|
|
45
46
|
const results = drafts.filter((d) => d.approval === wanted);
|
|
46
47
|
return HttpResponse.json({ count: results.length, next: null, previous: null, results });
|
|
47
48
|
}
|
|
49
|
+
const pv = hit.path.match(/^\/drafts\/([^/]+)\/preview\/$/);
|
|
50
|
+
if (pv) {
|
|
51
|
+
const d = drafts.find((x) => x.id === pv[1])!;
|
|
52
|
+
return HttpResponse.json({ subject: d.subject, preheader: d.preheader, html: d.html, text: d.text });
|
|
53
|
+
}
|
|
48
54
|
const m = hit.path.match(/^\/drafts\/([^/]+)\/$/);
|
|
49
55
|
if (m && hit.method === 'GET') {
|
|
50
56
|
const d = drafts.find((x) => x.id === m[1])!;
|
|
@@ -183,4 +189,54 @@ describe('Announcements fold', () => {
|
|
|
183
189
|
const { region } = await openFold();
|
|
184
190
|
expect(await within(region).findByText('Waiting for you')).toBeInTheDocument();
|
|
185
191
|
});
|
|
192
|
+
|
|
193
|
+
it('opens the viewer on a draft that is already listed when it is asked to', async () => {
|
|
194
|
+
const d = draft({ id: 'f-2', program_key: 'announcement', window: [] as any, item_keys: [] });
|
|
195
|
+
drafts.push(d);
|
|
196
|
+
const qc = new QueryClient({ defaultOptions: { queries: { retry: false } } });
|
|
197
|
+
const ui = (open: boolean) => (
|
|
198
|
+
<QueryClientProvider client={qc}>
|
|
199
|
+
<DraftItem api={createCommsApi(SLUG)} draft={d} startPreviewing={open} />
|
|
200
|
+
</QueryClientProvider>
|
|
201
|
+
);
|
|
202
|
+
const { rerender } = render(ui(false));
|
|
203
|
+
expect(screen.queryByTitle(/email preview/i)).toBeNull();
|
|
204
|
+
rerender(ui(true));
|
|
205
|
+
expect(await screen.findByTitle(/email preview/i)).toBeInTheDocument();
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
describe('loading an email from a file', () => {
|
|
209
|
+
const file = (content: string, name = 'engine.comms-content.json') =>
|
|
210
|
+
new File([content], name, { type: 'application/json' });
|
|
211
|
+
const email = { subject: 'Meet the engine, {{first_name}}', preheader: 'Faster patterns', html: '<h1>Hi</h1><p><img src="https://cdn.test/a.png" alt="A"></p>', text: 'Hi' };
|
|
212
|
+
|
|
213
|
+
it('saves the file as a draft exactly as written (html untouched) and opens it in the inbox viewer, never approving', async () => {
|
|
214
|
+
createReply = () => {
|
|
215
|
+
const d = draft({ id: 'f-1', program_key: 'announcement', ...email, window: [] as any, item_keys: [] });
|
|
216
|
+
drafts.push(d);
|
|
217
|
+
return HttpResponse.json(d, { status: 201 });
|
|
218
|
+
};
|
|
219
|
+
const { user, region } = await openFold();
|
|
220
|
+
await user.upload(within(region).getByLabelText(/load an email from a file/i), file(JSON.stringify(email)));
|
|
221
|
+
await waitFor(() => expect(posts()).toHaveLength(1));
|
|
222
|
+
expect(posts()[0].body).toEqual(email);
|
|
223
|
+
expect(await screen.findByTitle(/email preview/i)).toBeInTheDocument();
|
|
224
|
+
expect(screen.getByRole('group', { name: /inbox row/i })).toBeInTheDocument();
|
|
225
|
+
expect(hits.filter((h) => h.path.includes('approve') || h.path.includes('test'))).toEqual([]);
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
it('refuses a file that is not an email, and saves nothing', async () => {
|
|
229
|
+
const { user, region } = await openFold();
|
|
230
|
+
await user.upload(within(region).getByLabelText(/load an email from a file/i), file('{"hello":1}'));
|
|
231
|
+
expect(await within(region).findByText(/needs a subject and html/i)).toBeInTheDocument();
|
|
232
|
+
expect(posts()).toHaveLength(0);
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
it('refuses a file that is not JSON', async () => {
|
|
236
|
+
const { user, region } = await openFold();
|
|
237
|
+
await user.upload(within(region).getByLabelText(/load an email from a file/i), file('not json'));
|
|
238
|
+
expect(await within(region).findByText(/not valid JSON/i)).toBeInTheDocument();
|
|
239
|
+
expect(posts()).toHaveLength(0);
|
|
240
|
+
});
|
|
241
|
+
});
|
|
186
242
|
});
|
|
@@ -241,7 +241,7 @@ describe('overview (A1)', () => {
|
|
|
241
241
|
await comebackSwitch();
|
|
242
242
|
for (const name of [
|
|
243
243
|
/^comeback sequence settings$/i, /^product updates$/i, /^approval$/i,
|
|
244
|
-
/^voice$/i, /^sending domain$/i, /^results$/i, /^send log$/i,
|
|
244
|
+
/^voice$/i, /^time zone$/i, /^sending domain$/i, /^results$/i, /^send log$/i,
|
|
245
245
|
]) {
|
|
246
246
|
expect(screen.getByRole('button', { name })).toHaveAttribute('aria-expanded', 'false');
|
|
247
247
|
}
|
|
@@ -354,11 +354,11 @@ describe('comeback sequence settings (A2)', () => {
|
|
|
354
354
|
const step2 = within(fold).getAllByRole('listitem')[1];
|
|
355
355
|
await userEvent.click(within(step2).getByRole('button', { name: /^preview$/i }));
|
|
356
356
|
await waitFor(() => expect(hits.some((h) => h.method === 'GET' && h.path === '/programs/comeback/steps/1/preview/')).toBe(true));
|
|
357
|
-
const frame = await
|
|
357
|
+
const frame = await screen.findByTitle(/email preview/i);
|
|
358
358
|
expect(frame.tagName).toBe('IFRAME');
|
|
359
359
|
expect(frame.getAttribute('srcdoc')).toContain('<p>Hi Quinn, step 1</p>');
|
|
360
360
|
expect(frame.hasAttribute('sandbox')).toBe(true);
|
|
361
|
-
expect(
|
|
361
|
+
expect(screen.getAllByText('Preview subject 1')).toHaveLength(1);
|
|
362
362
|
});
|
|
363
363
|
|
|
364
364
|
it('sends a test of a step to the admin only, on click', async () => {
|
|
@@ -546,14 +546,58 @@ describe('draft review (A4)', () => {
|
|
|
546
546
|
it('previews a draft as the SERVER rendered it (G2), in a sandboxed iframe', async () => {
|
|
547
547
|
renderPage();
|
|
548
548
|
const fold = await openFold(/^product updates$/i);
|
|
549
|
-
await userEvent.click(await within(fold).findByRole('button', { name: /^preview$/i }));
|
|
549
|
+
await userEvent.click(await within(fold).findByRole('button', { name: /^preview as inbox$/i }));
|
|
550
550
|
await waitFor(() => expect(hits.some((h) => h.method === 'GET' && h.path === '/drafts/d-1/preview/')).toBe(true));
|
|
551
|
-
const frame = await
|
|
551
|
+
const frame = await screen.findByTitle(/email preview/i);
|
|
552
552
|
expect(frame.getAttribute('srcdoc')).toContain('<p>Hi Quinn, New: stitch counter</p>');
|
|
553
553
|
expect(frame.hasAttribute('sandbox')).toBe(true);
|
|
554
554
|
expect(writes()).toEqual([]);
|
|
555
555
|
});
|
|
556
556
|
|
|
557
|
+
describe('inbox viewer', () => {
|
|
558
|
+
async function openViewer() {
|
|
559
|
+
renderPage();
|
|
560
|
+
const fold = await openFold(/^product updates$/i);
|
|
561
|
+
await userEvent.click(await within(fold).findByRole('button', { name: /^preview as inbox$/i }));
|
|
562
|
+
const frame = await screen.findByTitle(/email preview/i);
|
|
563
|
+
return { frame };
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
it('shows the inbox row: sender name, subject once, and the preheader snippet', async () => {
|
|
567
|
+
await openViewer();
|
|
568
|
+
const row = screen.getByRole('group', { name: /inbox row/i });
|
|
569
|
+
expect(within(row).getByText('Crochets')).toBeInTheDocument();
|
|
570
|
+
expect(screen.getAllByText('Rendered: New: stitch counter')).toHaveLength(1);
|
|
571
|
+
expect(within(row).getByText(/Count rows hands-free/)).toBeInTheDocument();
|
|
572
|
+
});
|
|
573
|
+
|
|
574
|
+
it('switches the rendered email between desktop (700px) and mobile (375px) width', async () => {
|
|
575
|
+
const { frame } = await openViewer();
|
|
576
|
+
expect(screen.getByRole('button', { name: /^desktop$/i })).toHaveAttribute('aria-pressed', 'true');
|
|
577
|
+
expect(frame.style.width).toBe('700px');
|
|
578
|
+
await userEvent.click(screen.getByRole('button', { name: /^mobile$/i }));
|
|
579
|
+
expect(screen.getByRole('button', { name: /^mobile$/i })).toHaveAttribute('aria-pressed', 'true');
|
|
580
|
+
expect(frame.style.width).toBe('375px');
|
|
581
|
+
expect(frame.getAttribute('srcdoc')).toContain('<p>Hi Quinn, New: stitch counter</p>');
|
|
582
|
+
});
|
|
583
|
+
|
|
584
|
+
it('shows the plain-text version, and goes back to the email', async () => {
|
|
585
|
+
await openViewer();
|
|
586
|
+
await userEvent.click(screen.getByRole('button', { name: /^plain text$/i }));
|
|
587
|
+
expect(screen.queryByTitle(/email preview/i)).toBeNull();
|
|
588
|
+
expect(screen.getByText('Stitch counter', { selector: 'pre' })).toBeInTheDocument();
|
|
589
|
+
await userEvent.click(screen.getByRole('button', { name: /^email$/i }));
|
|
590
|
+
expect(screen.getByTitle(/email preview/i)).toBeInTheDocument();
|
|
591
|
+
});
|
|
592
|
+
|
|
593
|
+
it('never writes: viewing is read-only', async () => {
|
|
594
|
+
await openViewer();
|
|
595
|
+
await userEvent.click(screen.getByRole('button', { name: /^mobile$/i }));
|
|
596
|
+
await userEvent.click(screen.getByRole('button', { name: /^plain text$/i }));
|
|
597
|
+
expect(writes()).toEqual([]);
|
|
598
|
+
});
|
|
599
|
+
});
|
|
600
|
+
|
|
557
601
|
it('a draft whose writing failed offers only Discard', async () => {
|
|
558
602
|
db.drafts = [draft({ subject: '', error: 'generation_failed' })];
|
|
559
603
|
renderPage();
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The email viewer (bd startsim-uwiw6.4): previewing an email is ONE page-sized
|
|
3
|
+
* thing, not a panel nested inside a fold inside a list card.
|
|
4
|
+
*
|
|
5
|
+
* - a back link, one slim toolbar (Desktop | Mobile, Email | Plain text), the inbox row
|
|
6
|
+
* (sender, subject, preheader) and the email in a single frame;
|
|
7
|
+
* - the subject appears once; the sender is the foundry's sender name, else the
|
|
8
|
+
* foundry's own name, never the literal "Sender";
|
|
9
|
+
* - plain text wraps on words and keeps line breaks;
|
|
10
|
+
* - the html is the server's render in a sandboxed frame (no scripts);
|
|
11
|
+
* - with a host-provided link target, "Preview as inbox" / step "Preview" are links to it.
|
|
12
|
+
*/
|
|
13
|
+
import * as React from 'react';
|
|
14
|
+
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it } from 'vitest';
|
|
15
|
+
import { render, screen, within } from '@testing-library/react';
|
|
16
|
+
import userEvent from '@testing-library/user-event';
|
|
17
|
+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
|
18
|
+
import { http, HttpResponse } from 'msw';
|
|
19
|
+
import { setupServer } from 'msw/node';
|
|
20
|
+
|
|
21
|
+
import { EmailPreview } from '../components/EmailPreview';
|
|
22
|
+
import { EmailPreviewPage, parsePreviewItemId, previewItemId } from '../components/EmailPreviewPage';
|
|
23
|
+
import { CustomerEmailsPage } from '../components/pages/CustomerEmailsPage';
|
|
24
|
+
import { createCommsApi, setApiBase } from '../api/index';
|
|
25
|
+
import type { CommsSettings } from '../types/index';
|
|
26
|
+
import { BASE, P, SLUG, comeback, draft, productUpdate, settings } from './fixtures';
|
|
27
|
+
|
|
28
|
+
const email = {
|
|
29
|
+
subject: 'Meet the engine',
|
|
30
|
+
preheader: 'Faster, steadier patterns',
|
|
31
|
+
html: '<h1>Hi</h1>',
|
|
32
|
+
text: 'Line one is a supercalifragilisticexpialidocious_unbrokenword_that_must_not_split\nLine two',
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
describe('EmailPreview (the viewer itself)', () => {
|
|
36
|
+
const view = (over = {}) =>
|
|
37
|
+
render(<EmailPreview email={email} sender={{ name: 'Crochets', address: 'crochets@mail.test' }} backHref="/back" backLabel="Back to Customer emails" {...over} />);
|
|
38
|
+
|
|
39
|
+
it('has a back link, a slim toolbar and the inbox row, in one frame', () => {
|
|
40
|
+
view();
|
|
41
|
+
expect(screen.getByRole('link', { name: /back to customer emails/i })).toHaveAttribute('href', '/back');
|
|
42
|
+
expect(screen.getByRole('button', { name: /^desktop$/i })).toHaveAttribute('aria-pressed', 'true');
|
|
43
|
+
expect(screen.getByRole('button', { name: /^mobile$/i })).toBeInTheDocument();
|
|
44
|
+
expect(screen.getByRole('button', { name: /^email$/i })).toBeInTheDocument();
|
|
45
|
+
expect(screen.getByRole('button', { name: /^plain text$/i })).toBeInTheDocument();
|
|
46
|
+
expect(screen.getAllByTitle(/email preview/i)).toHaveLength(1);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('shows the subject once, with the sender and preheader on the inbox row', () => {
|
|
50
|
+
view();
|
|
51
|
+
expect(screen.getAllByText('Meet the engine')).toHaveLength(1);
|
|
52
|
+
const row = screen.getByRole('group', { name: /inbox row/i });
|
|
53
|
+
expect(within(row).getByText('Crochets')).toBeInTheDocument();
|
|
54
|
+
expect(within(row).getByText('Meet the engine')).toBeInTheDocument();
|
|
55
|
+
expect(within(row).getByText(/Faster, steadier patterns/)).toBeInTheDocument();
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('never prints the literal "Sender"', () => {
|
|
59
|
+
view({ sender: { name: '' } });
|
|
60
|
+
expect(screen.queryByText(/^sender$/i)).toBeNull();
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('lays the email out at 700px on desktop and 375px on mobile', async () => {
|
|
64
|
+
view();
|
|
65
|
+
const frame = screen.getByTitle(/email preview/i);
|
|
66
|
+
expect(frame.style.width).toBe('700px');
|
|
67
|
+
await userEvent.click(screen.getByRole('button', { name: /^mobile$/i }));
|
|
68
|
+
expect(screen.getByTitle(/email preview/i).style.width).toBe('375px');
|
|
69
|
+
expect(screen.getByTitle(/email preview/i).getAttribute('srcdoc')).toBe('<h1>Hi</h1>');
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('runs no scripts in the frame and has no internal scroll box', () => {
|
|
73
|
+
view();
|
|
74
|
+
const frame = screen.getByTitle(/email preview/i);
|
|
75
|
+
expect(frame.getAttribute('sandbox') ?? '').not.toMatch(/allow-scripts/);
|
|
76
|
+
expect(frame.getAttribute('scrolling')).toBe('no');
|
|
77
|
+
expect(frame.className).not.toMatch(/h-\[720px\]/);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('wraps plain text on words (not mid-word) and keeps its line breaks', async () => {
|
|
81
|
+
view();
|
|
82
|
+
await userEvent.click(screen.getByRole('button', { name: /^plain text$/i }));
|
|
83
|
+
expect(screen.queryByTitle(/email preview/i)).toBeNull();
|
|
84
|
+
const pre = screen.getByText(/Line one is/, { selector: 'pre' });
|
|
85
|
+
expect(pre.className).toMatch(/whitespace-pre-wrap/);
|
|
86
|
+
expect(pre.className).not.toMatch(/break-all/);
|
|
87
|
+
expect(pre.textContent).toContain('\nLine two');
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('calls onBack from the back link when given, without following the href', async () => {
|
|
91
|
+
let back = 0;
|
|
92
|
+
view({ onBack: () => { back += 1; } });
|
|
93
|
+
await userEvent.click(screen.getByRole('link', { name: /back to customer emails/i }));
|
|
94
|
+
expect(back).toBe(1);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
// ---- the page: fetches the server render + the sender ------------------------------------------
|
|
99
|
+
|
|
100
|
+
interface Hit { method: string; path: string }
|
|
101
|
+
let hits: Hit[] = [];
|
|
102
|
+
let sets: CommsSettings;
|
|
103
|
+
const rel = (p: string) => p.replace(new URL(P).pathname, '');
|
|
104
|
+
|
|
105
|
+
const server = setupServer(
|
|
106
|
+
http.all(`${P}/*`, ({ request }) => {
|
|
107
|
+
const path = rel(new URL(request.url).pathname);
|
|
108
|
+
hits.push({ method: request.method, path });
|
|
109
|
+
if (path === '/settings/') return HttpResponse.json(sets);
|
|
110
|
+
if (path === '/programs/') return HttpResponse.json([comeback(), productUpdate()]);
|
|
111
|
+
if (path === '/drafts/d-1/preview/') return HttpResponse.json({ subject: 'Rendered subject', preheader: 'Rendered pre', html: '<p>server html</p>', text: 'plain' });
|
|
112
|
+
if (path === '/programs/comeback/steps/1/preview/') return HttpResponse.json({ subject: 'Step subject', preheader: '', html: '<p>step html</p>', text: 'step plain' });
|
|
113
|
+
if (path === '/drafts/') {
|
|
114
|
+
const pending = new URL(request.url).searchParams.get('status') === 'pending';
|
|
115
|
+
return HttpResponse.json({ count: pending ? 1 : 0, next: null, previous: null, results: pending ? [draft()] : [] });
|
|
116
|
+
}
|
|
117
|
+
return HttpResponse.json({});
|
|
118
|
+
}),
|
|
119
|
+
);
|
|
120
|
+
beforeAll(() => {
|
|
121
|
+
server.listen({ onUnhandledRequest: 'error' });
|
|
122
|
+
setApiBase(`${BASE}/api/v1`);
|
|
123
|
+
});
|
|
124
|
+
afterAll(() => server.close());
|
|
125
|
+
beforeEach(() => {
|
|
126
|
+
hits = [];
|
|
127
|
+
sets = settings();
|
|
128
|
+
});
|
|
129
|
+
afterEach(() => server.resetHandlers());
|
|
130
|
+
|
|
131
|
+
const qc = () => new QueryClient({ defaultOptions: { queries: { retry: false } } });
|
|
132
|
+
const pageFor = (itemId: string, props = {}) =>
|
|
133
|
+
render(
|
|
134
|
+
<QueryClientProvider client={qc()}>
|
|
135
|
+
<EmailPreviewPage api={createCommsApi(SLUG)} itemId={itemId} fallbackSenderName="Crochets Foundry" backHref="/foundry/crochets/customer-emails" {...props} />
|
|
136
|
+
</QueryClientProvider>,
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
describe('EmailPreviewPage', () => {
|
|
140
|
+
it('previews a draft as the SERVER rendered it, never writing', async () => {
|
|
141
|
+
pageFor('d-1');
|
|
142
|
+
const frame = await screen.findByTitle(/email preview/i);
|
|
143
|
+
expect(frame.getAttribute('srcdoc')).toBe('<p>server html</p>');
|
|
144
|
+
expect(screen.getAllByText('Rendered subject')).toHaveLength(1);
|
|
145
|
+
expect(hits.filter((h) => h.method !== 'GET')).toEqual([]);
|
|
146
|
+
expect(screen.getByRole('link', { name: /back/i })).toHaveAttribute('href', '/foundry/crochets/customer-emails');
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it('previews a comeback step from its item id', async () => {
|
|
150
|
+
pageFor('step.comeback.1');
|
|
151
|
+
expect((await screen.findByTitle(/email preview/i)).getAttribute('srcdoc')).toBe('<p>step html</p>');
|
|
152
|
+
expect(hits.some((h) => h.path === '/programs/comeback/steps/1/preview/')).toBe(true);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it('shows the configured sender name', async () => {
|
|
156
|
+
pageFor('d-1');
|
|
157
|
+
await screen.findByTitle(/email preview/i);
|
|
158
|
+
expect(within(screen.getByRole('group', { name: /inbox row/i })).getByText('Crochets')).toBeInTheDocument();
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it('with no sender configured, falls back to the foundry name, never "Sender"', async () => {
|
|
162
|
+
sets = settings({ sender_name: '', from_address: null });
|
|
163
|
+
pageFor('d-1');
|
|
164
|
+
await screen.findByTitle(/email preview/i);
|
|
165
|
+
const row = screen.getByRole('group', { name: /inbox row/i });
|
|
166
|
+
expect(within(row).getByText('Crochets Foundry')).toBeInTheDocument();
|
|
167
|
+
expect(screen.queryByText(/^sender$/i)).toBeNull();
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it('uses the name part of a Name <address> from line when only that is configured', async () => {
|
|
171
|
+
sets = settings({ sender_name: '', from_address: 'Acme Co <hi@mail.acme.test>' });
|
|
172
|
+
pageFor('d-1');
|
|
173
|
+
await screen.findByTitle(/email preview/i);
|
|
174
|
+
expect(within(screen.getByRole('group', { name: /inbox row/i })).getByText('Acme Co')).toBeInTheDocument();
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
describe('preview item ids', () => {
|
|
179
|
+
it('round-trips a draft and a step', () => {
|
|
180
|
+
expect(parsePreviewItemId('d-1')).toEqual({ kind: 'draft', id: 'd-1' });
|
|
181
|
+
expect(previewItemId({ kind: 'draft', id: 'd-1' })).toBe('d-1');
|
|
182
|
+
expect(parsePreviewItemId('step.comeback.2')).toEqual({ kind: 'step', programKey: 'comeback', index: 2 });
|
|
183
|
+
expect(previewItemId({ kind: 'step', programKey: 'comeback', index: 2 })).toBe('step.comeback.2');
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
// ---- the launch points -----------------------------------------------------------------
|
|
188
|
+
|
|
189
|
+
describe('launching the viewer from the Customer emails page', () => {
|
|
190
|
+
const mountPage = (props = {}) =>
|
|
191
|
+
render(
|
|
192
|
+
<QueryClientProvider client={qc()}>
|
|
193
|
+
<CustomerEmailsPage api={createCommsApi(SLUG)} foundrySlug={SLUG} pollIntervalMs={10} {...props} />
|
|
194
|
+
</QueryClientProvider>,
|
|
195
|
+
);
|
|
196
|
+
const open = async (name: RegExp) => {
|
|
197
|
+
await userEvent.click(await screen.findByRole('button', { name }));
|
|
198
|
+
return screen.findByRole('region', { name });
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
it('with a viewer link target, a draft "Preview as inbox" is a link to it and fetches no preview', async () => {
|
|
202
|
+
mountPage({ viewerHref: (id: string) => `/foundry/${SLUG}/customer-emails/${id}/preview` });
|
|
203
|
+
const fold = await open(/^product updates$/i);
|
|
204
|
+
const link = await within(fold).findByRole('link', { name: /^preview as inbox$/i });
|
|
205
|
+
expect(link).toHaveAttribute('href', `/foundry/${SLUG}/customer-emails/d-1/preview`);
|
|
206
|
+
expect(hits.some((h) => h.path.includes('/preview/'))).toBe(false);
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
it('with a viewer link target, a comeback step "Preview" links to the same viewer', async () => {
|
|
210
|
+
mountPage({ viewerHref: (id: string) => `/v/${id}` });
|
|
211
|
+
const fold = await open(/^comeback sequence settings$/i);
|
|
212
|
+
const step2 = within(fold).getAllByRole('listitem')[1];
|
|
213
|
+
expect(within(step2).getByRole('link', { name: /^preview$/i })).toHaveAttribute('href', '/v/step.comeback.1');
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
it('with an onOpenViewer handler, a click hands over the href instead of reloading', async () => {
|
|
217
|
+
const opened: string[] = [];
|
|
218
|
+
mountPage({ viewerHref: (id: string) => `/v/${id}`, onOpenViewer: (href: string) => opened.push(href) });
|
|
219
|
+
const fold = await open(/^product updates$/i);
|
|
220
|
+
await userEvent.click(await within(fold).findByRole('link', { name: /^preview as inbox$/i }));
|
|
221
|
+
expect(opened).toEqual(['/v/d-1']);
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
it('without a host link target, the button opens the same viewer full-viewport and Back closes it', async () => {
|
|
225
|
+
mountPage();
|
|
226
|
+
const fold = await open(/^product updates$/i);
|
|
227
|
+
await userEvent.click(await within(fold).findByRole('button', { name: /^preview as inbox$/i }));
|
|
228
|
+
const frame = await screen.findByTitle(/email preview/i);
|
|
229
|
+
expect(frame.closest('[data-email-viewer]')).not.toBeNull();
|
|
230
|
+
await userEvent.click(screen.getByRole('link', { name: /back/i }));
|
|
231
|
+
expect(screen.queryByTitle(/email preview/i)).toBeNull();
|
|
232
|
+
});
|
|
233
|
+
});
|
|
@@ -33,6 +33,7 @@ export const settings = (over: Partial<CommsSettings> = {}): CommsSettings => ({
|
|
|
33
33
|
domain_records: [],
|
|
34
34
|
domain_checked_at: null,
|
|
35
35
|
paused: false,
|
|
36
|
+
default_timezone: '',
|
|
36
37
|
source_repos: [],
|
|
37
38
|
from_address: 'Crochets <crochets@mail.startsimpli.com>',
|
|
38
39
|
...over,
|