Skip to content

Commit

Permalink
Chore: enable eslint for unit tests (#738)
Browse files Browse the repository at this point in the history
  • Loading branch information
DanDeMicco authored Mar 27, 2018
1 parent daa8e86 commit 234feb0
Show file tree
Hide file tree
Showing 35 changed files with 880 additions and 516 deletions.
1 change: 0 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
src/third-party/*
dist/*
**/__tests__/*
6 changes: 6 additions & 0 deletions src/lib/__tests__/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": ["../../../.eslintrc"],
"globals": {
"Assert": false
}
}
4 changes: 2 additions & 2 deletions src/lib/__tests__/Controls-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ describe('lib/Controls', () => {

describe('clickHandler()', () => {
it('should stop block hiding', () => {
controls.clickHandler(event);
controls.clickHandler();
expect(controls.shouldHide).to.be.true;
});
});
Expand Down Expand Up @@ -297,5 +297,5 @@ describe('lib/Controls', () => {
document.activeElement.classList.remove('bp-page-num-input');
expect(controls.isPageNumFocused()).to.be.false;
});
})
});
});
30 changes: 13 additions & 17 deletions src/lib/__tests__/DownloadReachability-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import * as util from '../util';

const sandbox = sinon.sandbox.create();

const DEFAULT_DOWNLOAD_HOST_PREFIX = 'https://dl.';
const DOWNLOAD_NOTIFICATION_SHOWN_KEY = 'download_host_notification_shown';
const DOWNLOAD_HOST_FALLBACK_KEY = 'download_host_fallback';

Expand All @@ -20,13 +19,12 @@ describe('lib/DownloadReachability', () => {
sessionStorage.clear();
localStorage.clear();
sandbox.verifyAndRestore();

});

describe('isCustomDownloadHost()', () => {
it('should be true if the url does not start with the default host prefix but is a dl host', () => {
let url = 'https://dl3.boxcloud.com/foo';
let result = DownloadReachability.isCustomDownloadHost(url)
const result = DownloadReachability.isCustomDownloadHost(url);
expect(result).to.be.true;

url = 'https://dl.boxcloud.com/foo';
Expand All @@ -35,14 +33,12 @@ describe('lib/DownloadReachability', () => {
url = 'https://www.google.com';
expect(DownloadReachability.isCustomDownloadHost(url)).to.be.false;


url = 'https://kld3lk.boxcloud.com';
expect(DownloadReachability.isCustomDownloadHost(url)).to.be.true;

url = 'https://dl3.user.inside-box.net';
expect(DownloadReachability.isCustomDownloadHost(url)).to.be.true;


url = 'https://dl.user.inside-box.net';
expect(DownloadReachability.isCustomDownloadHost(url)).to.be.false;
});
Expand All @@ -52,7 +48,7 @@ describe('lib/DownloadReachability', () => {
it('should add the given host to the array of shown hosts', () => {
const blockedHost = 'https://dl3.boxcloud.com';

const result = DownloadReachability.setDownloadHostNotificationShown(blockedHost);
DownloadReachability.setDownloadHostNotificationShown(blockedHost);

const shownHostsArr = JSON.parse(localStorage.getItem(DOWNLOAD_NOTIFICATION_SHOWN_KEY)) || [];
expect(shownHostsArr).to.contain('https://dl3.boxcloud.com');
Expand All @@ -61,12 +57,11 @@ describe('lib/DownloadReachability', () => {

describe('setDownloadHostFallback()', () => {
it('should set the download host fallback key to be true', () => {
expect(sessionStorage.getItem(DOWNLOAD_HOST_FALLBACK_KEY)).to.not.equal('true')
expect(sessionStorage.getItem(DOWNLOAD_HOST_FALLBACK_KEY)).to.not.equal('true');

DownloadReachability.setDownloadHostFallback();

expect(sessionStorage.getItem(DOWNLOAD_HOST_FALLBACK_KEY)).to.equal('true')

expect(sessionStorage.getItem(DOWNLOAD_HOST_FALLBACK_KEY)).to.equal('true');
});
});

Expand Down Expand Up @@ -97,7 +92,7 @@ describe('lib/DownloadReachability', () => {

it('should return true if we do not have an entry for the given host and our session indicates we are falling back to the default host', () => {
let result = DownloadReachability.getDownloadNotificationToShow('https://foo.com');
expect(result).to.be.undefined;;
expect(result).to.be.undefined;

sessionStorage.setItem('download_host_fallback', 'true');
result = DownloadReachability.getDownloadNotificationToShow('https://dl5.boxcloud.com');
Expand All @@ -107,17 +102,16 @@ describe('lib/DownloadReachability', () => {
localStorage.setItem('download_host_notification_shown', JSON.stringify(shownHostsArr));
result = DownloadReachability.getDownloadNotificationToShow('https://dl5.boxcloud.com');
expect(result).to.be.undefined;

});
});

describe('setDownloadReachability()', () => {
afterEach(() => {
fetchMock.restore();
})
});
it('should catch an errored response', () => {
const setDownloadHostFallbackStub = sandbox.stub(DownloadReachability, 'setDownloadHostFallback');
fetchMock.head('https://dl3.boxcloud.com', {throws: new Error()})
fetchMock.head('https://dl3.boxcloud.com', { throws: new Error() });

return DownloadReachability.setDownloadReachability('https://dl3.boxcloud.com').catch(() => {
expect(setDownloadHostFallbackStub).to.be.called;
Expand Down Expand Up @@ -178,10 +172,12 @@ describe('lib/DownloadReachability', () => {
it('should retry download with default host if custom host is blocked', (done) => {
sandbox.stub(DownloadReachability, 'isDownloadHostBlocked').returns(false);
sandbox.stub(DownloadReachability, 'isCustomDownloadHost').returns(true);
sandbox.stub(DownloadReachability, 'setDownloadReachability').returns(new Promise((resolve) => {
resolve(true);
done();
}));
sandbox.stub(DownloadReachability, 'setDownloadReachability').returns(
new Promise((resolve) => {
resolve(true);
done();
})
);
sandbox.stub(util, 'openUrlInsideIframe');

const downloadUrl = 'https://custom.boxcloud.com/blah';
Expand Down
2 changes: 1 addition & 1 deletion src/lib/__tests__/Fullscreen-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ describe('lib/Fullscreen', () => {

it('should be called only once when the fullscreenchange event is emitted', () => {
const spy = sandbox.spy(fullscreen, 'fullscreenchangeHandler');
//rebind the dom listeners to use the spy
// rebind the dom listeners to use the spy
fullscreen.bindDOMListeners();

const event = new Event('webkitfullscreenchange');
Expand Down
4 changes: 2 additions & 2 deletions src/lib/__tests__/Logger-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ let logger;
const sandbox = sinon.sandbox.create();

describe('lib/Logger', () => {
let dateNowStub = sandbox.stub(Date, 'now');
const dateNowStub = sandbox.stub(Date, 'now');

beforeEach(() => {
dateNowStub.returns(0);
Expand Down Expand Up @@ -41,7 +41,7 @@ describe('lib/Logger', () => {
});

it('should set and get correctly', () => {
dateNowStub.returns(0);
dateNowStub.returns(0);
logger.setCached();
logger.setCacheStale();
logger.setFile({ id: 1 });
Expand Down
20 changes: 4 additions & 16 deletions src/lib/__tests__/PageControls-test.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,15 @@
/* eslint-disable no-unused-expressions */
import PageControls from '../PageControls';
import Controls from '../Controls';
import { CLASS_HIDDEN } from './../constants';
import fullscreen from '../Fullscreen';
import Browser from '../Browser';
import { decodeKeydown } from '../util';
import { ICON_DROP_DOWN, ICON_DROP_UP } from '../icons/icons';

let pageControls;
let clock;
let stubs = {};

const sandbox = sinon.sandbox.create();

const SHOW_PREVIEW_CONTROLS_CLASS = 'box-show-preview-controls';
const RESET_TIMEOUT_CLOCK_TICK = 2001;

const SHOW_PAGE_NUM_INPUT_CLASS = 'show-page-number-input';
const CONTROLS_PAGE_NUM_WRAPPER_CLASS = 'bp-page-num-wrapper';
const CONTROLS_CURRENT_PAGE = 'bp-current-page';
const CONTROLS_PAGE_NUM_INPUT_CLASS = 'bp-page-num-input';
const CONTROLS_TOTAL_PAGES = 'bp-total-pages';
const PAGE_NUM = 'bp-page-num';
const PREV_PAGE = 'bp-previous-page';
const NEXT_PAGE = 'bp-next-page';
Expand Down Expand Up @@ -206,7 +195,7 @@ describe('lib/PageControls', () => {
beforeEach(() => {
pageControls.currentPageEl = {
textContent: '1'
}
};
});

describe('getCurrentPageNumber()', () => {
Expand All @@ -223,12 +212,11 @@ describe('lib/PageControls', () => {
expect(currPageNum).to.equal(3);
});
});
})

});

describe('getTotalPages()', () => {
it('should return the total number of pages', () => {
pageControls.add(1 , 10);
pageControls.add(1, 10);
expect(pageControls.getTotalPages()).to.equal(10);
});
});
Expand Down Expand Up @@ -271,7 +259,7 @@ describe('lib/PageControls', () => {
};
pageControls.contentEl = {
focus: sandbox.stub()
}
};
stubs.browser = sandbox.stub(Browser, 'getName').returns('Explorer');
stubs.hidePageNumInput = sandbox.stub(pageControls, 'hidePageNumInput');
});
Expand Down
2 changes: 1 addition & 1 deletion src/lib/__tests__/Popup-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ describe('lib/Popup', () => {
});

it('should set the button handler if it exists', () => {
const handler = () => {};
const handler = () => {}; // eslint-disable-line require-jsdoc

popup.show('message', 'button', undefined);
expect(popup.buttonEl.handler).to.equal(undefined);
Expand Down
Loading

0 comments on commit 234feb0

Please sign in to comment.