@remit/ui 0.0.190 → 0.0.192
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 +1 -1
- package/src/components/account-service-choice.render.test.ts +152 -0
- package/src/components/account-service-choice.stories.tsx +122 -0
- package/src/components/account-service-choice.tsx +96 -0
- package/src/components/filter-rule.render.test.ts +10 -0
- package/src/components/filter-rule.ts +6 -4
- package/src/index.ts +6 -0
package/package.json
CHANGED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The onboarding service choice (#1178). Both services on is the caller's
|
|
3
|
+
* default, so what is asserted here is the choice's own contract: a provider
|
|
4
|
+
* that syncs one service renders no choice at all, the empty set is refused
|
|
5
|
+
* rather than submitted, and the re-consent line names the provider.
|
|
6
|
+
*/
|
|
7
|
+
import "@remit/test-dom";
|
|
8
|
+
import assert from "node:assert/strict";
|
|
9
|
+
import { describe, it } from "node:test";
|
|
10
|
+
import { act, createElement } from "react";
|
|
11
|
+
import { createRoot } from "react-dom/client";
|
|
12
|
+
import { renderToString } from "react-dom/server";
|
|
13
|
+
import {
|
|
14
|
+
ACCOUNT_SERVICE_EMPTY_MESSAGE,
|
|
15
|
+
type AccountService,
|
|
16
|
+
AccountServiceChoice,
|
|
17
|
+
type AccountServiceChoiceProps,
|
|
18
|
+
} from "./account-service-choice.js";
|
|
19
|
+
|
|
20
|
+
const bothServices: AccountService[] = ["Mail", "Calendar"];
|
|
21
|
+
|
|
22
|
+
const render = (props: Partial<AccountServiceChoiceProps> = {}): string =>
|
|
23
|
+
renderToString(
|
|
24
|
+
createElement(AccountServiceChoice, {
|
|
25
|
+
providerName: "Microsoft",
|
|
26
|
+
offered: bothServices,
|
|
27
|
+
selected: bothServices,
|
|
28
|
+
onChange: () => {},
|
|
29
|
+
...props,
|
|
30
|
+
}),
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
describe("AccountServiceChoice", () => {
|
|
34
|
+
it("offers mail and calendar, mail first", () => {
|
|
35
|
+
const html = render();
|
|
36
|
+
assert.match(html, /Mail/);
|
|
37
|
+
assert.match(html, /Calendar/);
|
|
38
|
+
assert.ok(html.indexOf("Mail") < html.indexOf("Calendar"));
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("ticks the services it is given and leaves the rest clear", () => {
|
|
42
|
+
const html = render({ selected: ["Calendar"] });
|
|
43
|
+
assert.equal(html.match(/checked=""/g)?.length, 1);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("ticks both when both are selected", () => {
|
|
47
|
+
assert.equal(render().match(/checked=""/g)?.length, 2);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("names the provider adding a service sends you back to", () => {
|
|
51
|
+
assert.match(
|
|
52
|
+
render(),
|
|
53
|
+
/Adding a service later means signing in with Microsoft again\./,
|
|
54
|
+
);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("renders nothing for a provider that only syncs mail", () => {
|
|
58
|
+
assert.equal(render({ offered: ["Mail"], selected: ["Mail"] }), "");
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("still shows the refusal when there are no rows to show", () => {
|
|
62
|
+
assert.match(
|
|
63
|
+
render({
|
|
64
|
+
offered: ["Mail"],
|
|
65
|
+
selected: [],
|
|
66
|
+
error: ACCOUNT_SERVICE_EMPTY_MESSAGE,
|
|
67
|
+
}),
|
|
68
|
+
/Pick at least one/,
|
|
69
|
+
);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("shows a refusal only when it is given one", () => {
|
|
73
|
+
assert.doesNotMatch(render({ selected: [] }), /Pick at least one/);
|
|
74
|
+
assert.match(
|
|
75
|
+
render({ selected: [], error: ACCOUNT_SERVICE_EMPTY_MESSAGE }),
|
|
76
|
+
/Pick at least one/,
|
|
77
|
+
);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("announces the refusal", () => {
|
|
81
|
+
assert.match(
|
|
82
|
+
render({ selected: [], error: ACCOUNT_SERVICE_EMPTY_MESSAGE }),
|
|
83
|
+
/role="alert"/,
|
|
84
|
+
);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("adds and removes one service at a time", () => {
|
|
88
|
+
const container = document.createElement("div");
|
|
89
|
+
document.body.appendChild(container);
|
|
90
|
+
const root = createRoot(container);
|
|
91
|
+
const changes: AccountService[][] = [];
|
|
92
|
+
|
|
93
|
+
act(() => {
|
|
94
|
+
root.render(
|
|
95
|
+
createElement(AccountServiceChoice, {
|
|
96
|
+
providerName: "Microsoft",
|
|
97
|
+
offered: bothServices,
|
|
98
|
+
selected: bothServices,
|
|
99
|
+
onChange: (next) => changes.push(next),
|
|
100
|
+
}),
|
|
101
|
+
);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
const boxes = container.querySelectorAll<HTMLInputElement>(
|
|
105
|
+
'input[type="checkbox"]',
|
|
106
|
+
);
|
|
107
|
+
act(() => {
|
|
108
|
+
boxes[1]?.click();
|
|
109
|
+
});
|
|
110
|
+
act(() => {
|
|
111
|
+
boxes[0]?.click();
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
assert.deepEqual(changes, [["Mail"], ["Calendar"]]);
|
|
115
|
+
|
|
116
|
+
act(() => {
|
|
117
|
+
root.unmount();
|
|
118
|
+
});
|
|
119
|
+
container.remove();
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it("restores a service in the stored order", () => {
|
|
123
|
+
const container = document.createElement("div");
|
|
124
|
+
document.body.appendChild(container);
|
|
125
|
+
const root = createRoot(container);
|
|
126
|
+
const changes: AccountService[][] = [];
|
|
127
|
+
|
|
128
|
+
act(() => {
|
|
129
|
+
root.render(
|
|
130
|
+
createElement(AccountServiceChoice, {
|
|
131
|
+
providerName: "Microsoft",
|
|
132
|
+
offered: bothServices,
|
|
133
|
+
selected: ["Calendar"],
|
|
134
|
+
onChange: (next) => changes.push(next),
|
|
135
|
+
}),
|
|
136
|
+
);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
act(() => {
|
|
140
|
+
container
|
|
141
|
+
.querySelector<HTMLInputElement>('input[type="checkbox"]')
|
|
142
|
+
?.click();
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
assert.deepEqual(changes, [["Mail", "Calendar"]]);
|
|
146
|
+
|
|
147
|
+
act(() => {
|
|
148
|
+
root.unmount();
|
|
149
|
+
});
|
|
150
|
+
container.remove();
|
|
151
|
+
});
|
|
152
|
+
});
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/react-vite";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import { expect, userEvent, within } from "storybook/test";
|
|
4
|
+
import {
|
|
5
|
+
ACCOUNT_SERVICE_EMPTY_MESSAGE,
|
|
6
|
+
type AccountService,
|
|
7
|
+
AccountServiceChoice,
|
|
8
|
+
} from "./account-service-choice.js";
|
|
9
|
+
import { Button } from "./button.js";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* What an account syncs, asked once before the provider redirect so the
|
|
13
|
+
* consent screen matches the pick (#1178).
|
|
14
|
+
*/
|
|
15
|
+
const meta: Meta<typeof AccountServiceChoice> = {
|
|
16
|
+
title: "Components/AccountServiceChoice",
|
|
17
|
+
component: AccountServiceChoice,
|
|
18
|
+
parameters: { layout: "padded" },
|
|
19
|
+
decorators: [
|
|
20
|
+
(Story) => (
|
|
21
|
+
<div className="mx-auto max-w-sm rounded-xl border border-line bg-surface p-4">
|
|
22
|
+
<Story />
|
|
23
|
+
</div>
|
|
24
|
+
),
|
|
25
|
+
],
|
|
26
|
+
};
|
|
27
|
+
export default meta;
|
|
28
|
+
|
|
29
|
+
type Story = StoryObj<typeof AccountServiceChoice>;
|
|
30
|
+
|
|
31
|
+
const bothServices: AccountService[] = ["Mail", "Calendar"];
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Stands in for the host: the refusal appears on a refused Continue, the way
|
|
35
|
+
* the onboarding step raises it, not the moment the set goes empty.
|
|
36
|
+
*/
|
|
37
|
+
function LiveChoice({
|
|
38
|
+
initial,
|
|
39
|
+
offered = bothServices,
|
|
40
|
+
}: {
|
|
41
|
+
initial: AccountService[];
|
|
42
|
+
offered?: AccountService[];
|
|
43
|
+
}) {
|
|
44
|
+
const [selected, setSelected] = useState(initial);
|
|
45
|
+
const [refused, setRefused] = useState(false);
|
|
46
|
+
const empty = selected.length === 0;
|
|
47
|
+
return (
|
|
48
|
+
<div className="space-y-3">
|
|
49
|
+
<AccountServiceChoice
|
|
50
|
+
providerName="Microsoft"
|
|
51
|
+
offered={offered}
|
|
52
|
+
selected={selected}
|
|
53
|
+
onChange={setSelected}
|
|
54
|
+
error={refused && empty ? ACCOUNT_SERVICE_EMPTY_MESSAGE : undefined}
|
|
55
|
+
/>
|
|
56
|
+
<Button variant="primary" onClick={() => setRefused(empty)}>
|
|
57
|
+
Continue
|
|
58
|
+
</Button>
|
|
59
|
+
</div>
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** A provider that syncs both. Both on is the default a host arrives with. */
|
|
64
|
+
export const BothServices: Story = {
|
|
65
|
+
render: () => <LiveChoice initial={bothServices} />,
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/** Calendar only — the Outlook account kept for its calendar and nothing else. */
|
|
69
|
+
export const CalendarOnly: Story = {
|
|
70
|
+
render: () => <LiveChoice initial={["Calendar"]} />,
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Neither ticked. Continue says what is wrong instead of going quiet, and its
|
|
75
|
+
* host refuses to submit the empty set.
|
|
76
|
+
*/
|
|
77
|
+
export const NeitherSelected: Story = {
|
|
78
|
+
render: () => <LiveChoice initial={[]} />,
|
|
79
|
+
play: async ({ canvasElement }) => {
|
|
80
|
+
const canvas = within(canvasElement);
|
|
81
|
+
await expect(canvas.queryByRole("alert")).toBeNull();
|
|
82
|
+
await userEvent.click(canvas.getByRole("button", { name: "Continue" }));
|
|
83
|
+
await expect(canvas.getByRole("alert")).toHaveTextContent(
|
|
84
|
+
"Pick at least one",
|
|
85
|
+
);
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* A provider that only syncs mail. The rows are absent, not a disabled row —
|
|
91
|
+
* the border below is the whole render.
|
|
92
|
+
*/
|
|
93
|
+
export const MailOnlyProvider: Story = {
|
|
94
|
+
render: () => (
|
|
95
|
+
<>
|
|
96
|
+
<AccountServiceChoice
|
|
97
|
+
providerName="Microsoft"
|
|
98
|
+
offered={["Mail"]}
|
|
99
|
+
selected={["Mail"]}
|
|
100
|
+
onChange={() => {}}
|
|
101
|
+
/>
|
|
102
|
+
<p className="border-t border-line pt-2 text-2xs text-fg-subtle">
|
|
103
|
+
Nothing above this line: an IMAP account syncs mail and is not asked.
|
|
104
|
+
</p>
|
|
105
|
+
</>
|
|
106
|
+
),
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* One service on offer and none picked. There is nothing to tick, so the
|
|
111
|
+
* refusal is the whole render — the host's Continue must not go quiet.
|
|
112
|
+
*/
|
|
113
|
+
export const MailOnlyProviderRefused: Story = {
|
|
114
|
+
render: () => <LiveChoice initial={[]} offered={["Mail"]} />,
|
|
115
|
+
play: async ({ canvasElement }) => {
|
|
116
|
+
const canvas = within(canvasElement);
|
|
117
|
+
await userEvent.click(canvas.getByRole("button", { name: "Continue" }));
|
|
118
|
+
await expect(canvas.getByRole("alert")).toHaveTextContent(
|
|
119
|
+
"Pick at least one",
|
|
120
|
+
);
|
|
121
|
+
},
|
|
122
|
+
};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { useId } from "react";
|
|
2
|
+
import { Banner } from "./banner.js";
|
|
3
|
+
import { Checkbox } from "./checkbox.js";
|
|
4
|
+
|
|
5
|
+
/** One service an account syncs. Mirrors the set the account endpoints take. */
|
|
6
|
+
export type AccountService = "Mail" | "Calendar";
|
|
7
|
+
|
|
8
|
+
/** Refusal for the empty set: no stored account ever syncs nothing. */
|
|
9
|
+
export const ACCOUNT_SERVICE_EMPTY_MESSAGE =
|
|
10
|
+
"Pick at least one. An account has to sync something.";
|
|
11
|
+
|
|
12
|
+
interface ServiceRow {
|
|
13
|
+
id: AccountService;
|
|
14
|
+
label: string;
|
|
15
|
+
description: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const SERVICE_ROWS: ServiceRow[] = [
|
|
19
|
+
{
|
|
20
|
+
id: "Mail",
|
|
21
|
+
label: "Mail",
|
|
22
|
+
description: "Messages, folders and sending.",
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
id: "Calendar",
|
|
26
|
+
label: "Calendar",
|
|
27
|
+
description: "This account's provider calendar, read into Remit.",
|
|
28
|
+
},
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
export interface AccountServiceChoiceProps {
|
|
32
|
+
/** Provider named in the re-consent line, e.g. "Microsoft". */
|
|
33
|
+
providerName: string;
|
|
34
|
+
/** Services this provider syncs. Under two of them the rows are absent. */
|
|
35
|
+
offered: AccountService[];
|
|
36
|
+
selected: AccountService[];
|
|
37
|
+
onChange: (next: AccountService[]) => void;
|
|
38
|
+
/** Refusal shown under the rows, e.g. ACCOUNT_SERVICE_EMPTY_MESSAGE. */
|
|
39
|
+
error?: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function AccountServiceChoice({
|
|
43
|
+
providerName,
|
|
44
|
+
offered,
|
|
45
|
+
selected,
|
|
46
|
+
onChange,
|
|
47
|
+
error,
|
|
48
|
+
}: AccountServiceChoiceProps) {
|
|
49
|
+
const noteId = useId();
|
|
50
|
+
const rows = SERVICE_ROWS.filter((row) => offered.includes(row.id));
|
|
51
|
+
|
|
52
|
+
const refusal = error ? (
|
|
53
|
+
<Banner tone="danger" variant="soft" className="mt-2 text-xs">
|
|
54
|
+
{error}
|
|
55
|
+
</Banner>
|
|
56
|
+
) : null;
|
|
57
|
+
|
|
58
|
+
// A single-service provider has nothing to choose, but its host can still
|
|
59
|
+
// refuse an empty set, and that refusal has to land somewhere.
|
|
60
|
+
if (rows.length < 2) return refusal;
|
|
61
|
+
|
|
62
|
+
const toggle = (id: AccountService, checked: boolean) => {
|
|
63
|
+
if (!checked) {
|
|
64
|
+
onChange(selected.filter((service) => service !== id));
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
onChange(
|
|
68
|
+
rows
|
|
69
|
+
.filter((row) => row.id === id || selected.includes(row.id))
|
|
70
|
+
.map((row) => row.id),
|
|
71
|
+
);
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
return (
|
|
75
|
+
<fieldset aria-describedby={noteId}>
|
|
76
|
+
<legend className="text-sm font-semibold text-fg">
|
|
77
|
+
What should Remit sync?
|
|
78
|
+
</legend>
|
|
79
|
+
<div className="mt-1 divide-y divide-line">
|
|
80
|
+
{rows.map((row) => (
|
|
81
|
+
<Checkbox
|
|
82
|
+
key={row.id}
|
|
83
|
+
label={row.label}
|
|
84
|
+
description={row.description}
|
|
85
|
+
checked={selected.includes(row.id)}
|
|
86
|
+
onChange={(event) => toggle(row.id, event.target.checked)}
|
|
87
|
+
/>
|
|
88
|
+
))}
|
|
89
|
+
</div>
|
|
90
|
+
<p id={noteId} className="mt-1.5 text-2xs text-fg-subtle">
|
|
91
|
+
{`Adding a service later means signing in with ${providerName} again.`}
|
|
92
|
+
</p>
|
|
93
|
+
{refusal}
|
|
94
|
+
</fieldset>
|
|
95
|
+
);
|
|
96
|
+
}
|
|
@@ -445,6 +445,16 @@ describe("FilterPreviewCount", () => {
|
|
|
445
445
|
assert.doesNotMatch(html, /role="alert"/);
|
|
446
446
|
});
|
|
447
447
|
|
|
448
|
+
it("does not mark the empty-index line as recounting", () => {
|
|
449
|
+
const html = render(
|
|
450
|
+
createElement(FilterPreviewCount, {
|
|
451
|
+
preview: { status: "ready", count: 0, stale: true, indexEmpty: true },
|
|
452
|
+
}),
|
|
453
|
+
);
|
|
454
|
+
assert.match(html, /Still indexing/);
|
|
455
|
+
assert.doesNotMatch(html, /recounting/);
|
|
456
|
+
});
|
|
457
|
+
|
|
448
458
|
it("counts many matches", () => {
|
|
449
459
|
const html = render(
|
|
450
460
|
createElement(FilterPreviewCount, {
|
|
@@ -230,10 +230,12 @@ export function matchJoinWord(operator: MatchOperator): string {
|
|
|
230
230
|
export function previewCountSummary(preview: PreviewCount): string {
|
|
231
231
|
if (preview.status === "loading") return "Counting matches…";
|
|
232
232
|
if (preview.status === "error") return preview.reason;
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
233
|
+
// An index with nothing in it counted nothing, so there is no count to mark
|
|
234
|
+
// as recounting. The sentence is about the index, not about the rule, and it
|
|
235
|
+
// reads the same whichever predicate is on screen.
|
|
236
|
+
if (preview.indexEmpty)
|
|
237
|
+
return "Still indexing — nothing to match against yet";
|
|
238
|
+
if (preview.count === 0) return "No mail matches yet";
|
|
237
239
|
const noun = preview.count === 1 ? "message" : "messages";
|
|
238
240
|
const base = `${preview.count} ${noun} match`;
|
|
239
241
|
return preview.stale ? `${base} — recounting` : base;
|
package/src/index.ts
CHANGED
|
@@ -16,6 +16,12 @@ export {
|
|
|
16
16
|
isThreadCategory,
|
|
17
17
|
type ThreadCategory,
|
|
18
18
|
} from "./category-presentation.js";
|
|
19
|
+
export {
|
|
20
|
+
ACCOUNT_SERVICE_EMPTY_MESSAGE,
|
|
21
|
+
type AccountService,
|
|
22
|
+
AccountServiceChoice,
|
|
23
|
+
type AccountServiceChoiceProps,
|
|
24
|
+
} from "./components/account-service-choice.js";
|
|
19
25
|
export {
|
|
20
26
|
AddressDisplay,
|
|
21
27
|
type AddressDisplayProps,
|