Skip to content

Commit c1e530d

Browse files
committed
Complete unit test
1 parent af7d78a commit c1e530d

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

test/database/archived-database.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,34 @@ describe('archived-database', () => {
2626
expect(baiduInfo.total).toEqual(2)
2727
expect(baiduInfo.time).toEqual(4)
2828
})
29+
30+
test('2', async () => {
31+
const key = `_a_${baidu}`
32+
const toImport = {}
33+
toImport[key] = {
34+
focus: 1,
35+
time: 2,
36+
total: 3
37+
}
38+
await archivedDatabase.importData(toImport)
39+
const result = await archivedDatabase.selectArchived(new Set([baidu]))
40+
expect(result.length).toEqual(1)
41+
const baiduInfo = result[0]
42+
expect(baiduInfo.focus).toEqual(1)
43+
expect(baiduInfo.time).toEqual(2)
44+
expect(baiduInfo.total).toEqual(3)
45+
})
46+
47+
test('3', async () => {
48+
const key = `_a_${baidu}`
49+
const toImport = {}
50+
toImport[key] = {}
51+
await archivedDatabase.importData(toImport)
52+
const result = await archivedDatabase.selectArchived(new Set([baidu]))
53+
expect(result.length).toEqual(1)
54+
const baiduInfo = result[0]
55+
expect(baiduInfo.focus).toEqual(0)
56+
expect(baiduInfo.time).toEqual(0)
57+
expect(baiduInfo.total).toEqual(0)
58+
})
2959
})

test/database/icon-url-database.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ const db = new IconUrlDatabase(storage.local)
66
const baidu = 'baidu.com'
77

88
describe('icon-url-database', () => {
9-
beforeEach(async () => storage.local.clear())
9+
beforeEach(async () => {
10+
await storage.local.clear()
11+
const mockUserAgent = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36"
12+
Object.defineProperty(global.navigator, 'userAgent', { value: mockUserAgent, configurable: true })
13+
})
1014

1115
test('1', async () => {
1216
await db.put(baidu, 'test1')

0 commit comments

Comments
 (0)