|
| 1 | +import { describe, it, expect } from "vitest"; |
| 2 | +import { extractTags, sortEntries } from "./utils"; |
| 3 | + |
| 4 | +describe("sortEntries", () => { |
| 5 | + it("sorts entries alphabetically by title", () => { |
| 6 | + const first = { title: "First Entry", url: "first.com", tags: ["foo"] }; |
| 7 | + const second = { title: "Second", url: "second.com", tags: ["bar"] }; |
| 8 | + const third = { |
| 9 | + title: "Another Entry", |
| 10 | + url: "another.com", |
| 11 | + tags: ["foo", "bar"], |
| 12 | + }; |
| 13 | + |
| 14 | + expect(sortEntries([first, second, third])).toEqual([third, first, second]); |
| 15 | + }); |
| 16 | + |
| 17 | + it("disregards leading 'The' when sorting titles", () => { |
| 18 | + const first = { title: "The First Entry", url: "first.com", tags: ["foo"] }; |
| 19 | + const second = { title: "Go Second", url: "second.com", tags: ["bar"] }; |
| 20 | + const third = { |
| 21 | + title: "Another Entry", |
| 22 | + url: "another.com", |
| 23 | + tags: ["foo", "bar"], |
| 24 | + }; |
| 25 | + |
| 26 | + expect(sortEntries([first, second, third])).toEqual([third, first, second]); |
| 27 | + }); |
| 28 | +}); |
| 29 | + |
| 30 | +describe("extractTags", () => { |
| 31 | + it("returns an array of unique tags from all of the entries provided", () => { |
| 32 | + const first = { |
| 33 | + title: "First Entry", |
| 34 | + url: "first.com", |
| 35 | + tags: ["foo", "baz"], |
| 36 | + }; |
| 37 | + const second = { title: "Second", url: "second.com", tags: ["bar"] }; |
| 38 | + const third = { |
| 39 | + title: "Another Entry", |
| 40 | + url: "another.com", |
| 41 | + tags: ["foo", "bar"], |
| 42 | + }; |
| 43 | + |
| 44 | + expect(extractTags([first, second, third])).toEqual(["foo", "baz", "bar"]); |
| 45 | + }); |
| 46 | +}); |
0 commit comments