Squashed 'third_party/pi/' content from commit d981de122
git-subtree-dir: third_party/pi git-subtree-split: d981de1229ef899957bbe968bc8dcda02a21f477
This commit is contained in:
58
packages/tui/test/settings-list.test.ts
Normal file
58
packages/tui/test/settings-list.test.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
import assert from "node:assert";
|
||||
import { describe, it } from "node:test";
|
||||
import { SettingsList, type SettingsListTheme } from "../src/components/settings-list.ts";
|
||||
|
||||
const testTheme: SettingsListTheme = {
|
||||
label: (text) => text,
|
||||
value: (text) => text,
|
||||
description: (text) => text,
|
||||
cursor: "> ",
|
||||
hint: (text) => text,
|
||||
};
|
||||
|
||||
const items = [
|
||||
{
|
||||
id: "tui-mode",
|
||||
label: "TUI mode",
|
||||
currentValue: "regular",
|
||||
values: ["regular", "fullscreen"],
|
||||
},
|
||||
];
|
||||
|
||||
describe("SettingsList", () => {
|
||||
it("includes spaces in an active search instead of changing the selected setting", () => {
|
||||
const changes: Array<{ id: string; value: string }> = [];
|
||||
const list = new SettingsList(
|
||||
items.map((item) => ({ ...item })),
|
||||
10,
|
||||
testTheme,
|
||||
(id, value) => changes.push({ id, value }),
|
||||
() => {},
|
||||
{ enableSearch: true },
|
||||
);
|
||||
|
||||
for (const character of "TUI mode") list.handleInput(character);
|
||||
|
||||
assert.deepStrictEqual(changes, []);
|
||||
assert.match(list.render(80)[0] ?? "", /TUI mode/);
|
||||
|
||||
list.handleInput("\r");
|
||||
assert.deepStrictEqual(changes, [{ id: "tui-mode", value: "fullscreen" }]);
|
||||
});
|
||||
|
||||
it("keeps Space as a change shortcut before a search query is entered", () => {
|
||||
const changes: Array<{ id: string; value: string }> = [];
|
||||
const list = new SettingsList(
|
||||
items.map((item) => ({ ...item })),
|
||||
10,
|
||||
testTheme,
|
||||
(id, value) => changes.push({ id, value }),
|
||||
() => {},
|
||||
{ enableSearch: true },
|
||||
);
|
||||
|
||||
list.handleInput(" ");
|
||||
|
||||
assert.deepStrictEqual(changes, [{ id: "tui-mode", value: "fullscreen" }]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user