Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
latonv committed Oct 5, 2023
1 parent 57ede48 commit 09f342d
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 0 deletions.
45 changes: 45 additions & 0 deletions test/search-backend/fulltext-search-backend.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,51 @@ describe('FulltextSearchBackend', () => {
window.history.replaceState({}, '', url.toString());
});

it('includes reCache param from URL if not provided', async () => {
const url = new URL(window.location.href);
url.searchParams.set('reCache', '1');
window.history.replaceState({}, '', url.toString());

const backend = new FulltextSearchBackend();
await backend.performSearch({ query: 'foo' });

const queryParams = new URL(urlCalled!.toString()).searchParams;
expect(queryParams.get('caching')).to.equal('{"recompute":true}');

url.searchParams.delete('reCache');
window.history.replaceState({}, '', url.toString());
});

it('includes noCache param from URL if not provided', async () => {
const url = new URL(window.location.href);
url.searchParams.set('noCache', '1');
window.history.replaceState({}, '', url.toString());

const backend = new FulltextSearchBackend();
await backend.performSearch({ query: 'foo' });

const queryParams = new URL(urlCalled!.toString()).searchParams;
expect(queryParams.get('caching')).to.equal('{"bypass":true}');

url.searchParams.delete('noCache');
window.history.replaceState({}, '', url.toString());
});

it('includes dontCache param from URL if not provided', async () => {
const url = new URL(window.location.href);
url.searchParams.set('dontCache', '1');
window.history.replaceState({}, '', url.toString());

const backend = new FulltextSearchBackend();
await backend.performSearch({ query: 'foo' });

const queryParams = new URL(urlCalled!.toString()).searchParams;
expect(queryParams.get('caching')).to.equal('{"no_compute":true}');

url.searchParams.delete('dontCache');
window.history.replaceState({}, '', url.toString());
});

it('can enable debugging by default on all searches', async () => {
const backend = new FulltextSearchBackend({
baseUrl: 'foo.bar',
Expand Down
45 changes: 45 additions & 0 deletions test/search-backend/metadata-search-backend.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,51 @@ describe('MetadataSearchBackend', () => {
window.history.replaceState({}, '', url.toString());
});

it('includes reCache param from URL if not provided', async () => {
const url = new URL(window.location.href);
url.searchParams.set('reCache', '1');
window.history.replaceState({}, '', url.toString());

const backend = new MetadataSearchBackend();
await backend.performSearch({ query: 'foo' });

const queryParams = new URL(urlCalled!.toString()).searchParams;
expect(queryParams.get('caching')).to.equal('{"recompute":true}');

url.searchParams.delete('reCache');
window.history.replaceState({}, '', url.toString());
});

it('includes noCache param from URL if not provided', async () => {
const url = new URL(window.location.href);
url.searchParams.set('noCache', '1');
window.history.replaceState({}, '', url.toString());

const backend = new MetadataSearchBackend();
await backend.performSearch({ query: 'foo' });

const queryParams = new URL(urlCalled!.toString()).searchParams;
expect(queryParams.get('caching')).to.equal('{"bypass":true}');

url.searchParams.delete('noCache');
window.history.replaceState({}, '', url.toString());
});

it('includes dontCache param from URL if not provided', async () => {
const url = new URL(window.location.href);
url.searchParams.set('dontCache', '1');
window.history.replaceState({}, '', url.toString());

const backend = new MetadataSearchBackend();
await backend.performSearch({ query: 'foo' });

const queryParams = new URL(urlCalled!.toString()).searchParams;
expect(queryParams.get('caching')).to.equal('{"no_compute":true}');

url.searchParams.delete('dontCache');
window.history.replaceState({}, '', url.toString());
});

it('can enable debugging by default on all searches', async () => {
const backend = new MetadataSearchBackend({
baseUrl: 'foo.bar',
Expand Down

0 comments on commit 09f342d

Please sign in to comment.