-
Notifications
You must be signed in to change notification settings - Fork 2
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
Showing
2 changed files
with
90 additions
and
19 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,55 @@ | ||
import { describe, it, expect, vi, beforeEach } from 'vitest'; | ||
import { approveOrigin } from './approve-origin'; | ||
import { localExtStorage } from './storage/local'; | ||
|
||
// Mocks | ||
vi.mock('./storage/local', () => ({ | ||
get: vi.fn(), | ||
set: vi.fn(), | ||
})); | ||
vi.mock('./popup', () => ({ | ||
popup: vi.fn(), | ||
})); | ||
|
||
const mockTab = { | ||
index: 2, | ||
pinned: false, | ||
highlighted: true, | ||
windowId: 1, | ||
active: true, | ||
id: 123456, | ||
incognito: false, | ||
selected: false, | ||
discarded: false, | ||
autoDiscardable: true, | ||
groupId: -1, | ||
}; | ||
|
||
describe('originHandlers', () => { | ||
beforeEach(() => { | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
describe('approveOrigin', () => { | ||
it('throws an error if the sender origin is not supported', async () => { | ||
const messageSender = { origin: 'http://insecure.com' }; | ||
await expect(approveOrigin(messageSender)).rejects.toThrow('Unsupported sender'); | ||
}); | ||
|
||
it('returns the previously approved choice if one exists', async () => { | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call | ||
localExtStorage.mockReturnValue( | ||
Check failure on line 41 in apps/extension/src/approve-origin.test.ts GitHub Actions / testsrc/approve-origin.test.ts > originHandlers > approveOrigin > returns the previously approved choice if one exists
|
||
Promise.resolve([{ origin: 'https://example.com', choice: 'Approved' }]), | ||
); | ||
|
||
const messageSender = { | ||
origin: 'https://example.com', | ||
tab: mockTab, | ||
}; | ||
const choice = await approveOrigin(messageSender); | ||
expect(choice).toBe('Approved'); | ||
}); | ||
|
||
// More tests based on different scenarios... | ||
}); | ||
}); |
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