1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-22 11:45:59 +01:00
bitwarden-browser/apps/browser/test.setup.ts
Cesar Gonzalez 51f482dde9
[PM-5880] Refactor browser platform utils service to remove window references (#7885)
* [PM-5880] Refactor Browser Platform Utils Service to Remove Window Service

* [PM-5880] Implementing BrowserClipboardService to handle clipboard logic between the BrowserPlatformUtils and offscreen document

* [PM-5880] Adjusting how readText is handled within BrowserClipboardService

* [PM-5880] Adjusting how readText is handled within BrowserClipboardService

* [PM-5880] Working through implementation of chrome offscreen API usage

* [PM-5880] Implementing jest tests for the methods added to the BrowserApi class

* [PM-5880] Implementing jest tests for the OffscreenDocument class

* [PM-5880] Working through jest tests for BrowserClipboardService

* [PM-5880] Adding typing information to the clipboard methods present within the BrowserPlatformUtilsService

* [PM-5880] Working on adding ServiceWorkerGlobalScope typing information

* [PM-5880] Updating window references when calling BrowserPlatformUtils methods

* [PM-5880] Finishing out jest tests for the BrowserClipboardService

* [PM-5880] Finishing out jest tests for the BrowserClipboardService

* [PM-5880] Implementing jest tests to validate the changes within BrowserApi

* [PM-5880] Implementing jest tests to ensure coverage within OffscreenDocument

* [PM-5880] Implementing jest tests for the BrowserPlatformUtilsService

* [PM-5880] Removing unused catch statements

* [PM-5880] Implementing jest tests for the BrowserPlatformUtilsService

* [PM-5880] Implementing jest tests for the BrowserPlatformUtilsService

* [PM-5880] Fixing broken tests
2024-03-06 16:33:38 +00:00

141 lines
2.3 KiB
TypeScript

// Add chrome storage api
const QUOTA_BYTES = 10;
const storage = {
local: {
set: jest.fn(),
get: jest.fn(),
remove: jest.fn(),
QUOTA_BYTES,
getBytesInUse: jest.fn(),
clear: jest.fn(),
},
session: {
set: jest.fn(),
get: jest.fn(),
has: jest.fn(),
remove: jest.fn(),
},
};
const runtime = {
onMessage: {
addListener: jest.fn(),
removeListener: jest.fn(),
},
sendMessage: jest.fn(),
getManifest: jest.fn(() => ({ version: 2 })),
getURL: jest.fn((path) => `chrome-extension://id/${path}`),
connect: jest.fn(),
onConnect: {
addListener: jest.fn(),
removeListener: jest.fn(),
},
reload: jest.fn(),
};
const contextMenus = {
create: jest.fn(),
removeAll: jest.fn(),
};
const i18n = {
getMessage: jest.fn(),
getUILanguage: jest.fn(),
};
const tabs = {
get: jest.fn(),
executeScript: jest.fn(),
sendMessage: jest.fn(),
query: jest.fn(),
onActivated: {
addListener: jest.fn(),
removeListener: jest.fn(),
},
onReplaced: {
addListener: jest.fn(),
removeListener: jest.fn(),
},
onUpdated: {
addListener: jest.fn(),
removeListener: jest.fn(),
},
onRemoved: {
addListener: jest.fn(),
removeListener: jest.fn(),
},
};
const scripting = {
executeScript: jest.fn(),
};
const windows = {
create: jest.fn(),
get: jest.fn(),
getCurrent: jest.fn(),
update: jest.fn(),
remove: jest.fn(),
onFocusChanged: {
addListener: jest.fn(),
removeListener: jest.fn(),
},
};
const port = {
onMessage: {
addListener: jest.fn(),
removeListener: jest.fn(),
},
postMessage: jest.fn(),
};
const privacy = {
services: {
autofillAddressEnabled: {
get: jest.fn(),
set: jest.fn(),
},
autofillCreditCardEnabled: {
get: jest.fn(),
set: jest.fn(),
},
passwordSavingEnabled: {
get: jest.fn(),
set: jest.fn(),
},
},
};
const extension = {
getBackgroundPage: jest.fn(),
getViews: jest.fn(),
};
const offscreen = {
createDocument: jest.fn(),
closeDocument: jest.fn((callback) => {
if (callback) {
callback();
}
}),
Reason: {
CLIPBOARD: "clipboard",
},
};
// set chrome
global.chrome = {
i18n,
storage,
runtime,
contextMenus,
tabs,
scripting,
windows,
port,
privacy,
extension,
offscreen,
} as any;