-
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.
Ensures that default settings are being merged with the existing extension settings found in the browser as appropriate.
- Loading branch information
1 parent
0c00766
commit d24bdcf
Showing
1 changed file
with
47 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { describe, expect, it, vi } from 'vitest' | ||
import { storageInit } from '@/lib/storageInit' | ||
import type { StorageAll } from '@/types/StorageAll' | ||
|
||
const browserMock = { | ||
storage: { | ||
sync: { | ||
get: vi.fn(async (_: string | string[] | Record<string, any> | null | undefined): Promise<Record<string, any>> => ({ blockDefault: true })), | ||
set: vi.fn(async (_: Record<string, any>): Promise<void> => {}) | ||
}, | ||
|
||
local: { | ||
get: vi.fn(async (_: string | string[] | Record<string, any> | null | undefined): Promise<Record<string, any>> => ({})), | ||
set: vi.fn(async (_: Record<string, any>): Promise<void> => {}) | ||
} | ||
} | ||
} | ||
|
||
vi.stubGlobal('browser', browserMock) | ||
|
||
const defaultStorage: StorageAll = { | ||
sync: { | ||
provider: 'mullvad', | ||
blockDefault: false | ||
}, | ||
|
||
local: { | ||
servers: [], | ||
lastUpdated: 0 | ||
} | ||
} | ||
|
||
describe('storageInit()', () => { | ||
it('should initialize with default values with existing browser storage values taking priority', async () => { | ||
expect(await storageInit(defaultStorage)).toEqual({ | ||
sync: { | ||
provider: 'mullvad', | ||
blockDefault: true | ||
}, | ||
|
||
local: { | ||
servers: [], | ||
lastUpdated: 0 | ||
} | ||
}) | ||
}) | ||
}) |