File tree Expand file tree Collapse file tree 6 files changed +33
-11
lines changed
Expand file tree Collapse file tree 6 files changed +33
-11
lines changed Original file line number Diff line number Diff line change 4545 "vue" : " ^3.0.11" ,
4646 "vue-router" : " ^4.0.8"
4747 }
48- }
48+ }
Original file line number Diff line number Diff line change 1- import whitelistDatabase from '../database/whitelist-database'
1+ import WhitelistDatabase from '../database/whitelist-database'
22import { t2Chrome } from '../util/i18n/chrome/t'
33import { extractHostname , isBrowserUrl } from '../util/pattern'
44
5- const db = whitelistDatabase
5+ const db = new WhitelistDatabase ( chrome . storage . local )
66
77const menuId = '_timer_menu_item_' + Date . now ( )
88
Original file line number Diff line number Diff line change 11import { WHITELIST_KEY } from "./constant"
22
3-
4- const ruleId = '_timer_whitelist_db_change_rule_id'
5-
63class WhitelistDatabase {
74
8- private localStorage = chrome . storage . local
5+ private localStorage : chrome . storage . StorageArea
96
10- constructor ( ) { }
7+ constructor ( storage : chrome . storage . StorageArea ) {
8+ this . localStorage = storage
9+ }
1110
1211 private update ( selectAll : string [ ] ) : Promise < void > {
1312 const obj = { }
@@ -62,4 +61,4 @@ class WhitelistDatabase {
6261 }
6362}
6463
65- export default new WhitelistDatabase ( )
64+ export default WhitelistDatabase
Original file line number Diff line number Diff line change 11import TimerDatabase , { TimerCondition } from '../database/timer-database'
2- import whitelistDatabase from '../database/whitelist-database'
2+ import WhitelistDatabase from '../database/whitelist-database'
33import ArchivedDatabase from '../database/archived-database'
44import SiteInfo from '../entity/dto/site-info'
55import { log } from '../common/logger'
@@ -13,6 +13,7 @@ const timerDatabase = new TimerDatabase(chrome.storage.local)
1313const archivedDatabase = new ArchivedDatabase ( chrome . storage . local )
1414const iconUrlDatabase = new IconUrlDatabase ( chrome . storage . local )
1515const mergeRuleDatabase = new MergeRuleDatabase ( chrome . storage . local )
16+ const whitelistDatabase = new WhitelistDatabase ( chrome . storage . local )
1617
1718declare type PageParam = {
1819 pageNum ?: number
Original file line number Diff line number Diff line change 11import { log } from "../common/logger"
2- import whitelistDatabase from "../database/whitelist-database"
2+ import WhitelistDatabase from "../database/whitelist-database"
33
4+ const whitelistDatabase = new WhitelistDatabase ( chrome . storage . local )
45/**
56 * Service of whitelist
67 *
Original file line number Diff line number Diff line change 1+ import WhitelistDatabase from "../../src/database/whitelist-database"
2+ import storage from "../__mock__/storage"
3+
4+ const db = new WhitelistDatabase ( storage . local )
5+
6+ describe ( 'timer-database' , ( ) => {
7+ beforeEach ( async ( ) => storage . local . clear ( ) )
8+
9+ test ( '1' , async ( ) => {
10+ await db . add ( 'www.baidu.com' )
11+ await db . add ( 'google.com' )
12+ const list = await db . selectAll ( )
13+ expect ( list . sort ( ) ) . toEqual ( [ 'www.baidu.com' , 'google.com' ] . sort ( ) )
14+ expect ( ( await db . includes ( 'www.baidu.com' ) ) ) . toBeTruthy ( )
15+ await db . remove ( 'www.baidu.com' )
16+ expect ( ( await db . selectAll ( ) ) ) . toEqual ( [ 'google.com' ] )
17+ expect ( ( await db . includes ( 'www.baidu.com' ) ) ) . toBeFalsy ( )
18+ await db . add ( 'google.com' )
19+ expect ( ( await db . selectAll ( ) ) ) . toEqual ( [ 'google.com' ] )
20+ } )
21+ } )
You can’t perform that action at this time.
0 commit comments