···11+import { describe, it, beforeEach, expect } from "bun:test";
22+import { SearchIndex } from ".";
33+44+describe("Search Index", () => {
55+ let index: SearchIndex;
66+ beforeEach(() => {
77+ index = new SearchIndex();
88+ });
99+1010+ it("should add a new page to the index", () => {
1111+ index.addPage(
1212+ "https://www.example.com",
1313+ "This is a sample webpage about dogs",
1414+ );
1515+ expect(index.getPagesForKeyword("dogs")).toContain(
1616+ "https://www.example.com",
1717+ );
1818+ });
1919+ it("should return an empty list for the keyword", () => {
2020+ expect(index.getPagesForKeyword("pineapple")).toBeEmpty();
2121+ });
2222+ it("should update a page in the index", () => {
2323+ index.addPage(
2424+ "https://www.example.com",
2525+ "This is a sample web page about dogs",
2626+ );
2727+ index.updatePage(
2828+ "https://www.example.com",
2929+ "This is a sample web page about cats",
3030+ );
3131+ expect(index.getPagesForKeyword("dogs")).not.toContain(
3232+ "https://www.example.com",
3333+ );
3434+ expect(index.getPagesForKeyword("cats")).toContain(
3535+ "https://www.example.com",
3636+ );
3737+ });
3838+ it("should remove a page from the index", () => {
3939+ index.addPage(
4040+ "https://www.example.com",
4141+ "This is a sample web page about cats",
4242+ );
4343+ index.removePage("https://www.example.com");
4444+ expect(index.getPagesForKeyword("cats")).not.toContain(
4545+ "https://www.example.com",
4646+ );
4747+ });
4848+ it("should return relevant pages for a keyword", () => {
4949+ index.addPage(
5050+ "https://www.example.com",
5151+ "This is a sample web page about cats",
5252+ );
5353+ expect(index.getPagesForKeyword("cats")).toContain(
5454+ "https://www.example.com",
5555+ );
5656+ });
5757+ it("should return multiple relavent pages that share a keyword", () => {
5858+ index.addPage(
5959+ "https://www.pineapple-world.com",
6060+ "We have lots of pineapples. You've never seen this many pineapples before.",
6161+ );
6262+ index.addPage(
6363+ "https://www.pineapple-is-my-favorite-fruit.com",
6464+ "I love pineapples, it's all I eat. I mean I REALLY LOVE PINEAPPLES",
6565+ );
6666+6767+ expect(index.getPagesForKeyword("pineapples")).toBeArrayOfSize(2);
6868+ });
6969+});