Skip to content
Permalink
Browse files

Fix tests

  • Loading branch information...
rafaelgssa committed Sep 29, 2019
1 parent f20afd7 commit 93c48288b179440717f50dd704d3784629300ace
Showing with 25 additions and 14 deletions.
  1. +9 −10 test/ItemParser.js
  2. +6 −0 test/content/EventWatcher.js
  3. +10 −4 test/content/Scrobble.js
@@ -7,27 +7,32 @@ describe(`ItemParser`, () => {
sinon.spy(ItemParser, `isReady`);
});

beforeEach(() => {
sinon.stub(NetflixApiUtils, `getSession`).resolves();
});

afterEach(() => {
ItemParser.isReady.resetHistory();
NetflixApiUtils.getSession.restore();
});

after(() => {
ItemParser.isReady.restore();
});

it(`isReady() returns true when the URL indicates that the user is watching something`, () => {
it(`isReady() returns true when the URL indicates that the user is watching something`, async () => {
const url = `/watch/12345678`;
sinon.stub(ItemParser, `getLocation`).returns(url);
expect(ItemParser.isReady()).to.be.true;
expect(await ItemParser.isReady()).to.be.true;
expect(ItemParser.getLocation.callCount).to.equal(1);
expect(ItemParser.getLocation.returnValues[0]).to.equal(url);
ItemParser.getLocation.restore();
});

it(`isReady() returns false when the URL indicates that the user is not watching something`, () => {
it(`isReady() returns false when the URL indicates that the user is not watching something`, async () => {
const url = `/browse`;
sinon.stub(ItemParser, `getLocation`).returns(url);
expect(ItemParser.isReady()).to.be.false;
expect(await ItemParser.isReady()).to.be.false;
expect(ItemParser.getLocation.callCount).to.equal(1);
expect(ItemParser.getLocation.returnValues[0]).to.equal(url);
ItemParser.getLocation.restore();
@@ -38,7 +43,6 @@ describe(`ItemParser`, () => {
sinon.stub(NetflixApiUtils, `getMetadata`).withArgs(`12345678`).resolves(`Test`);
const result = await ItemParser.start();
expect(ItemParser.isReady.callCount).to.equal(1);
expect(ItemParser.isReady.returnValues[0]).to.be.true;
expect(NetflixApiUtils.getMetadata.callCount).to.equal(1);
expect(NetflixApiUtils.getMetadata.args[0]).to.deep.equal([`12345678`]);
expect(result).to.equal(`Test`);
@@ -55,8 +59,6 @@ describe(`ItemParser`, () => {
}, 500);
const result = await ItemParser.start();
expect(ItemParser.isReady.callCount).to.equal(2);
expect(ItemParser.isReady.returnValues[0]).to.be.false;
expect(ItemParser.isReady.returnValues[1]).to.be.true;
expect(NetflixApiUtils.getMetadata.callCount).to.equal(1);
expect(NetflixApiUtils.getMetadata.args[0]).to.deep.equal([`12345678`]);
expect(result).to.equal(`Test`);
@@ -69,9 +71,6 @@ describe(`ItemParser`, () => {
sinon.stub(NetflixApiUtils, `getMetadata`);
ItemParser.start();
setTimeout(() => {
expect(ItemParser.isReady.callCount).to.equal(2);
expect(ItemParser.isReady.returnValues[0]).to.be.false;
expect(ItemParser.isReady.returnValues[1]).to.be.false;
expect(NetflixApiUtils.getMetadata.callCount).to.equal(0);
NetflixApiUtils.getMetadata.restore();
ItemParser.getLocation.restore();
@@ -1,6 +1,7 @@
import sinon from 'sinon';
import EventWatcher from '../../src/class/content/EventWatcher';
import NetflixTestUtils from '../../test-helpers/NetflixTestHelper';
import NetflixApiUtils from '../../src/class/NetflixApiUtils';

const onPlay = sinon.spy();
const onStop = sinon.spy();
@@ -10,11 +11,16 @@ events.startListeners();

describe(`EventWatcher`, () => {
beforeEach(() => {
sinon.stub(NetflixApiUtils, `getSession`).resolves();
document.body.innerHTML = ``;
onPlay.resetHistory();
onStop.resetHistory();
});

afterEach(() => {
NetflixApiUtils.getSession.restore();
});

it(`onStop() and onPlay() are called when the url changes from a show to another`, async () => {
NetflixTestUtils.renderPlayer(`show`);
await events.onUrlChange(`/watch/1`, `/watch/2`);
@@ -1,9 +1,11 @@
import browser from 'sinon-chrome';
import fakeFetch from '../../test-helpers/fake-fetch';
import sinon from 'sinon';
import Settings from '../../src/settings';
import Scrobble from '../../src/class/content/Scrobble';
import NetflixTestUtils from '../../test-helpers/NetflixTestHelper';
import Shared from '../../src/class/Shared';
import NetflixApiUtils from '../../src/class/NetflixApiUtils';

Shared.setBackgroundPage(true);

@@ -74,16 +76,20 @@ describe(`Scrobble`, () => {
expect(scrobbleShow.url).to.equal(`${Settings.apiUri}/scrobble`);
});

it(`checkForChanges() sets the progress for movie`, () => {
it(`checkForChanges() sets the progress for movie`, async () => {
sinon.stub(NetflixApiUtils, `getSession`).resolves();
NetflixTestUtils.renderPlayer(`movie`);
scrobbleMovie.checkForChanges();
await scrobbleMovie.checkForChanges();
expect(scrobbleMovie.progress.toFixed(2)).to.equal(`2.91`);
NetflixApiUtils.getSession.restore();
});

it(`checkForChanges() sets the progress for show`, () => {
it(`checkForChanges() sets the progress for show`, async () => {
sinon.stub(NetflixApiUtils, `getSession`).resolves();
NetflixTestUtils.renderPlayer(`show`);
scrobbleShow.checkForChanges();
await scrobbleShow.checkForChanges();
expect(scrobbleShow.progress.toFixed(2)).to.equal(`1.57`);
NetflixApiUtils.getSession.restore();
});

it(`start() calls success`, done => {

0 comments on commit 93c4828

Please sign in to comment.
You can’t perform that action at this time.