diff --git a/manifest.json b/manifest.json index dbba8b7..69c08f7 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "name": "graytabby", - "version": "19.12.11", + "version": "20.05.17", "icons": { "128": "assets/img/blobbycat/browseraction128.png" }, diff --git a/src/lib/utils.ts b/src/lib/utils.ts index a8af40f..8ca9d79 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -7,6 +7,14 @@ export function fieldKeeper(obj: T, ...keys: K[]): Pickargs[i]] = args[i + 1]; + } + return ret; +} + export async function save(key: string, value: any): Promise { const record: any = {}; record[key] = value; diff --git a/tests/archive.test.ts b/tests/archive.test.ts index 66c65b6..196a1fe 100644 --- a/tests/archive.test.ts +++ b/tests/archive.test.ts @@ -1,12 +1,12 @@ import { expect } from 'chai'; -import * as mockBrowser from 'sinon-chrome'; import { archivePlan } from '../src/bg/archive'; import { Broker, BrokerConsumer } from '../src/lib/brokers'; import { ARCHIVAL, DOCUMENT } from '../src/lib/globals'; import { dateFromKey, INDEX_V2_KEY } from '../src/app/tabs'; -import { assertElement, testTab, stubGlobals, unstubGlobals } from './utils'; +import { assertElement, testTab, stubGlobals, unstubGlobals, mockedBrowser } from './utils'; import { BrowserTab } from '../src/lib/types'; import { graytabby } from '../src/app/ui'; +import { dictOf } from '../src/lib/utils'; describe('archive operation', function() { beforeEach(async function() { @@ -32,9 +32,9 @@ describe('archive operation', function() { consumer([testTab({ url: 'http://example.com' })], {}, () => null); const group = assertElement('#groups > div', DOCUMENT.get()); - mockBrowser.storage.local.get - .withArgs(INDEX_V2_KEY) - .returns(new Promise(() => [dateFromKey(group.id)])); + mockedBrowser() + .storage.local.get.withArgs(INDEX_V2_KEY) + .returns(Promise.resolve(dictOf(INDEX_V2_KEY, [dateFromKey(group.id)]))); const a = assertElement('a', group); a.click(); }); diff --git a/tests/tabs.test.ts b/tests/tabs.test.ts new file mode 100644 index 0000000..a279a1c --- /dev/null +++ b/tests/tabs.test.ts @@ -0,0 +1,52 @@ +import { expect } from 'chai'; +import { GrayTabGroup, INDEX_V1_KEY, loadAllTabGroups } from '../src/app/tabs'; +import { dictOf } from '../src/lib/utils'; +import { mockedBrowser, stubGlobals, unstubGlobals } from './utils'; + +describe('tabs', function() { + beforeEach(async function() { + await stubGlobals(); + }); + + afterEach(function() { + unstubGlobals(); + }); + + it('should load old string format', async function() { + const oldGroups: GrayTabGroup[] = [ + { + tabs: [ + { + url: '1', + title: 'one', + key: 0, + }, + { + url: '2', + title: 'two', + key: 1, + }, + ], + date: 1589760256, // May 17 2020 in Linux Timestamp. + }, + { + tabs: [ + { + url: '3', + title: 'three', + key: 0, + }, + ], + date: 1589760257, + }, + ]; + mockedBrowser() + .storage.local.get.withArgs(INDEX_V1_KEY) + .returns(Promise.resolve(dictOf(INDEX_V1_KEY, JSON.stringify(oldGroups)))); + const groups = await loadAllTabGroups(); + for (const oldGroup of oldGroups) { + oldGroup.date *= 1000; // Seconds to millis conversion. + } + expect(groups).to.deep.equal(oldGroups); + }); +}); diff --git a/tests/utils.ts b/tests/utils.ts index 4d61536..3862498 100644 --- a/tests/utils.ts +++ b/tests/utils.ts @@ -2,10 +2,10 @@ import { expect } from 'chai'; import { JSDOM } from 'jsdom'; import * as mockBrowser from 'sinon-chrome'; import { INDEX_V1_KEY, INDEX_V2_KEY } from '../src/app/tabs'; -import { graytabby } from '../src/app/ui'; import { BROWSER, DOCUMENT } from '../src/lib/globals'; import { OPTIONS_KEY } from '../src/lib/options'; import { BrowserTab } from '../src/lib/types'; +import SinonChrome from 'sinon-chrome'; export async function stubGlobals(): Promise { BROWSER.set(mockBrowser); @@ -22,6 +22,10 @@ export function unstubGlobals(): void { DOCUMENT.set(null); } +export function mockedBrowser(): typeof SinonChrome { + return (BROWSER.get()); +} + export function testTab(args: Partial): BrowserTab { return { index: 1,