Skip to content
This repository has been archived by the owner on Feb 24, 2023. It is now read-only.

Commit

Permalink
bump coverage :)
Browse files Browse the repository at this point in the history
  • Loading branch information
moribellamy committed May 16, 2020
1 parent 78c21eb commit 51ef9c7
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 4 deletions.
115 changes: 115 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"sinon-chrome": "^3.0.1",
"ts-loader": "^6.2.2",
"ts-node": "^8.10.1",
"ts-sinon": "^1.2.0",
"typescript": "^3.8.3",
"web-ext": "^4.2.0",
"webextension-polyfill-ts": "^0.9.1",
Expand Down
2 changes: 1 addition & 1 deletion src/brokers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface Payload<T> {
message: T;
}

type BrokerConsumer<MessageT> = (msg: MessageT, sender: any, unsubFunc: () => void) => void;
export type BrokerConsumer<MessageT> = (msg: MessageT, sender: any, unsubFunc: () => void) => void;
type MessageHandler<MessageT> = (payload: Payload<MessageT>, sender: any) => void;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function makeElement(
attrs: { [key: string]: string } = {},
children?: string | Element[],
): Element {
const elem = document.createElement(type);
const elem = DOCUMENT.get().createElement(type);
for (const key in attrs) {
elem.setAttribute(key, attrs[key]);
}
Expand Down
45 changes: 43 additions & 2 deletions tests/grayTabby.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,25 @@ import { JSDOM } from 'jsdom';
import * as mockBrowser from 'sinon-chrome';
import { grayTabby } from '../src/ui';
import { OPTIONS_KEY } from '../src/options';
import { INDEX_V1_KEY, INDEX_V2_KEY } from '../src/tabs';
import { BROWSER, DOCUMENT } from '../src/globals';
import { INDEX_V1_KEY, INDEX_V2_KEY, dateFromKey } from '../src/tabs';
import { BROWSER, DOCUMENT, ARCHIVAL } from '../src/globals';
import { BrowserTab } from '../@types/graytabby';
import { Broker, BrokerConsumer } from '../src/brokers';

function testTab(args: Partial<BrowserTab>): BrowserTab {
return {
index: 1,
incognito: false,
highlighted: false,
active: false,
pinned: false,
...args,
};
}

// function wait(ms: number) {
// return new Promise(resolve => setTimeout(resolve, ms));
// }

describe('graytabby', function() {
this.beforeEach(async function() {
Expand All @@ -28,4 +45,28 @@ describe('graytabby', function() {
it('should attach to dom without throwing', async () => {
await getGrayTabby();
});

it('should suppport basic archival', async () => {
const archival = new Broker<BrowserTab[]>('moreTabs');
// Capture callback for tab archival so we can inject tabs in test.
let consumer: BrokerConsumer<BrowserTab[]>;
archival.sub = func => {
consumer = func;
};
ARCHIVAL.set(archival);
await getGrayTabby();

let group: HTMLDivElement = DOCUMENT.get().querySelector('#groups > div');
assert.equal(group, null);

consumer([testTab({ url: 'http://example.com' })], {}, () => null);
group = DOCUMENT.get().querySelector('#groups > div');
assert.notEqual(group, null);

mockBrowser.storage.local.get
.withArgs(INDEX_V2_KEY)
.returns(new Promise(() => [dateFromKey(group.id)]));
const a: HTMLAnchorElement = group.querySelector('a');
a.click();
});
});

0 comments on commit 51ef9c7

Please sign in to comment.