|
| 1 | +import { describe, it, expect } from "vitest" |
| 2 | +import { getAllModesInfo } from "../modes" |
| 3 | +import { ModeConfig } from "@roo-code/types" |
| 4 | + |
| 5 | +describe("getAllModesInfo", () => { |
| 6 | + it("should return slug and name for all built-in modes", () => { |
| 7 | + const modesInfo = getAllModesInfo() |
| 8 | + |
| 9 | + // Should have multiple modes |
| 10 | + expect(modesInfo.length).toBeGreaterThan(0) |
| 11 | + |
| 12 | + // Each mode should have slug and name |
| 13 | + modesInfo.forEach((mode) => { |
| 14 | + expect(mode).toHaveProperty("slug") |
| 15 | + expect(mode).toHaveProperty("name") |
| 16 | + expect(typeof mode.slug).toBe("string") |
| 17 | + expect(typeof mode.name).toBe("string") |
| 18 | + expect(mode.slug).toBeTruthy() |
| 19 | + expect(mode.name).toBeTruthy() |
| 20 | + }) |
| 21 | + |
| 22 | + // Check that we have some expected built-in modes |
| 23 | + const slugs = modesInfo.map((m) => m.slug) |
| 24 | + expect(slugs).toContain("code") |
| 25 | + expect(slugs).toContain("architect") |
| 26 | + expect(slugs).toContain("ask") |
| 27 | + }) |
| 28 | + |
| 29 | + it("should include custom modes when provided", () => { |
| 30 | + const customModes: ModeConfig[] = [ |
| 31 | + { |
| 32 | + slug: "custom-test", |
| 33 | + name: "Custom Test Mode", |
| 34 | + roleDefinition: "Test role", |
| 35 | + groups: ["read"], |
| 36 | + }, |
| 37 | + ] |
| 38 | + |
| 39 | + const modesInfo = getAllModesInfo(customModes) |
| 40 | + |
| 41 | + // Should include the custom mode |
| 42 | + const customMode = modesInfo.find((m) => m.slug === "custom-test") |
| 43 | + expect(customMode).toBeDefined() |
| 44 | + expect(customMode?.name).toBe("Custom Test Mode") |
| 45 | + }) |
| 46 | + |
| 47 | + it("should override built-in modes with custom modes of the same slug", () => { |
| 48 | + const customModes: ModeConfig[] = [ |
| 49 | + { |
| 50 | + slug: "code", |
| 51 | + name: "Custom Code Mode", |
| 52 | + roleDefinition: "Custom role", |
| 53 | + groups: ["read"], |
| 54 | + }, |
| 55 | + ] |
| 56 | + |
| 57 | + const modesInfo = getAllModesInfo(customModes) |
| 58 | + |
| 59 | + // Should have the custom mode name for the code slug |
| 60 | + const codeMode = modesInfo.find((m) => m.slug === "code") |
| 61 | + expect(codeMode).toBeDefined() |
| 62 | + expect(codeMode?.name).toBe("Custom Code Mode") |
| 63 | + |
| 64 | + // Should not have duplicate entries |
| 65 | + const codeModes = modesInfo.filter((m) => m.slug === "code") |
| 66 | + expect(codeModes.length).toBe(1) |
| 67 | + }) |
| 68 | +}) |
0 commit comments