Skip to content

Commit

Permalink
Adds predictive search (#81)
Browse files Browse the repository at this point in the history
* Adds trie data structure impl

* Adds base/naive filter implementation

* first impl of filter with test failures

* Batches promises in search index

* moves resources folder to public

* Makes filter a static config

* prevent empty search

* adds amm to filter config

* makes input field required to prevent blank searches

* Bug fixes/imporvements to filter

- Adds a handleSubmit function to prevetn arbitrary whitespace from being queried as a search term
- Makes SearchBar more re-usable by making the filter items a prop
- Removes unused dependencies
- Upgrades chakra-ui/react lib

* Adds/modifies unit tests for search-bar

* Fixes Trie class tess; upgrades deps; refactors

* Adds tab key controls for search

* Removes mistakenly added code

* Makes autocomplete accessible

* Removes unused import

* Adds small tab bug fix; adds/fixes searchbar tests

* Bug fix with empty string filtering

* Fixes background color missing on tags
  • Loading branch information
narbs91 authored Jan 3, 2022
1 parent 6149930 commit 6dd5094
Show file tree
Hide file tree
Showing 13 changed files with 1,388 additions and 633 deletions.
90 changes: 90 additions & 0 deletions _tests_/filter/trie.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import Trie from "../../src/filter/trie";

describe("Trie insertion", () => {
it("inserts items into the trie", () => {
// Prepare
let trie = new Trie();

// Execute
trie.insert("eip");
trie.insert("ethereum");
trie.insert("eth");
trie.insert("arweave");

// Verify
expect(trie.contains("eip")).toBeTruthy();
expect(trie.contains("ethereum")).toBeTruthy();
expect(trie.contains("eth")).toBeTruthy();
expect(trie.contains("arweave")).toBeTruthy();
expect(trie.contains("bitcoin")).toBeFalsy();
});
});

describe("Trie word retrieval", () => {
it("retrieves words beginning with e", () => {
// Prepare
let output = [];
let trie = new Trie();
trie.insert("eip");
trie.insert("ethereum");
trie.insert("eth");
trie.insert("arweave");

// Execute
output = trie.find("e");

// Verify
expect(output.length).toBe(3);
expect(output.find((element) => element === "eip")).toBe("eip");
expect(output.find((element) => element === "ethereum")).toBe("ethereum");
expect(output.find((element) => element === "eth")).toBe("eth");
expect(output.find((element) => element === "arweave")).toBeFalsy();
});

it("retrieves exact word", () => {
// Prepare
let output = [];
let trie = new Trie();
trie.insert("eip");
trie.insert("ethereum");
trie.insert("eth");
trie.insert("arweave");

// Execute
output = trie.find("arweave");

// Verify
expect(output.length).toBe(1);
expect(output.find((element) => element === "arweave")).toBe("arweave");
});

it("Does not find word when trie populated", () => {
// Prepare
let output = [];
let trie = new Trie();
trie.insert("eip");
trie.insert("ethereum");
trie.insert("eth");
trie.insert("arweave");

// Execute
output = trie.find("bitcoin");

// Verify
expect(output.length).toBe(0);
expect(output.find((element) => element === "bitcoin")).toBeFalsy();
});

it("Does not find word when trie empty", () => {
// Prepare
let output = [];
let trie = new Trie();

// Execute
output = trie.find("bitcoin");

// Verify
expect(output.length).toBe(0);
expect(output.find((element) => element === "bitcoin")).toBeFalsy();
});
});
Loading

1 comment on commit 6dd5094

@vercel
Copy link

@vercel vercel bot commented on 6dd5094 Jan 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.