test: pin four cases the reviews of the stack left unpinned
Non-blocking suggestions of the independent reviews of PRs #490 to #493, applied in a follow-up link above #493 (Max's decision of 2026-10-24): - locales.keys.test.ts: a variable name that differs by its case only is a gap (`{{version}}` against `{{Version}}`, review 27037, H8); the header says that `{{- name}}` and `{{name}}` render alike with `escapeValue: false`. - db.test.ts: a `)` glued to a word ends no path (`C:\Users\jean\Projet(2024)final\x.db`, review 27073, R10). - TemplateActions.delete.test.ts: three templates, the middle one deleted, so a handler bound to the first or the last fails (review 27088, R11). - ProfileSwitcher.wiring.test.ts: a locked profile that has a PIN opens the upsell, never the PIN entry; in Base it asks for the PIN (review 27084, R5). - elementTree.ts: an absence is proved with `find`, never with `holding` (review 27088, S2). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
67e51e08b6
commit
41f3b15f4d
5 changed files with 53 additions and 11 deletions
|
|
@ -32,6 +32,7 @@ const harness = hookHarness();
|
||||||
|
|
||||||
const SUMMER: BudgetTemplate = { id: 4, name: "Été", created_at: "" };
|
const SUMMER: BudgetTemplate = { id: 4, name: "Été", created_at: "" };
|
||||||
const WINTER: BudgetTemplate = { id: 9, name: "Hiver", created_at: "" };
|
const WINTER: BudgetTemplate = { id: 9, name: "Hiver", created_at: "" };
|
||||||
|
const SPRING: BudgetTemplate = { id: 6, name: "Printemps", created_at: "" };
|
||||||
|
|
||||||
const CONFIRM = "t(budget.deleteTemplateConfirm)";
|
const CONFIRM = "t(budget.deleteTemplateConfirm)";
|
||||||
|
|
||||||
|
|
@ -41,7 +42,7 @@ let onDelete = vi.fn<(templateId: number) => void>();
|
||||||
const render = () =>
|
const render = () =>
|
||||||
harness.render(() =>
|
harness.render(() =>
|
||||||
TemplateActions({
|
TemplateActions({
|
||||||
templates: [SUMMER, WINTER],
|
templates: [SUMMER, WINTER, SPRING],
|
||||||
onApply: vi.fn(),
|
onApply: vi.fn(),
|
||||||
onApplyAllMonths: vi.fn(),
|
onApplyAllMonths: vi.fn(),
|
||||||
onSave: vi.fn(),
|
onSave: vi.fn(),
|
||||||
|
|
@ -60,13 +61,14 @@ function openList() {
|
||||||
type FakeEvent = { stopPropagation: ReturnType<typeof vi.fn> };
|
type FakeEvent = { stopPropagation: ReturnType<typeof vi.fn> };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clicks the delete button of the second template and waits for the handler.
|
* Clicks the delete button of the middle template of three and waits for the
|
||||||
* The event's propagation must stop before the answer: the click would
|
* handler: a handler bound to the first or to the last template would delete
|
||||||
* otherwise reach the row, which selects the template.
|
* another one. The event's propagation must stop before the answer: the click
|
||||||
|
* would otherwise reach the row, which selects the template.
|
||||||
*/
|
*/
|
||||||
async function clickDeleteOfWinter(): Promise<FakeEvent> {
|
async function clickDeleteOfWinter(): Promise<FakeEvent> {
|
||||||
const buttons = holding(openList(), Trash2);
|
const buttons = holding(openList(), Trash2);
|
||||||
expect(buttons).toHaveLength(2);
|
expect(buttons).toHaveLength(3);
|
||||||
const event: FakeEvent = { stopPropagation: vi.fn() };
|
const event: FakeEvent = { stopPropagation: vi.fn() };
|
||||||
const handled = (buttons[1].props.onClick as (e: FakeEvent) => Promise<void>)(event);
|
const handled = (buttons[1].props.onClick as (e: FakeEvent) => Promise<void>)(event);
|
||||||
expect(event.stopPropagation).toHaveBeenCalledTimes(1);
|
expect(event.stopPropagation).toHaveBeenCalledTimes(1);
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,9 @@
|
||||||
// switcher's hooks. No effect is run: `commit()` would add the switcher's
|
// switcher's hooks. No effect is run: `commit()` would add the switcher's
|
||||||
// mousedown listener to a `document` the node environment does not have.
|
// mousedown listener to a `document` the node environment does not have.
|
||||||
// UpsellDialog stays an element, never called: what it renders (UpsellGate,
|
// UpsellDialog stays an element, never called: what it renders (UpsellGate,
|
||||||
// Escape) is proved by UpsellDialog.render.test.tsx.
|
// Escape) is proved by UpsellDialog.render.test.tsx. A locked profile that has
|
||||||
|
// a PIN opens the dialog, never the PIN entry: the lock is checked first, or
|
||||||
|
// the right PIN would switch to a locked profile.
|
||||||
import { describe, it, expect, vi, beforeEach } from "vitest";
|
import { describe, it, expect, vi, beforeEach } from "vitest";
|
||||||
import type { ReactNode } from "react";
|
import type { ReactNode } from "react";
|
||||||
|
|
||||||
|
|
@ -21,6 +23,7 @@ const ctx = vi.hoisted(() => ({
|
||||||
profiles: [
|
profiles: [
|
||||||
{ id: "default", name: "Principal", color: "#4A90A4", pin_hash: null, db_filename: "simpl_resultat.db", created_at: "" },
|
{ id: "default", name: "Principal", color: "#4A90A4", pin_hash: null, db_filename: "simpl_resultat.db", created_at: "" },
|
||||||
{ id: "second", name: "Second", color: "#C17767", pin_hash: null, db_filename: "profile_second.db", created_at: "" },
|
{ id: "second", name: "Second", color: "#C17767", pin_hash: null, db_filename: "profile_second.db", created_at: "" },
|
||||||
|
{ id: "third", name: "Troisième", color: "#8E7CC3", pin_hash: "a-pin-hash", db_filename: "profile_third.db", created_at: "" },
|
||||||
],
|
],
|
||||||
/** What `useEntitlement("multi-profile")` returns: Free by default. */
|
/** What `useEntitlement("multi-profile")` returns: Free by default. */
|
||||||
gate: { allowed: false, ready: true },
|
gate: { allowed: false, ready: true },
|
||||||
|
|
@ -40,6 +43,7 @@ import { ChevronDown } from "lucide-react";
|
||||||
import { hookHarness } from "../../test/hookHarness";
|
import { hookHarness } from "../../test/hookHarness";
|
||||||
import { find, holding } from "../../test/elementTree";
|
import { find, holding } from "../../test/elementTree";
|
||||||
import ProfileSwitcher from "./ProfileSwitcher";
|
import ProfileSwitcher from "./ProfileSwitcher";
|
||||||
|
import PinDialog from "./PinDialog";
|
||||||
import UpsellDialog from "../shared/UpsellDialog";
|
import UpsellDialog from "../shared/UpsellDialog";
|
||||||
import UpsellGate from "../shared/UpsellGate";
|
import UpsellGate from "../shared/UpsellGate";
|
||||||
|
|
||||||
|
|
@ -61,6 +65,7 @@ const profileButtons = (tree: ReactNode, id: string) =>
|
||||||
|
|
||||||
const dialogs = (tree: ReactNode) => find(tree, (el) => el.type === UpsellDialog);
|
const dialogs = (tree: ReactNode) => find(tree, (el) => el.type === UpsellDialog);
|
||||||
const gates = (tree: ReactNode) => find(tree, (el) => el.type === UpsellGate);
|
const gates = (tree: ReactNode) => find(tree, (el) => el.type === UpsellGate);
|
||||||
|
const pins = (tree: ReactNode) => find(tree, (el) => el.type === PinDialog);
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
harness.clear();
|
harness.clear();
|
||||||
|
|
@ -106,4 +111,29 @@ describe("ProfileSwitcher — the upsell of a locked profile (#451)", () => {
|
||||||
expect(ctx.switchProfile).toHaveBeenCalledWith("second");
|
expect(ctx.switchProfile).toHaveBeenCalledWith("second");
|
||||||
expect(dialogs(render())).toHaveLength(0);
|
expect(dialogs(render())).toHaveLength(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("Free: a locked profile that has a PIN opens the dialog, never the PIN entry", () => {
|
||||||
|
openMenu();
|
||||||
|
const menu = profileButtons(render(), "third");
|
||||||
|
expect(menu).toHaveLength(1);
|
||||||
|
(menu[0].props.onClick as () => void)();
|
||||||
|
|
||||||
|
const opened = render();
|
||||||
|
expect(dialogs(opened)).toHaveLength(1);
|
||||||
|
expect(pins(opened)).toHaveLength(0);
|
||||||
|
expect(ctx.switchProfile).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Base: a profile that has a PIN asks for it, no dialog", () => {
|
||||||
|
ctx.gate = { allowed: true, ready: true };
|
||||||
|
openMenu();
|
||||||
|
(profileButtons(render(), "third")[0].props.onClick as () => void)();
|
||||||
|
|
||||||
|
const opened = render();
|
||||||
|
const asked = pins(opened);
|
||||||
|
expect(asked).toHaveLength(1);
|
||||||
|
expect(asked[0].props.profileName).toBe("Troisième");
|
||||||
|
expect(dialogs(opened)).toHaveLength(0);
|
||||||
|
expect(ctx.switchProfile).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,10 @@
|
||||||
// leaf both files hold carries one set of tokens, format options included.
|
// leaf both files hold carries one set of tokens, format options included.
|
||||||
// Neither file nests a key (`$t(…)`) or writes the unescaped form (`{{- …}}`)
|
// Neither file nests a key (`$t(…)`) or writes the unescaped form (`{{- …}}`)
|
||||||
// yet: a nested key would not be compared, and `{{- name}}` would read as the
|
// yet: a nested key would not be compared, and `{{- name}}` would read as the
|
||||||
// token `- name`, a gap against `{{name}}`.
|
// token `- name`, a gap against `{{name}}`. With `escapeValue: false`
|
||||||
|
// (src/i18n/config.ts), both forms render the same text in this app: such a
|
||||||
|
// gap would be conservative, like a format name written in another case, not
|
||||||
|
// an escaping defect.
|
||||||
|
|
||||||
import { describe, it, expect } from "vitest";
|
import { describe, it, expect } from "vitest";
|
||||||
import fr from "./locales/fr.json";
|
import fr from "./locales/fr.json";
|
||||||
|
|
@ -245,6 +248,10 @@ describe("locale values: the variable comparison (#480)", () => {
|
||||||
expect(gaps({ x: "{{count}} in {{folder}}" }, { x: "{{count}} in {{dir}}" })).toEqual([
|
expect(gaps({ x: "{{count}} in {{folder}}" }, { x: "{{count}} in {{dir}}" })).toEqual([
|
||||||
"x: {{count}}, {{folder}} in a; {{count}}, {{dir}} in b",
|
"x: {{count}}, {{folder}} in a; {{count}}, {{dir}} in b",
|
||||||
]);
|
]);
|
||||||
|
// A name that differs by its case only is another variable: i18next looks
|
||||||
|
// `{{Version}}` up as written, and shows it raw, braces included, when the
|
||||||
|
// call passes `version`.
|
||||||
|
expect(gaps({ x: "{{version}}" }, { x: "{{Version}}" })).toEqual(["x: {{version}} in a; {{Version}} in b"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("names a variable missing on either side", () => {
|
it("names a variable missing on either side", () => {
|
||||||
|
|
|
||||||
|
|
@ -758,8 +758,9 @@ describe("describePreparation (#390)", () => {
|
||||||
expect(cleaned).not.toMatch(/Jean|Dupont|marie|claire|Users|home|Program|server/);
|
expect(cleaned).not.toMatch(/Jean|Dupont|marie|claire|Users|home|Program|server/);
|
||||||
});
|
});
|
||||||
|
|
||||||
// A folder name may hold `;`, `|`, a backtick, or a `)` followed by a word:
|
// A folder name may hold `;`, `|`, a backtick, or a `)` followed by a word
|
||||||
// none of them ends a path, so no word of that folder stays (#478).
|
// or glued to one (`Projet(2024)final`): none of them ends a path, so no
|
||||||
|
// word of that folder stays (#478).
|
||||||
it.each([
|
it.each([
|
||||||
["C:\\Users\\Jean (Work) Smith\\AppData\\x.db", "x.db"],
|
["C:\\Users\\Jean (Work) Smith\\AppData\\x.db", "x.db"],
|
||||||
["C:\\Users\\jean\\My;Docs\\x.db", "x.db"],
|
["C:\\Users\\jean\\My;Docs\\x.db", "x.db"],
|
||||||
|
|
@ -767,10 +768,11 @@ describe("describePreparation (#390)", () => {
|
||||||
["C:\\Users\\jean\\My`Docs\\x.db", "x.db"],
|
["C:\\Users\\jean\\My`Docs\\x.db", "x.db"],
|
||||||
["unable to open C:\\Users\\Jean (Work) Smith\\AppData\\x.db: disk I/O error", "unable to open x.db: disk I-O error"],
|
["unable to open C:\\Users\\Jean (Work) Smith\\AppData\\x.db: disk I/O error", "unable to open x.db: disk I-O error"],
|
||||||
["/home/jean (work)/x.db", "x.db"],
|
["/home/jean (work)/x.db", "x.db"],
|
||||||
|
["C:\\Users\\jean\\Projet(2024)final\\x.db", "x.db"],
|
||||||
])("withoutFolders keeps no word of a folder that holds a former stop: %s (#478)", (input, expected) => {
|
])("withoutFolders keeps no word of a folder that holds a former stop: %s (#478)", (input, expected) => {
|
||||||
const cleaned = withoutFolders(input);
|
const cleaned = withoutFolders(input);
|
||||||
expect(cleaned).toBe(expected);
|
expect(cleaned).toBe(expected);
|
||||||
expect(cleaned).not.toMatch(/Users|Jean|jean|Work|work|Smith|AppData|My|Docs|home/);
|
expect(cleaned).not.toMatch(/Users|Jean|jean|Work|work|Smith|AppData|My|Docs|home|Projet|final/);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("withoutFolders ends a path at sentence punctuation and at the next path", () => {
|
it("withoutFolders ends a path at sentence punctuation and at the next path", () => {
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,8 @@
|
||||||
// is an item of `props.children`, an array there being read one level deep:
|
// is an item of `props.children`, an array there being read one level deep:
|
||||||
// in `<td>{rows}</td>` the items of `rows` are direct children of the cell,
|
// in `<td>{rows}</td>` the items of `rows` are direct children of the cell,
|
||||||
// in `<td>{label}{rows}</td>` they are not. A fragment holds its own
|
// in `<td>{label}{rows}</td>` they are not. A fragment holds its own
|
||||||
// children, not its parent.
|
// children, not its parent. An absence is proved with `find`, never with
|
||||||
|
// `holding`: its one-level read would miss an element nested deeper.
|
||||||
//
|
//
|
||||||
// Both read `props.children` only: an element passed in another prop
|
// Both read `props.children` only: an element passed in another prop
|
||||||
// (`icon={<Plus />}`) is not reached. A component in the tree is an element,
|
// (`icon={<Plus />}`) is not reached. A component in the tree is an element,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue