74 lines
2.2 KiB
TypeScript
74 lines
2.2 KiB
TypeScript
import { beforeEach, describe, expect, it, jest } from '@jest/globals';
|
|
|
|
import handler from '~background/messages/database/get';
|
|
import { DEFAULT_EXTENSION_DATA } from '~utils/constants';
|
|
import type { ExtensionData } from '~utils/types';
|
|
|
|
describe('background/messages/database/get.ts', () => {
|
|
const req = { name: 'database/get' as const };
|
|
const res = { send: jest.fn() };
|
|
|
|
beforeEach(() => {
|
|
jest.clearAllMocks();
|
|
});
|
|
|
|
it('should return default data if no data is in storage', async () => {
|
|
await handler(req, res);
|
|
|
|
expect(chrome.storage.local.get).toHaveBeenCalledWith('data');
|
|
expect(res.send).toHaveBeenCalledWith({ data: DEFAULT_EXTENSION_DATA, success: true });
|
|
});
|
|
|
|
it('should return stored data if it exists in storage', async () => {
|
|
const data: ExtensionData = {
|
|
actions: [
|
|
{
|
|
domain: 'jestjs.io',
|
|
name: 'click',
|
|
selector: '#jest',
|
|
},
|
|
],
|
|
exclusions: {
|
|
domains: ['*.jestjs.io'],
|
|
overflows: ['*.jestjs.io'],
|
|
tags: ['JEST'],
|
|
},
|
|
keywords: ['jest'],
|
|
rules: [
|
|
{
|
|
action: {
|
|
type: 'block' as chrome.declarativeNetRequest.RuleActionType,
|
|
},
|
|
condition: {
|
|
resourceTypes: [
|
|
'font' as chrome.declarativeNetRequest.ResourceType,
|
|
'image' as chrome.declarativeNetRequest.ResourceType,
|
|
'media' as chrome.declarativeNetRequest.ResourceType,
|
|
'object' as chrome.declarativeNetRequest.ResourceType,
|
|
'script' as chrome.declarativeNetRequest.ResourceType,
|
|
'stylesheet' as chrome.declarativeNetRequest.ResourceType,
|
|
'xmlhttprequest' as chrome.declarativeNetRequest.ResourceType,
|
|
],
|
|
urlFilter: '||jestjs.io^',
|
|
},
|
|
id: 1,
|
|
priority: 1,
|
|
},
|
|
],
|
|
tokens: {
|
|
backdrops: ['#backdrop'],
|
|
classes: ['jest'],
|
|
containers: ['#container'],
|
|
selectors: ['#element'],
|
|
},
|
|
version: '0.0.0',
|
|
};
|
|
|
|
await chrome.storage.local.set({ data });
|
|
await handler(req, res);
|
|
|
|
expect(chrome.storage.local.get).toHaveBeenCalledWith('data');
|
|
expect(res.send).toHaveBeenCalledWith({ data, success: true });
|
|
});
|
|
});
|