| 1 | import { SlashCommandDescription } from "core"; |
| 2 | import { sortCommandsByBookmarkStatus } from "../utils"; |
| 3 | |
| 4 | describe("sortCommandsByBookmarkStatus", () => { |
| 5 | const mockCommands: SlashCommandDescription[] = [ |
| 6 | { |
| 7 | name: "command1", |
| 8 | description: "First command", |
| 9 | prompt: "This is command 1", |
| 10 | }, |
| 11 | { |
| 12 | name: "command2", |
| 13 | description: "Second command", |
| 14 | prompt: "This is command 2", |
| 15 | }, |
| 16 | { |
| 17 | name: "command3", |
| 18 | description: "Third command", |
| 19 | prompt: "This is command 3", |
| 20 | }, |
| 21 | { |
| 22 | name: "command4", |
| 23 | description: "Fourth command", |
| 24 | prompt: "This is command 4", |
| 25 | }, |
| 26 | ]; |
| 27 | |
| 28 | it("should return commands in the same order when no bookmarks exist", () => { |
| 29 | const result = sortCommandsByBookmarkStatus(mockCommands, []); |
| 30 | expect(result).toEqual(mockCommands); |
| 31 | // Ensure it's a new array, not the original |
| 32 | expect(result).not.toBe(mockCommands); |
| 33 | }); |
| 34 | |
| 35 | it("should put bookmarked commands first", () => { |
| 36 | const bookmarkedCommands = ["command3", "command1"]; |
| 37 | const result = sortCommandsByBookmarkStatus( |
| 38 | mockCommands, |
| 39 | bookmarkedCommands, |
| 40 | ); |
| 41 | |
| 42 | expect(result[0].name).toBe("command1"); |
| 43 | expect(result[1].name).toBe("command3"); |
| 44 | }); |
| 45 | }); |