-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4e975be
commit 328c8ef
Showing
3 changed files
with
65 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import FlexSearch from 'flexsearch' | ||
// @ts-ignore | ||
import { encode as encode_balance } from 'flexsearch/dist/module/lang/latin/balance' | ||
|
||
export const getSearchEncoder = (): FlexSearch.Encoders => { | ||
return encode_balance as FlexSearch.Encoders | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import CozyClient from 'cozy-client' | ||
|
||
import { getPouchLink } from '@/search/helpers/client' | ||
|
||
import { startReplicationWithDebounce } from './replication' | ||
|
||
jest.mock('cozy-client') | ||
jest.mock('@/search/helpers/client', () => ({ | ||
getPouchLink: jest.fn() | ||
})) | ||
|
||
describe('startReplicationWithDebounce', () => { | ||
let client: CozyClient | ||
let pouchLink: any | ||
|
||
beforeEach(() => { | ||
client = new CozyClient() | ||
pouchLink = { | ||
startReplication: jest.fn() | ||
} | ||
log = { | ||
debug: jest.fn() | ||
} | ||
;(getPouchLink as jest.Mock).mockReturnValue(pouchLink) | ||
jest.useFakeTimers() | ||
}) | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks() | ||
jest.clearAllTimers() | ||
}) | ||
|
||
it('should start replication after the specified interval', () => { | ||
const interval = 1000 | ||
const replicate = startReplicationWithDebounce(client, interval) | ||
|
||
replicate() | ||
expect(pouchLink.startReplication).not.toHaveBeenCalled() | ||
jest.advanceTimersByTime(interval) | ||
expect(pouchLink.startReplication).toHaveBeenCalledTimes(1) | ||
}) | ||
|
||
it('should debounce replication calls within the interval', () => { | ||
const interval = 1000 | ||
const replicate = startReplicationWithDebounce(client, interval) | ||
|
||
replicate() | ||
jest.advanceTimersByTime(interval / 2) | ||
expect(pouchLink.startReplication).not.toHaveBeenCalled() | ||
replicate() | ||
replicate() | ||
|
||
jest.advanceTimersByTime(interval) | ||
expect(pouchLink.startReplication).toHaveBeenCalledTimes(1) | ||
}) | ||
}) |