-
Notifications
You must be signed in to change notification settings - Fork 17
/
data.test.ts
46 lines (39 loc) · 1.36 KB
/
data.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import * as translationsStore from './data';
// import { IDBFactory } from "fake-indexeddb";
// const wipeIDB = () => {
// // Whenever you want a fresh indexedDB
// indexedDB = new IDBFactory();
// };
test('translations data handler', async () => {
const translations = Array(5)
.fill(null)
.map((_, index) => ({
timestamp: new Date().getTime(),
translation: {
from: 'en',
to: 'de',
originalText: 'text ' + (index + 1),
translatedText: 'text ' + (index + 1),
},
}));
// TODO: report to `fake-indexeddb` bug about concurrent inserting problems
const identifiers: number[] = [];
for (const translation of translations) {
const id = await translationsStore.addEntry(translation);
identifiers.push(id);
}
const expectedIdentifiersList = translations.map((_, index) => index + 1);
expect(identifiers).toEqual(expectedIdentifiersList);
const entriesWithKeys = await translationsStore.getEntries(undefined, undefined, {
order: 'asc',
});
expect(typeof entriesWithKeys).toBe('object');
expect(Array.isArray(entriesWithKeys)).toBe(true);
// TODO: report to `idb` bug about invalid type of cursor value (not include a key property name)
// Remove `id` key
const entries = (entriesWithKeys as any[]).map(
({ data: { id, ...anotherProps } }) => anotherProps,
);
// Check equality with original data
expect(entries).toEqual(translations);
});