|
| 1 | +import { describe, expect, test } from "bun:test"; |
| 2 | + |
| 3 | +import { buildSearchIndex, searchCommandIndex } from "../commands/search.js"; |
| 4 | +import { createProgram } from "../program.js"; |
| 5 | + |
| 6 | +describe("search command", () => { |
| 7 | + test("registers the root search command", () => { |
| 8 | + const commandNames = createProgram().commands.map((command) => command.name()); |
| 9 | + expect(commandNames).toContain("search"); |
| 10 | + }); |
| 11 | + |
| 12 | + test("indexes providers and nested commands", () => { |
| 13 | + const index = buildSearchIndex(); |
| 14 | + expect(index.some((entry) => entry.command === "autocli tools download")).toBe(true); |
| 15 | + expect(index.some((entry) => entry.command === "autocli tools download video")).toBe(true); |
| 16 | + expect(index.some((entry) => entry.command === "autocli login")).toBe(true); |
| 17 | + }); |
| 18 | + |
| 19 | + test("finds provider matches by display name and category words", () => { |
| 20 | + const results = searchCommandIndex(buildSearchIndex(), "uptime robot", { limit: 5 }); |
| 21 | + expect(results[0]?.command).toBe("autocli devops uptimerobot"); |
| 22 | + }); |
| 23 | + |
| 24 | + test("finds command matches from examples and descriptions", () => { |
| 25 | + const results = searchCommandIndex(buildSearchIndex(), "youtube download", { limit: 5 }); |
| 26 | + expect(results.some((entry) => entry.command === "autocli tools download")).toBe(true); |
| 27 | + }); |
| 28 | + |
| 29 | + test("supports category filtering", () => { |
| 30 | + const results = searchCommandIndex(buildSearchIndex(), "uptime", { |
| 31 | + category: "devops", |
| 32 | + limit: 10, |
| 33 | + }); |
| 34 | + expect(results.every((entry) => entry.category === "devops")).toBe(true); |
| 35 | + }); |
| 36 | + |
| 37 | + test("finds root commands by option text", () => { |
| 38 | + const results = searchCommandIndex(buildSearchIndex(), "browser login", { limit: 5 }); |
| 39 | + expect(results[0]?.command).toBe("autocli login"); |
| 40 | + }); |
| 41 | +}); |
0 commit comments