diff --git a/src/backup-restore/background/procedures/restore/index.test.ts b/src/backup-restore/background/procedures/restore/index.test.ts index dc65cff36b..54a71ebf7a 100644 --- a/src/backup-restore/background/procedures/restore/index.test.ts +++ b/src/backup-restore/background/procedures/restore/index.test.ts @@ -1,6 +1,5 @@ import BlobPolyfill from 'node-blob' import atobPolyfill from 'atob' -// import * as sinon from 'sinon' import expect from 'expect' import { BackupBackend, ObjectChange } from '../../backend' import { BackupRestoreProcedure } from '.' @@ -197,103 +196,103 @@ describe('BackupRestoreProcedure', () => { it.skip('should not restore empty objects in place of Blobs', async () => { return - const favCreateChange: ObjectChange = { - collection: 'favIcons', - operation: 'create', - objectPk: 'test.com', - object: { favIcon: {}, hostname: 'test.com' }, - timestamp: 0, - } - const pageCreateChange: ObjectChange = { - collection: 'pages', - operation: 'create', - objectPk: 'test.com/route', - object: { - url: 'test.com/route', - screenshot: {}, - hostname: 'test.com', - }, - timestamp: 0, - } - const pageUpdateChange: ObjectChange = { - collection: 'pages', - operation: 'update', - objectPk: 'test.com/route', - object: { - url: 'test.com/route', - screenshot: {}, - hostname: 'test.com', - }, - timestamp: 0, - } - const pageDeleteChange: ObjectChange = { - collection: 'pages', - operation: 'delete', - objectPk: 'test.com/route', - timestamp: 0, - } + // const favCreateChange: ObjectChange = { + // collection: 'favIcons', + // operation: 'create', + // objectPk: 'test.com', + // object: { favIcon: {}, hostname: 'test.com' }, + // timestamp: 0, + // } + // const pageCreateChange: ObjectChange = { + // collection: 'pages', + // operation: 'create', + // objectPk: 'test.com/route', + // object: { + // url: 'test.com/route', + // screenshot: {}, + // hostname: 'test.com', + // }, + // timestamp: 0, + // } + // const pageUpdateChange: ObjectChange = { + // collection: 'pages', + // operation: 'update', + // objectPk: 'test.com/route', + // object: { + // url: 'test.com/route', + // screenshot: {}, + // hostname: 'test.com', + // }, + // timestamp: 0, + // } + // const pageDeleteChange: ObjectChange = { + // collection: 'pages', + // operation: 'delete', + // objectPk: 'test.com/route', + // timestamp: 0, + // } - const createObject = sinon.fake() - const updateOneObject = sinon.fake() - const updateObjects = sinon.fake() - const deleteOneObject = sinon.fake() - const deleteObjects = sinon.fake() + // const createObject = sinon.fake() + // const updateOneObject = sinon.fake() + // const updateObjects = sinon.fake() + // const deleteOneObject = sinon.fake() + // const deleteObjects = sinon.fake() - const restoreProcedure = new BackupRestoreProcedure({ - backend: null, - storageManager: { - collection: () => ({ - createObject, - deleteOneObject, - deleteObjects, - updateOneObject, - updateObjects, - }), - registry: { - collections: { - pages: { pkIndex: 'test' }, - favIcons: { pkIndex: 'test' }, - }, - }, - } as any, - logErrors: false, - storage: null, - }) - restoreProcedure._getBlobClass = () => - typeof Blob !== 'undefined' ? Blob : BlobPolyfill - restoreProcedure._getAtobFunction = () => - typeof atob !== 'undefined' ? atob : atobPolyfill + // const restoreProcedure = new BackupRestoreProcedure({ + // backend: null, + // storageManager: { + // collection: () => ({ + // createObject, + // deleteOneObject, + // deleteObjects, + // updateOneObject, + // updateObjects, + // }), + // registry: { + // collections: { + // pages: { pkIndex: 'test' }, + // favIcons: { pkIndex: 'test' }, + // }, + // }, + // } as any, + // logErrors: false, + // storage: null, + // }) + // restoreProcedure._getBlobClass = () => + // typeof Blob !== 'undefined' ? Blob : BlobPolyfill + // restoreProcedure._getAtobFunction = () => + // typeof atob !== 'undefined' ? atob : atobPolyfill - const { - screenshot, - ...pageWithoutScreenshotKey - } = pageCreateChange.object + // const { + // screenshot, + // ...pageWithoutScreenshotKey + // } = pageCreateChange.object - expect(createObject.callCount).toBe(0) - await restoreProcedure._writeChange(favCreateChange) - expect(createObject.callCount).toBe(0) + // expect(createObject.callCount).toBe(0) + // await restoreProcedure._writeChange(favCreateChange) + // expect(createObject.callCount).toBe(0) - await restoreProcedure._writeChange(pageCreateChange) - expect(createObject.lastCall.calledWith(pageWithoutScreenshotKey)).toBe( - true, - ) + // await restoreProcedure._writeChange(pageCreateChange) + // expect(createObject.lastCall.calledWith(pageWithoutScreenshotKey)).toBe( + // true, + // ) - await restoreProcedure._writeChange(pageUpdateChange) - expect( - updateObjects.lastCall.calledWith( - { - test: pageUpdateChange.objectPk, - }, - pageWithoutScreenshotKey, - ), - ).toBe(true) + // await restoreProcedure._writeChange(pageUpdateChange) + // expect( + // updateObjects.lastCall.calledWith( + // { + // test: pageUpdateChange.objectPk, + // }, + // pageWithoutScreenshotKey, + // ), + // ).toBe(true) - await restoreProcedure._writeChange(pageDeleteChange) - expect( - deleteObjects.lastCall.calledWith({ - test: pageDeleteChange.objectPk, - }), - ).toBe(true) + // await restoreProcedure._writeChange(pageDeleteChange) + // expect( + // deleteObjects.lastCall.calledWith({ + // test: pageDeleteChange.objectPk, + // }), + // ).toBe(true) }) it.skip('should correctly restore screenshot blobs', async () => { diff --git a/src/content-scripts/content_script/global.ts b/src/content-scripts/content_script/global.ts index d90affbd6d..3f4bdf0c42 100644 --- a/src/content-scripts/content_script/global.ts +++ b/src/content-scripts/content_script/global.ts @@ -125,6 +125,7 @@ import { } from '@worldbrain/memex-common/lib/subscriptions/constants' import type { RemoteSearchInterface } from 'src/search/background/types' import * as anchoring from '@worldbrain/memex-common/lib/annotations' +import { getWindow } from 'src/util/get-Window' // Content Scripts are separate bundles of javascript code that can be loaded // on demand by the browser, as needed. This main function manages the initialisation @@ -1093,6 +1094,7 @@ export async function main( imageSupport: runInBackground(), pkmSyncBG: runInBackground(), getRootElement: null, + windowAPI: getWindow(), }) components.sidebar?.resolve() }, diff --git a/src/sidebar/annotations-sidebar/containers/logic.test.ts b/src/sidebar/annotations-sidebar/containers/logic.test.ts index 82e4543002..3a4241ee12 100644 --- a/src/sidebar/annotations-sidebar/containers/logic.test.ts +++ b/src/sidebar/annotations-sidebar/containers/logic.test.ts @@ -114,7 +114,7 @@ const setupLogicHelper = async ({ backgroundModules.summarizeBG.remoteFunctions, ) as any, browserAPIs: device.browserAPIs, - windowAPI: device.windowAPI, + windowAPI: window, customListsBG: backgroundModules.customLists.remoteFunctions, contentSharingBG: backgroundModules.contentSharing.remoteFunctions, contentSharingByTabsBG: insertBackgroundFunctionTab( diff --git a/src/tab-management/background/index.test.ts b/src/tab-management/background/index.test.ts index cfdfa49ed2..7e3a565be7 100644 --- a/src/tab-management/background/index.test.ts +++ b/src/tab-management/background/index.test.ts @@ -9,61 +9,62 @@ describe('activity logger background tests', () => { it( 'should be able to track existing tabs', async ({ device }) => { - const { browserAPIs } = device - const { tabManagement } = device.backgroundModules + return + // const { browserAPIs } = device + // const { tabManagement } = device.backgroundModules - const mockTabs = [ - { id: 0, url: 'https://test.com', status: 'complete' }, - { id: 1, url: 'chrome://extensions', status: 'loading' }, - { id: 2, url: 'https://test.com/1', status: 'complete' }, - { id: 3, url: 'https://test.com/2', status: 'loading' }, - { id: 4, url: 'https://test.com/3', status: 'complete' }, - { id: 5, url: 'https://worldbrain.io', status: 'complete' }, - ] as Tabs.Tab[] + // const mockTabs = [ + // { id: 0, url: 'https://test.com', status: 'complete' }, + // { id: 1, url: 'chrome://extensions', status: 'loading' }, + // { id: 2, url: 'https://test.com/1', status: 'complete' }, + // { id: 3, url: 'https://test.com/2', status: 'loading' }, + // { id: 4, url: 'https://test.com/3', status: 'complete' }, + // { id: 5, url: 'https://worldbrain.io', status: 'complete' }, + // ] as Tabs.Tab[] - const createScriptCallObj = (tabId: number, file: string) => ({ - id: tabId, - script: { file, runAt: 'document_idle' }, - }) + // const createScriptCallObj = (tabId: number, file: string) => ({ + // id: tabId, + // script: { file, runAt: 'document_idle' }, + // }) - // Mock out tabs API, so it sets something we can check - browserAPIs.tabs.query = async () => mockTabs + // // Mock out tabs API, so it sets something we can check + // browserAPIs.tabs.query = async () => mockTabs - const executeScriptsCalls: Array<{ - id: number - script: { file: string } - }> = [] - browserAPIs.tabs.executeScript = (async (tabId, script) => { - executeScriptsCalls.push({ id: tabId!, script }) - return [] - }) as any - await tabManagement.trackExistingTabs() + // const executeScriptsCalls: Array<{ + // id: number + // script: { file: string } + // }> = [] + // browserAPIs.tabs.executeScript = (async (tabId, script) => { + // executeScriptsCalls.push({ id: tabId!, script }) + // return [] + // }) as any + // await tabManagement.trackExistingTabs() - expect([...tabManagement.tabManager._tabs.entries()]).toEqual( - mockTabs.map((tab) => [ - tab.id, - expect.objectContaining({ - id: tab.id, - url: tab.url, - isLoaded: tab.status === 'complete', - }), - ]), - ) + // expect([...tabManagement.tabManager._tabs.entries()]).toEqual( + // mockTabs.map((tab) => [ + // tab.id, + // expect.objectContaining({ + // id: tab.id, + // url: tab.url, + // isLoaded: tab.status === 'complete', + // }), + // ]), + // ) - const expectedCalls = [] - mockTabs.forEach((tab) => { - if (tab.id === 1) { - return - } + // const expectedCalls = [] + // mockTabs.forEach((tab) => { + // if (tab.id === 1) { + // return + // } - expectedCalls.push( - createScriptCallObj(tab.id, '/lib/browser-polyfill.js'), - createScriptCallObj(tab.id, '/content_script.js'), - ) - }) - expect(executeScriptsCalls).toEqual( - expect.arrayContaining(expectedCalls), - ) + // expectedCalls.push( + // createScriptCallObj(tab.id, '/lib/browser-polyfill.js'), + // createScriptCallObj(tab.id, '/content_script.js'), + // ) + // }) + // expect(executeScriptsCalls).toEqual( + // expect.arrayContaining(expectedCalls), + // ) }, { shouldSkip: true }, ) diff --git a/src/tests/background-integration-tests.ts b/src/tests/background-integration-tests.ts index e9c54d12be..5327caf9ac 100644 --- a/src/tests/background-integration-tests.ts +++ b/src/tests/background-integration-tests.ts @@ -366,7 +366,7 @@ export function registerBackgroundIntegrationTest( test: BackgroundIntegrationTest, options: BackgroundIntegrationTestSetupOpts = {}, ) { - it.skip(test.description + ' - single device', async () => { + it(test.description + ' - single device', async () => { await runBackgroundIntegrationTest(test, { ...options, ...(test.customTestOpts ?? {}), diff --git a/src/tests/integration-tests.ts b/src/tests/integration-tests.ts index 252f8aa43c..7dd4c124a9 100644 --- a/src/tests/integration-tests.ts +++ b/src/tests/integration-tests.ts @@ -64,7 +64,6 @@ export interface BackgroundIntegrationTestSetup { persistentStorageManager: StorageManager backgroundModules: BackgroundModules browserAPIs: Browser - windowAPI: Window services: Services browserLocalStorage: MemoryBrowserStorage storageChangeDetector: StorageChangeDetector