From 75277fc5e15db7bbe6a85149877fde28227468a7 Mon Sep 17 00:00:00 2001 From: Sumedha Pramod Date: Thu, 29 Mar 2018 15:05:33 -0700 Subject: [PATCH] Chore: Run eslint on test files (#149) * Chore: Run eslint on test files * Chore: Fix tests --- .babelrc | 4 +- .eslintignore | 2 +- .eslintrc | 3 +- src/__tests__/AnnotationDialog-test.js | 1 - src/__tests__/AnnotationService-test.js | 17 +- src/__tests__/AnnotationThread-test.js | 3 - src/__tests__/Annotator-test.js | 134 ++++++++------- src/__tests__/BoxAnnotations-test.js | 8 +- src/__tests__/CreateAnnotationDialog-test.js | 13 +- src/__tests__/util-test.js | 68 ++++---- .../AnnotationModeController-test.js | 21 ++- .../__tests__/DrawingModeController-test.js | 21 ++- .../__tests__/HighlightModeController-test.js | 13 +- .../__tests__/PointModeController-test.js | 9 +- .../__tests__/CreateHighlightDialog-test.js | 12 +- src/doc/__tests__/DocAnnotator-test.js | 152 ++++++++++-------- src/doc/__tests__/DocDrawingDialog-test.js | 31 ++-- src/doc/__tests__/DocDrawingThread-test.js | 38 ++--- src/doc/__tests__/DocHighlightDialog-test.js | 23 +-- src/doc/__tests__/DocHighlightThread-test.js | 25 +-- src/doc/__tests__/DocPointDialog-test.js | 1 - src/doc/__tests__/docUtil-test.js | 19 +-- .../__tests__/DrawingContainer-test.js | 42 ++--- src/drawing/__tests__/DrawingPath-test.js | 66 ++++---- src/drawing/__tests__/DrawingThread-test.js | 19 +-- src/image/__tests__/ImageAnnotator-test.js | 24 +-- src/image/__tests__/ImagePointDialog-test.js | 1 - src/image/__tests__/ImagePointThread-test.js | 2 +- 28 files changed, 376 insertions(+), 396 deletions(-) diff --git a/.babelrc b/.babelrc index 7c30e6c34..c6d2cf423 100644 --- a/.babelrc +++ b/.babelrc @@ -23,9 +23,11 @@ "plugins": [ ["istanbul", { "exclude": [ + "src/polyfill.js", "**/*-test.js", - "src/lib/polyfill.js", "build/**", + "docs/**", + "lib'**", ] }], ["babel-plugin-transform-require-ignore", { "extensions": [".scss"] }] diff --git a/.eslintignore b/.eslintignore index b5acbbae4..4674fa221 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,5 +1,5 @@ src/third-party/* dist/* +docs/* lib/* -**/__tests__/* index.js diff --git a/.eslintrc b/.eslintrc index bead7bcbf..e06820009 100644 --- a/.eslintrc +++ b/.eslintrc @@ -22,7 +22,8 @@ "sinon": false, "assert": false, "fixture": false, - "__": false + "__": false, + "Assert": false }, "rules": { "quotes": [ diff --git a/src/__tests__/AnnotationDialog-test.js b/src/__tests__/AnnotationDialog-test.js index 251627444..5cdbb5fbe 100644 --- a/src/__tests__/AnnotationDialog-test.js +++ b/src/__tests__/AnnotationDialog-test.js @@ -6,7 +6,6 @@ import * as util from '../util'; import * as constants from '../constants'; const CLASS_FLIPPED_DIALOG = 'ba-annotation-dialog-flipped'; -const CLASS_CANCEL_DELETE = 'cancel-delete-btn'; const CLASS_REPLY_TEXTAREA = 'reply-textarea'; const CLASS_REPLY_CONTAINER = 'reply-container'; const CLASS_ANIMATE_DIALOG = 'ba-animate-show-dialog'; diff --git a/src/__tests__/AnnotationService-test.js b/src/__tests__/AnnotationService-test.js index 759489eb9..9c6d0244c 100644 --- a/src/__tests__/AnnotationService-test.js +++ b/src/__tests__/AnnotationService-test.js @@ -33,6 +33,7 @@ describe('AnnotationService', () => { }); it('should (almost always) return unique GUIDs', () => { + // eslint-disable-next-line no-self-compare expect(AnnotationService.generateID() === AnnotationService.generateID()).to.be.false; }); }); @@ -103,7 +104,9 @@ describe('AnnotationService', () => { }); describe('read()', () => { - const url = `${API_HOST}/2.0/files/1/annotations?version=2&fields=item,thread,details,message,created_by,created_at,modified_at,permissions`; + const url = `${ + API_HOST + }/2.0/files/1/annotations?version=2&fields=item,thread,details,message,created_by,created_at,modified_at,permissions`; it('should return array of annotations for the specified file and file version', () => { const annotation1 = new Annotation({ @@ -266,7 +269,7 @@ describe('AnnotationService', () => { sandbox.stub(annotationService, 'read').returns(Promise.resolve(threads)); sandbox.stub(annotationService, 'createThreadMap').returns(threads); - return annotationService.getThreadMap(2).then((threadMap) => { + return annotationService.getThreadMap(2).then(() => { expect(annotationService.createThreadMap).to.be.called; }); }); @@ -459,7 +462,9 @@ describe('AnnotationService', () => { annotationService.api = 'box'; annotationService.fileId = 1; const fileVersionId = 2; - const url = `${annotationService.api}/2.0/files/${annotationService.fileId}/annotations?version=${fileVersionId}&fields=item,thread,details,message,created_by,created_at,modified_at,permissions`; + const url = `${annotationService.api}/2.0/files/${annotationService.fileId}/annotations?version=${ + fileVersionId + }&fields=item,thread,details,message,created_by,created_at,modified_at,permissions`; const result = annotationService.getReadUrl(fileVersionId); expect(result).to.equal(url); @@ -471,7 +476,11 @@ describe('AnnotationService', () => { const fileVersionId = 2; const marker = 'next_annotation'; const limit = 1; - const url = `${annotationService.api}/2.0/files/${annotationService.fileId}/annotations?version=${fileVersionId}&fields=item,thread,details,message,created_by,created_at,modified_at,permissions&marker=${marker}&limit=${limit}`; + const url = `${annotationService.api}/2.0/files/${annotationService.fileId}/annotations?version=${ + fileVersionId + }&fields=item,thread,details,message,created_by,created_at,modified_at,permissions&marker=${marker}&limit=${ + limit + }`; const result = annotationService.getReadUrl(fileVersionId, marker, limit); expect(result).to.equal(url); diff --git a/src/__tests__/AnnotationThread-test.js b/src/__tests__/AnnotationThread-test.js index ad6e1719e..6161c2482 100644 --- a/src/__tests__/AnnotationThread-test.js +++ b/src/__tests__/AnnotationThread-test.js @@ -1,5 +1,4 @@ /* eslint-disable no-unused-expressions */ -import EventEmitter from 'events'; import AnnotationThread from '../AnnotationThread'; import Annotation from '../Annotation'; import * as util from '../util'; @@ -262,7 +261,6 @@ describe('AnnotationThread', () => { it('should overwrite a local annotation to the thread if it does exist as an associated annotation', () => { const serverAnnotation = { annotationID: 123 }; const tempAnnotation = { annotationID: 1 }; - const isServerAnnotation = (annotation) => annotation === serverAnnotation; thread.annotations[tempAnnotation.annotationID] = tempAnnotation; expect(thread.annotations[123]).to.be.undefined; @@ -507,7 +505,6 @@ describe('AnnotationThread', () => { .then(() => { expect(stubs.emit).to.be.calledWith(THREAD_EVENT.threadCleanup); expect(stubs.emit).to.be.calledWith(THREAD_EVENT.delete); - done(); }) .catch(() => { sinon.assert.failException; diff --git a/src/__tests__/Annotator-test.js b/src/__tests__/Annotator-test.js index 3ed632ac7..4cb8f9586 100644 --- a/src/__tests__/Annotator-test.js +++ b/src/__tests__/Annotator-test.js @@ -3,22 +3,7 @@ import EventEmitter from 'events'; import Annotator from '../Annotator'; import * as util from '../util'; import AnnotationService from '../AnnotationService'; -import { - STATES, - TYPES, - CLASS_ANNOTATION_DRAW_MODE, - CLASS_ANNOTATION_MODE, - CLASS_ACTIVE, - CLASS_HIDDEN, - SELECTOR_ANNOTATION_BUTTON_DRAW_POST, - SELECTOR_ANNOTATION_BUTTON_DRAW_UNDO, - SELECTOR_ANNOTATION_BUTTON_DRAW_REDO, - SELECTOR_ANNOTATION_DRAWING_HEADER, - SELECTOR_BOX_PREVIEW_BASE_HEADER, - ANNOTATOR_EVENT, - THREAD_EVENT, - CONTROLLER_EVENT -} from '../constants'; +import { STATES, TYPES, ANNOTATOR_EVENT, THREAD_EVENT, CONTROLLER_EVENT } from '../constants'; let annotator; let stubs = {}; @@ -48,9 +33,9 @@ describe('Annotator', () => { const options = { annotator: { NAME: 'name', - CONTROLLERS: { 'something': stubs.controller } + CONTROLLERS: { something: stubs.controller } }, - modeButtons: { 'something': {} } + modeButtons: { something: {} } }; annotator = new Annotator({ canAnnotate: true, @@ -67,7 +52,7 @@ describe('Annotator', () => { loadError: 'load error', createError: 'create error', deleteError: 'delete error', - authError: 'auth error', + authError: 'auth error' } }); @@ -205,23 +190,27 @@ describe('Annotator', () => { it('should fetch and then render annotations', () => { annotator.fetchPromise = Promise.resolve(); annotator.loadAnnotations(); - return annotator.fetchPromise.then(() => { - expect(annotator.render).to.be.called; - expect(annotator.emit).to.not.be.called; - }).catch((err) => { - sinon.assert.failException; - }); + return annotator.fetchPromise + .then(() => { + expect(annotator.render).to.be.called; + expect(annotator.emit).to.not.be.called; + }) + .catch(() => { + sinon.assert.failException; + }); }); it('should emit an error if the annotator fails to fetch and render annotations', () => { annotator.fetchPromise = Promise.reject(); annotator.loadAnnotations(); - return annotator.fetchPromise.then(() => { - sinon.assert.failException; - }).catch((err) => { - expect(annotator.render).to.not.be.called; - expect(annotator.emit).to.be.calledWith(ANNOTATOR_EVENT.loadError, err); - }); + return annotator.fetchPromise + .then(() => { + sinon.assert.failException; + }) + .catch((err) => { + expect(annotator.render).to.not.be.called; + expect(annotator.emit).to.be.calledWith(ANNOTATOR_EVENT.loadError, err); + }); }); }); @@ -243,8 +232,8 @@ describe('Annotator', () => { describe('setupControllers()', () => { it('should instantiate controllers for enabled types', () => { - annotator.modeControllers = { 'something': stubs.controller }; - annotator.options = { modeButtons: { 'something': {} } } + annotator.modeControllers = { something: stubs.controller }; + annotator.options = { modeButtons: { something: {} } }; stubs.controllerMock.expects('init'); stubs.controllerMock.expects('addListener').withArgs('annotationcontrollerevent', sinon.match.func); @@ -252,7 +241,7 @@ describe('Annotator', () => { }); it('should setup shared point dialog in the point controller', () => { - annotator.modeControllers = { 'point': stubs.controller }; + annotator.modeControllers = { point: stubs.controller }; annotator.isMobile = true; stubs.controllerMock.expects('init'); @@ -276,7 +265,6 @@ describe('Annotator', () => { annotator.setupControllers(); }); - describe('destroy()', () => { it('should unbind custom listeners on thread and unbind DOM listeners', () => { const unbindDOMStub = sandbox.stub(annotator, 'unbindDOMListeners'); @@ -294,33 +282,33 @@ describe('Annotator', () => { describe('render()', () => { it('should call hide on each thread in map', () => { annotator.modeControllers = { - 'type': { + type: { render: sandbox.stub() }, - 'type2': { + type2: { render: sandbox.stub() } }; annotator.render(); - expect(annotator.modeControllers['type'].render).to.be.called; - expect(annotator.modeControllers['type2'].render).to.be.called; + expect(annotator.modeControllers.type.render).to.be.called; + expect(annotator.modeControllers.type2.render).to.be.called; }); }); describe('renderPage()', () => { it('should call hide on each thread in map on page 1', () => { annotator.modeControllers = { - 'type': { + type: { renderPage: sandbox.stub() }, - 'type2': { + type2: { renderPage: sandbox.stub() } }; annotator.renderPage(1); - expect(annotator.modeControllers['type'].renderPage).to.be.calledWith(1); - expect(annotator.modeControllers['type2'].renderPage).to.be.called; + expect(annotator.modeControllers.type.renderPage).to.be.calledWith(1); + expect(annotator.modeControllers.type2.renderPage).to.be.called; }); }); @@ -376,11 +364,13 @@ describe('Annotator', () => { }; const result = annotator.fetchAnnotations(); - result.then(() => { - expect(result).to.be.true; - }).catch(() => { - sinon.assert.failException; - }); + result + .then(() => { + expect(result).to.be.true; + }) + .catch(() => { + sinon.assert.failException; + }); }); it('should fetch existing annotations if the user can view all annotations', () => { @@ -391,13 +381,15 @@ describe('Annotator', () => { }; const result = annotator.fetchAnnotations(); - result.then(() => { - expect(result).to.be.true; - expect(annotator.threadMap).to.not.be.undefined; - expect(annotator.emit).to.be.calledWith(ANNOTATOR_EVENT.fetch); - }).catch(() => { - sinon.assert.failException; - }); + result + .then(() => { + expect(result).to.be.true; + expect(annotator.threadMap).to.not.be.undefined; + expect(annotator.emit).to.be.calledWith(ANNOTATOR_EVENT.fetch); + }) + .catch(() => { + sinon.assert.failException; + }); }); it('should fetch existing annotations if the user can view all annotations', () => { @@ -408,15 +400,17 @@ describe('Annotator', () => { }; const result = annotator.fetchAnnotations(); - result.then(() => { - expect(result).to.be.true; - stubs.threadPromise.then(() => { - expect(annotator.threadMap).to.not.be.undefined; - expect(annotator.emit).to.be.calledWith(ANNOTATOR_EVENT.fetch); + result + .then(() => { + expect(result).to.be.true; + stubs.threadPromise.then(() => { + expect(annotator.threadMap).to.not.be.undefined; + expect(annotator.emit).to.be.calledWith(ANNOTATOR_EVENT.fetch); + }); + }) + .catch(() => { + sinon.assert.failException; }); - }).catch(() => { - sinon.assert.failException; - }); }); }); @@ -519,7 +513,7 @@ describe('Annotator', () => { describe('handleControllerEvents()', () => { const mode = 'something'; - let data = { mode }; + const data = { mode }; beforeEach(() => { sandbox.stub(annotator, 'emit'); @@ -590,13 +584,13 @@ describe('Annotator', () => { describe('getCurrentAnnotationMode()', () => { it('should return null if no mode is enabled', () => { - annotator.modeControllers['something'] = stubs.controller; + annotator.modeControllers.something = stubs.controller; stubs.controllerMock.expects('isEnabled').returns(false); expect(annotator.getCurrentAnnotationMode()).to.be.null; }); it('should return the current annotation mode', () => { - annotator.modeControllers['something'] = stubs.controller; + annotator.modeControllers.something = stubs.controller; stubs.controllerMock.expects('isEnabled').returns(true); expect(annotator.getCurrentAnnotationMode()).to.equal('something'); }); @@ -614,7 +608,7 @@ describe('Annotator', () => { stubs.thread.dialog = { postAnnotation: sandbox.stub() }; annotator.modeControllers = { - 'point': stubs.controller + point: stubs.controller }; }); @@ -697,7 +691,7 @@ describe('Annotator', () => { it('should scroll to annotation if threadID exists on page', () => { annotator.modeControllers = { - 'type': { + type: { getThreadByID: sandbox.stub().returns(stubs.thread), threads: { 1: { '123abc': stubs.thread } } } @@ -725,7 +719,7 @@ describe('Annotator', () => { describe('toggleAnnotationMode()', () => { beforeEach(() => { - annotator.modeControllers['something'] = stubs.controller; + annotator.modeControllers.something = stubs.controller; }); it('should exit the current mode', () => { @@ -816,7 +810,7 @@ describe('Annotator', () => { it('should return false if annotations are not allowed on the current viewer', () => { annotator.options.annotator = undefined; expect(annotator.isModeAnnotatable(TYPES.point)).to.be.false; - }) + }); it('should return true if the type is supported by the viewer', () => { expect(annotator.isModeAnnotatable(TYPES.point)).to.be.true; diff --git a/src/__tests__/BoxAnnotations-test.js b/src/__tests__/BoxAnnotations-test.js index 4893ab7aa..264b228a5 100644 --- a/src/__tests__/BoxAnnotations-test.js +++ b/src/__tests__/BoxAnnotations-test.js @@ -3,8 +3,6 @@ import BoxAnnotations from '../BoxAnnotations'; import { TYPES } from '../constants'; import * as util from '../util'; import DrawingModeController from '../controllers/DrawingModeController'; -import PointModeController from '../controllers/PointModeController'; -import HighlightModeController from '../controllers/HighlightModeController'; let loader; let stubs; @@ -113,8 +111,8 @@ describe('BoxAnnotations', () => { it('should use the specified types from options', () => { loader.viewerOptions = { - 'Document': { enabledTypes: ['draw'] } - } + Document: { enabledTypes: ['draw'] } + }; expect(loader.getAnnotatorTypes(stubs.config)).to.deep.equal(['draw']); }); @@ -159,7 +157,7 @@ describe('BoxAnnotations', () => { viewer: { NAME: 'Document' } - } + }; sandbox.stub(loader, 'getAnnotatorTypes').returns(['point']); }); diff --git a/src/__tests__/CreateAnnotationDialog-test.js b/src/__tests__/CreateAnnotationDialog-test.js index 9a98a0992..e50047fe9 100644 --- a/src/__tests__/CreateAnnotationDialog-test.js +++ b/src/__tests__/CreateAnnotationDialog-test.js @@ -1,19 +1,14 @@ /* eslint-disable no-unused-expressions */ import CreateAnnotationDialog from '../CreateAnnotationDialog'; import { - CLASS_ADD_HIGHLIGHT_BTN, - CLASS_ADD_HIGHLIGHT_COMMENT_BTN, CLASS_MOBILE_CREATE_ANNOTATION_DIALOG, CLASS_ANNOTATION_DIALOG, - CLASS_ANNOTATION_CARET, CLASS_HIDDEN, CREATE_EVENT } from '../constants'; import CommentBox from '../CommentBox'; import * as util from '../util'; -const CLASS_CREATE_DIALOG = 'ba-create-annotation-dialog'; - const sandbox = sinon.sandbox.create(); let dialog; let parentEl; @@ -21,11 +16,11 @@ const localized = { highlightToggle: 'highlight toggle', highlightComment: 'highlight comment' }; -let stubs = {}; +const stubs = {}; describe('CreateAnnotationDialog', () => { beforeEach(() => { - const parentEl = document.createElement('div'); + parentEl = document.createElement('div'); parentEl.classList.add('bp-create-dialog-container'); dialog = new CreateAnnotationDialog(parentEl, { isMobile: true, @@ -215,7 +210,7 @@ describe('CreateAnnotationDialog', () => { dialog.isMobile = true; dialog.show(document.createElement('div')); - const stubs = [ + const eventStub = [ { stub: sandbox.stub(dialog.containerEl, 'removeEventListener'), args: ['touchend', dialog.stopPropagation] @@ -224,7 +219,7 @@ describe('CreateAnnotationDialog', () => { dialog.destroy(); - stubs.forEach((stub) => { + eventStub.forEach((stub) => { expect(stub.stub).to.be.calledWith(...stub.args); }); }); diff --git a/src/__tests__/util-test.js b/src/__tests__/util-test.js index 248e06b0c..4cf7d89e9 100644 --- a/src/__tests__/util-test.js +++ b/src/__tests__/util-test.js @@ -47,7 +47,6 @@ import { STATES, TYPES, CLASS_ANNOTATION_COMMENT_TEXT, - SELECTOR_ANNOTATION_COMMENT_TEXT, SELECTOR_ANNOTATION_DIALOG, SELECTOR_ANNOTATION_CARET, CLASS_ACTIVE, @@ -60,7 +59,7 @@ import { const DIALOG_WIDTH = 81; const sandbox = sinon.sandbox.create(); -let stubs = {}; +const stubs = {}; describe('util', () => { let childEl; @@ -509,13 +508,12 @@ describe('util', () => { describe('eventToLocationHandler()', () => { let getLocation; - let annotator; let callback; let locationHandler; let event; beforeEach(() => { - getLocation = ((event) => 'location'); + getLocation = () => 'location'; callback = sandbox.stub(); locationHandler = eventToLocationHandler(getLocation, callback); event = { @@ -553,12 +551,12 @@ describe('util', () => { prevDefAndStopProp(event); expect(event.preventDefault).to.be.called; expect(event.stopPropagation).to.be.called; - }) + }); }); describe('createLocation()', () => { it('should create a location object without dimensions', () => { - const location = createLocation(1,2, undefined); + const location = createLocation(1, 2, undefined); expect(location).to.deep.equal({ x: 1, y: 2 @@ -567,7 +565,7 @@ describe('util', () => { it('should create a location object with dimensions', () => { const dimensionalObj = 'dimensional object'; - const location = createLocation(1,2, dimensionalObj); + const location = createLocation(1, 2, dimensionalObj); expect(location).to.deep.equal({ x: 1, y: 2, @@ -582,47 +580,47 @@ describe('util', () => { }); it('should return empty when modifier and key are same', () => { - expect( decodeKeydown({ key: 'Control', ctrlKey: true })).to.equal(''); + expect(decodeKeydown({ key: 'Control', ctrlKey: true })).to.equal(''); }); it('should return correct with ctrl modifier', () => { - expect( decodeKeydown({ key: '1', ctrlKey: true })).to.equal('Control+1'); + expect(decodeKeydown({ key: '1', ctrlKey: true })).to.equal('Control+1'); }); it('should return correct with shift modifier', () => { - expect( decodeKeydown({ key: '1', shiftKey: true })).to.equal('Shift+1'); + expect(decodeKeydown({ key: '1', shiftKey: true })).to.equal('Shift+1'); }); it('should return correct with meta modifier', () => { - expect( decodeKeydown({ key: '1', metaKey: true })).to.equal('Meta+1'); + expect(decodeKeydown({ key: '1', metaKey: true })).to.equal('Meta+1'); }); it('should return space key', () => { - expect( decodeKeydown({ key: ' ' })).to.equal('Space'); + expect(decodeKeydown({ key: ' ' })).to.equal('Space'); }); it('should return right arrow key', () => { - expect( decodeKeydown({ key: 'Right' })).to.equal('ArrowRight'); + expect(decodeKeydown({ key: 'Right' })).to.equal('ArrowRight'); }); it('should return left arrow key', () => { - expect( decodeKeydown({ key: 'Left' })).to.equal('ArrowLeft'); + expect(decodeKeydown({ key: 'Left' })).to.equal('ArrowLeft'); }); it('should return up arrow key', () => { - expect( decodeKeydown({ key: 'Up' })).to.equal('ArrowUp'); + expect(decodeKeydown({ key: 'Up' })).to.equal('ArrowUp'); }); it('should return down arrow key', () => { - expect( decodeKeydown({ key: 'Down' })).to.equal('ArrowDown'); + expect(decodeKeydown({ key: 'Down' })).to.equal('ArrowDown'); }); it('should return esc key', () => { - expect( decodeKeydown({ key: 'U+001B' })).to.equal('Escape'); + expect(decodeKeydown({ key: 'U+001B' })).to.equal('Escape'); }); it('should decode correct UTF8 key', () => { - expect( decodeKeydown({ key: 'U+0041' })).to.equal('A'); + expect(decodeKeydown({ key: 'U+0041' })).to.equal('A'); }); }); @@ -712,7 +710,6 @@ describe('util', () => { }); describe('createCommentTextNode()', () => { - it('should add a
for each newline', () => { const text = ` @@ -726,14 +723,13 @@ describe('util', () => { }); it('should add a

containing text for mixed newline/text', () => { - const text = `some breaks \n and \n text`; + const text = 'some breaks \n and \n text'; const textEl = createCommentTextNode(text); const paras = textEl.querySelectorAll('p'); expect(paras.length === 3).to.be.true; }); - it('should use the text as textContent if no newlines', () => { const text = 'no breaks and some text'; const textEl = createCommentTextNode(text); @@ -817,23 +813,27 @@ describe('util', () => { describe('hasValidBoundaryCoordinates()', () => { it('return true only if boundary coordinates are valid', () => { expect(hasValidBoundaryCoordinates({})).to.be.false; - expect(hasValidBoundaryCoordinates({ - minX: NaN, - minY: 1, - maxX: 1, - maxY: 1 - })).to.be.false; - expect(hasValidBoundaryCoordinates({ - minX: 1, - minY: 1, - maxX: 1, - maxY: 1 - })).to.be.true; + expect( + hasValidBoundaryCoordinates({ + minX: NaN, + minY: 1, + maxX: 1, + maxY: 1 + }) + ).to.be.false; + expect( + hasValidBoundaryCoordinates({ + minX: 1, + minY: 1, + maxX: 1, + maxY: 1 + }) + ).to.be.true; }); it('should return true for highlight annotations', () => { expect(hasValidBoundaryCoordinates({ type: TYPES.highlight })).to.be.true; - }) + }); }); describe('generateMobileDialogEl()', () => { diff --git a/src/controllers/__tests__/AnnotationModeController-test.js b/src/controllers/__tests__/AnnotationModeController-test.js index fcc1cae98..e036ebee6 100644 --- a/src/controllers/__tests__/AnnotationModeController-test.js +++ b/src/controllers/__tests__/AnnotationModeController-test.js @@ -1,7 +1,7 @@ +/* eslint-disable no-unused-expressions */ import rbush from 'rbush'; import EventEmitter from 'events'; import AnnotationModeController from '../AnnotationModeController'; -import DocDrawingThread from '../../doc/DocDrawingThread'; import * as util from '../../util'; import { CLASS_HIDDEN, @@ -53,12 +53,12 @@ describe('controllers/AnnotationModeController', () => { describe('init()', () => { it('should init controller', () => { - sandbox.stub(controller, 'showButton'); + stubs.showButton = sandbox.stub(controller, 'showButton'); controller.init({ modeButton: {}, permissions: { canAnnotate: true } }); - expect(controller.showButton).to.be.called; + expect(stubs.showButton).to.be.called; }); it('should not show modeButton if none provided', () => { @@ -79,6 +79,7 @@ describe('controllers/AnnotationModeController', () => { describe('destroy()', () => { it('should destroy all the threads in controller', () => { + // eslint-disable-next-line new-cap controller.threads = { 1: new rbush() }; controller.registerThread(stubs.thread); @@ -104,7 +105,7 @@ describe('controllers/AnnotationModeController', () => { expect(controller.getButton('.class')).to.not.be.null; }); - }) + }); describe('showButton()', () => { beforeEach(() => { @@ -212,7 +213,7 @@ describe('controllers/AnnotationModeController', () => { controller.buttonEl.classList.add(CLASS_ACTIVE); expect(controller.isEnabled()).to.be.true; }); - }) + }); describe('bindListeners()', () => { it('should bind mode listeners', () => { @@ -289,6 +290,7 @@ describe('controllers/AnnotationModeController', () => { }); it('should internally keep track of the registered thread', () => { + // eslint-disable-next-line new-cap controller.threads = { 1: new rbush() }; const pageThreads = controller.threads[1]; expect(pageThreads.collides(boundingBox)).to.be.false; @@ -321,6 +323,7 @@ describe('controllers/AnnotationModeController', () => { }); it('should internally keep track of the registered thread', () => { + // eslint-disable-next-line new-cap controller.threads = { 1: new rbush() }; const pageThreads = controller.threads[1]; @@ -378,7 +381,7 @@ describe('controllers/AnnotationModeController', () => { controller.localized = { deleteError: 'delete error', createError: 'create error' - } + }; }); it('should mark hadPendingThreads as false and emit event on thread save or cancel', () => { @@ -437,9 +440,9 @@ describe('controllers/AnnotationModeController', () => { const fn = 'fn'; controller.pushElementHandler(element, type, fn); - const handlers = controller.handlers; + const { handlers } = controller; const lengthAfter = handlers.length; - expect(lengthAfter).to.equal(lengthBefore+1); + expect(lengthAfter).to.equal(lengthBefore + 1); expect(handlers[handlers.length - 1]).to.deep.equal({ eventObj: element, func: fn, @@ -491,7 +494,9 @@ describe('controllers/AnnotationModeController', () => { it('should render the annotations on every page', () => { controller.threads = { + // eslint-disable-next-line new-cap 1: new rbush(), + // eslint-disable-next-line new-cap 2: new rbush() }; controller.threads[1].insert(stubs.thread); diff --git a/src/controllers/__tests__/DrawingModeController-test.js b/src/controllers/__tests__/DrawingModeController-test.js index b148fcb92..077752945 100644 --- a/src/controllers/__tests__/DrawingModeController-test.js +++ b/src/controllers/__tests__/DrawingModeController-test.js @@ -1,3 +1,4 @@ +/* eslint-disable no-unused-expressions */ import rbush from 'rbush'; import AnnotationModeController from '../AnnotationModeController'; import DrawingModeController from '../DrawingModeController'; @@ -5,15 +6,13 @@ import * as util from '../../util'; import { TYPES, STATES, - THREAD_EVENT, SELECTOR_ANNOTATION_BUTTON_DRAW_CANCEL, SELECTOR_ANNOTATION_BUTTON_DRAW_POST, SELECTOR_ANNOTATION_BUTTON_DRAW_UNDO, SELECTOR_ANNOTATION_BUTTON_DRAW_REDO, SELECTOR_DRAW_MODE_HEADER, CLASS_ANNOTATION_MODE, - CLASS_ACTIVE, - CONTROLLER_EVENT + CLASS_ACTIVE } from '../../constants'; let controller; @@ -70,7 +69,7 @@ describe('controllers/DrawingModeController', () => { const blankDiv = document.createElement('div'); stubs.insertTemplate = sandbox.stub(util, 'insertTemplate'); sandbox.stub(controller, 'getButton').returns(blankDiv); - controller['localized'] = { + controller.localized = { cancelButton: 'cancel', doneButton: 'done' }; @@ -306,6 +305,7 @@ describe('controllers/DrawingModeController', () => { it('should delete a non-pending thread', () => { stubs.thread.state = 'idle'; + // eslint-disable-next-line new-cap controller.threads[1] = new rbush(); controller.registerThread(stubs.thread); const unregisterThreadStub = sandbox.stub(controller, 'unregisterThread'); @@ -319,6 +319,7 @@ describe('controllers/DrawingModeController', () => { it('should not delete a thread if the dialog no longer exists', () => { stubs.thread.dialog = null; + // eslint-disable-next-line new-cap controller.threads[1] = new rbush(); controller.registerThread(stubs.thread); const unregisterThreadStub = sandbox.stub(controller, 'unregisterThread'); @@ -332,9 +333,10 @@ describe('controllers/DrawingModeController', () => { describe('handleSelection()', () => { beforeEach(() => { + // eslint-disable-next-line new-cap controller.threads[1] = new rbush(); controller.registerThread(stubs.thread); - stubs.intersecting = sandbox.stub(controller, 'getIntersectingThreads').returns([ stubs.thread ]); + stubs.intersecting = sandbox.stub(controller, 'getIntersectingThreads').returns([stubs.thread]); stubs.select = sandbox.stub(controller, 'select'); stubs.clean = sandbox.stub(controller, 'removeSelection'); @@ -346,7 +348,7 @@ describe('controllers/DrawingModeController', () => { it('should do nothing with an empty event', () => { controller.handleSelection(); expect(stubs.intersecting).to.not.be.called; - }) + }); it('should do nothing no intersecting threads are found', () => { stubs.intersecting.returns([]); @@ -360,7 +362,7 @@ describe('controllers/DrawingModeController', () => { controller.currentThread = { state: STATES.pending }; controller.handleSelection(stubs.event); expect(stubs.intersecting).to.not.be.called; - }) + }); it('should call select on an thread found in the data store', () => { controller.handleSelection(stubs.event); @@ -449,7 +451,10 @@ describe('controllers/DrawingModeController', () => { }); it('should do nothing if thread has invalid boundary', () => { - stubs.threadMock.expects('saveAnnotation').withArgs(TYPES.draw).never(); + stubs.threadMock + .expects('saveAnnotation') + .withArgs(TYPES.draw) + .never(); controller.saveThread({ minX: NaN, minY: 1, maxX: 1, maxY: 1 }); controller.saveThread({ type: TYPES.draw }); expect(controller.registerThread).to.not.be.called; diff --git a/src/controllers/__tests__/HighlightModeController-test.js b/src/controllers/__tests__/HighlightModeController-test.js index 91defc013..2341c8b74 100644 --- a/src/controllers/__tests__/HighlightModeController-test.js +++ b/src/controllers/__tests__/HighlightModeController-test.js @@ -1,16 +1,7 @@ -import EventEmitter from 'events'; +/* eslint-disable no-unused-expressions */ import HighlightModeController from '../HighlightModeController'; import * as util from '../../util'; -import { - CLASS_HIDDEN, - CLASS_ACTIVE, - CLASS_ANNOTATION_MODE, - THREAD_EVENT, - STATES, - TYPES, - CONTROLLER_EVENT, - CLASS_ANNOTATION_LAYER_HIGHLIGHT -} from '../../constants'; +import { CLASS_ANNOTATION_MODE, THREAD_EVENT, TYPES, CONTROLLER_EVENT } from '../../constants'; let controller; let stubs = {}; diff --git a/src/controllers/__tests__/PointModeController-test.js b/src/controllers/__tests__/PointModeController-test.js index 53ccb89e5..5c190474d 100644 --- a/src/controllers/__tests__/PointModeController-test.js +++ b/src/controllers/__tests__/PointModeController-test.js @@ -1,17 +1,12 @@ -import EventEmitter from 'events'; +/* eslint-disable no-unused-expressions */ import PointModeController from '../PointModeController'; import AnnotationModeController from '../AnnotationModeController'; -import CreateAnnotationDialog from '../../CreateAnnotationDialog'; import * as util from '../../util'; import { - CLASS_HIDDEN, CLASS_ACTIVE, CLASS_ANNOTATION_MODE, - ANNOTATOR_EVENT, THREAD_EVENT, - STATES, CONTROLLER_EVENT, - CREATE_EVENT, SELECTOR_ANNOTATION_BUTTON_POINT_EXIT, SELECTOR_POINT_MODE_HEADER } from '../../constants'; @@ -63,7 +58,7 @@ describe('controllers/PointModeController', () => { const blankDiv = document.createElement('div'); stubs.insertTemplate = sandbox.stub(util, 'insertTemplate'); sandbox.stub(controller, 'getButton').returns(blankDiv); - controller['localized'] = { closeButton: 'Close' }; + controller.localized = { closeButton: 'Close' }; controller.setupHeader(blankDiv, blankDiv); expect(controller.getButton).to.be.calledWith(SELECTOR_ANNOTATION_BUTTON_POINT_EXIT); diff --git a/src/doc/__tests__/CreateHighlightDialog-test.js b/src/doc/__tests__/CreateHighlightDialog-test.js index c99a6f51c..c520c9058 100644 --- a/src/doc/__tests__/CreateHighlightDialog-test.js +++ b/src/doc/__tests__/CreateHighlightDialog-test.js @@ -4,7 +4,6 @@ import { CLASS_ADD_HIGHLIGHT_BTN, CLASS_ADD_HIGHLIGHT_COMMENT_BTN, CLASS_ANNOTATION_CARET, - CLASS_HIDDEN, CREATE_EVENT } from '../../constants'; import CommentBox from '../../CommentBox'; @@ -30,7 +29,7 @@ describe('doc/CreateHighlightDialog', () => { beforeEach(() => { fixture.load('doc/__tests__/CreateHighlightDialog-test.html'); - const parentEl = document.createElement('div'); + parentEl = document.createElement('div'); parentEl.classList.add('bp-create-dialog-container'); dialog = new CreateHighlightDialog(parentEl, { allowHighlight: true, @@ -91,7 +90,7 @@ describe('doc/CreateHighlightDialog', () => { stubs.parentMock.expects('appendChild').never(); dialog.show({}, {}); expect(stubs.pageInfo).to.be.called; - }) + }); it('should set the parentEl to a new reference, via setParentEl(), if a new one is supplied', () => { const newParent = document.createElement('span'); @@ -129,7 +128,7 @@ describe('doc/CreateHighlightDialog', () => { it('should position the dialog according to the bottom right corner of the selection', () => { stubs.pageInfo.returns({ pageEl: document.createElement('div') }); - stubs.getCoords.returns({x: 1, y: 2}); + stubs.getCoords.returns({ x: 1, y: 2 }); dialog.setPosition(stubs.selection); expect(stubs.update).to.be.called; }); @@ -154,7 +153,7 @@ describe('doc/CreateHighlightDialog', () => { const highlightCreateStub = sandbox.stub(dialog.highlightCreateEl, 'removeEventListener'); const commentCreateStub = sandbox.stub(dialog.commentCreateEl, 'removeEventListener'); - const stubs = [ + const eventStubs = [ { stub: highlightCreateStub, args: ['touchstart', dialog.stopPropagation] @@ -179,7 +178,7 @@ describe('doc/CreateHighlightDialog', () => { dialog.destroy(); - stubs.forEach((stub) => { + eventStubs.forEach((stub) => { expect(stub.stub).to.be.calledWith(...stub.args); }); }); @@ -198,7 +197,6 @@ describe('doc/CreateHighlightDialog', () => { }); it('should update the left of the ui element, to center it', () => { - const width = dialog.containerEl.clientWidth; const x = 50; dialog.position.x = x; sandbox.stub(util, 'repositionCaret').returns(x); diff --git a/src/doc/__tests__/DocAnnotator-test.js b/src/doc/__tests__/DocAnnotator-test.js index 825e94244..c79ebead7 100644 --- a/src/doc/__tests__/DocAnnotator-test.js +++ b/src/doc/__tests__/DocAnnotator-test.js @@ -3,7 +3,6 @@ import rangy from 'rangy'; import Annotator from '../../Annotator'; import Annotation from '../../Annotation'; import AnnotationThread from '../../AnnotationThread'; -import HighlightModeController from '../../controllers/HighlightModeController'; import DocAnnotator from '../DocAnnotator'; import DocHighlightThread from '../DocHighlightThread'; import DocDrawingThread from '../DocDrawingThread'; @@ -18,10 +17,8 @@ import { CLASS_ANNOTATION_LAYER_HIGHLIGHT, CLASS_ANNOTATION_PLAIN_HIGHLIGHT, DATA_TYPE_ANNOTATION_DIALOG, - THREAD_EVENT, CONTROLLER_EVENT, - CREATE_EVENT, - ANNOTATOR_TYPE + CREATE_EVENT } from '../../constants'; let annotator; @@ -45,7 +42,7 @@ describe('doc/DocAnnotator', () => { annotator: { NAME: 'name', TYPE: ['highlight', 'highlight-comment'], - CONTROLLERS: { 'something': stubs.controller } + CONTROLLERS: { something: stubs.controller } } }; annotator = new DocAnnotator({ @@ -96,7 +93,7 @@ describe('doc/DocAnnotator', () => { destroy: () => {}, show: () => {}, hide: () => {}, - setPosition: () => {}, + setPosition: () => {} }; stubs.createDialogMock = sandbox.mock(annotator.createHighlightDialog); }); @@ -134,7 +131,7 @@ describe('doc/DocAnnotator', () => { const y = 200; const dimensions = { x, y }; const quadPoints = [[1, 2, 3, 4, 5, 6, 7, 8], [2, 3, 4, 5, 6, 7, 8, 9]]; - let page = 3; + const page = 3; beforeEach(() => { stubs.event = { @@ -175,11 +172,13 @@ describe('doc/DocAnnotator', () => { it('should replace event with mobile touch event if user is on a touch enabled device', () => { annotator.hasTouch = true; stubs.event = { - targetTouches: [{ - clientX: x, - clientY: y, - target: annotator.annotatedEl - }] + targetTouches: [ + { + clientX: x, + clientY: y, + target: annotator.annotatedEl + } + ] }; annotator.getLocationFromEvent(stubs.event, TYPES.point); }); @@ -189,11 +188,13 @@ describe('doc/DocAnnotator', () => { expect(annotator.getLocationFromEvent(stubs.event, TYPES.point)).to.be.null; stubs.event = { - targetTouches: [{ - target: annotator.annotatedEl - }] + targetTouches: [ + { + target: annotator.annotatedEl + } + ] }; - annotator + annotator; expect(annotator.getLocationFromEvent(stubs.event, TYPES.point)).to.be.null; }); @@ -518,7 +519,7 @@ describe('doc/DocAnnotator', () => { const controller = { registerThread: sandbox.stub() }; stubs.registerThread = controller.registerThread; - annotator.modeControllers = { 'random': controller }; + annotator.modeControllers = { random: controller }; expect(annotator.createHighlightThread()).to.deep.equal(thread); expect(stubs.registerThread).to.not.be.called; @@ -533,7 +534,7 @@ describe('doc/DocAnnotator', () => { const controller = { registerThread: sandbox.stub() }; stubs.registerThread = controller.registerThread; - annotator.modeControllers = { 'highlight': controller }; + annotator.modeControllers = { highlight: controller }; expect(annotator.createHighlightThread()).to.deep.equal(thread); expect(stubs.registerThread).to.be.called; @@ -544,10 +545,10 @@ describe('doc/DocAnnotator', () => { beforeEach(() => { sandbox.stub(annotator, 'scaleAnnotationCanvases'); annotator.modeControllers = { - 'type': { + type: { renderPage: sandbox.stub() }, - 'type2': { + type2: { renderPage: sandbox.stub() } }; @@ -563,8 +564,8 @@ describe('doc/DocAnnotator', () => { createMock.expects('hide'); annotator.renderPage(1); expect(annotator.scaleAnnotationCanvases).to.be.calledWith(1); - expect(annotator.modeControllers['type'].renderPage).to.be.calledWith(1); - expect(annotator.modeControllers['type2'].renderPage).to.be.calledWith(1); + expect(annotator.modeControllers.type.renderPage).to.be.calledWith(1); + expect(annotator.modeControllers.type2.renderPage).to.be.calledWith(1); }); }); @@ -602,7 +603,7 @@ describe('doc/DocAnnotator', () => { sandbox.stub(rangy, 'createHighlighter').returns(stubs.highlighter); annotator.modeControllers = { - 'highlight': {}, + highlight: {}, 'highlight-comment': {} }; }); @@ -612,12 +613,21 @@ describe('doc/DocAnnotator', () => { }); it('should not bind any plain highlight functions if they are disabled', () => { - stubs.createDialogMock.expects('addListener').withArgs(CREATE_EVENT.plain, sinon.match.func).never(); + stubs.createDialogMock + .expects('addListener') + .withArgs(CREATE_EVENT.plain, sinon.match.func) + .never(); }); it('should not bind any comment highlight functions if they are disabled', () => { - stubs.createDialogMock.expects('addListener').withArgs(CREATE_EVENT.comment, sinon.match.func).never(); - stubs.createDialogMock.expects('addListener').withArgs(CREATE_EVENT.post, sinon.match.func).never(); + stubs.createDialogMock + .expects('addListener') + .withArgs(CREATE_EVENT.comment, sinon.match.func) + .never(); + stubs.createDialogMock + .expects('addListener') + .withArgs(CREATE_EVENT.post, sinon.match.func) + .never(); }); it('should call parent to setup annotations and initialize highlighter', () => { @@ -654,7 +664,7 @@ describe('doc/DocAnnotator', () => { stubs.elMock.expects('addEventListener').withArgs('dblclick', sinon.match.func); stubs.elMock.expects('addEventListener').withArgs('mousedown', sinon.match.func); stubs.elMock.expects('addEventListener').withArgs('contextmenu', sinon.match.func); - stubs.elMock.expects('addEventListener').withArgs('click', sinon.match.func) + stubs.elMock.expects('addEventListener').withArgs('click', sinon.match.func); annotator.bindDOMListeners(); }); @@ -691,7 +701,6 @@ describe('doc/DocAnnotator', () => { annotator.drawEnabled = true; const docListen = sandbox.spy(document, 'addEventListener'); - const annotatedElementListen = sandbox.spy(annotator.annotatedElement, 'addEventListener'); annotator.bindDOMListeners(); expect(docListen).to.be.calledWith('selectionchange', sinon.match.func); @@ -709,7 +718,6 @@ describe('doc/DocAnnotator', () => { annotator.drawEnabled = true; const docListen = sandbox.spy(document, 'addEventListener'); - const annotatedElementListen = sandbox.spy(annotator.annotatedElement, 'addEventListener'); annotator.bindDOMListeners(); expect(docListen).to.not.be.calledWith('selectionchange', sinon.match.func); @@ -723,14 +731,25 @@ describe('doc/DocAnnotator', () => { annotator.drawEnabled = true; stubs.elMock.expects('addEventListener').withArgs('click', sinon.match.func); - stubs.elMock.expects('addEventListener').never().withArgs('mouseup', sinon.match.func); - stubs.elMock.expects('addEventListener').never().withArgs('dblclick', sinon.match.func); - stubs.elMock.expects('addEventListener').never().withArgs('mousedown', sinon.match.func); - stubs.elMock.expects('addEventListener').never().withArgs('contextmenu', sinon.match.func); + stubs.elMock + .expects('addEventListener') + .never() + .withArgs('mouseup', sinon.match.func); + stubs.elMock + .expects('addEventListener') + .never() + .withArgs('dblclick', sinon.match.func); + stubs.elMock + .expects('addEventListener') + .never() + .withArgs('mousedown', sinon.match.func); + stubs.elMock + .expects('addEventListener') + .never() + .withArgs('contextmenu', sinon.match.func); annotator.bindDOMListeners(); }); - }); describe('unbindDOMListeners()', () => { @@ -775,7 +794,6 @@ describe('doc/DocAnnotator', () => { annotator.isMobile = true; annotator.hasTouch = false; const docStopListen = sandbox.spy(document, 'removeEventListener'); - const annotatedElementStopListen = sandbox.spy(annotator.annotatedElement, 'removeEventListener'); annotator.unbindDOMListeners(); expect(docStopListen).to.be.calledWith('selectionchange', sinon.match.func); @@ -789,13 +807,13 @@ describe('doc/DocAnnotator', () => { it('should tell controllers to clean up selections', () => { annotator.permissions.canAnnotate = true; annotator.modeControllers = { - 'test': { + test: { removeSelection: sandbox.stub() } }; annotator.unbindDOMListeners(); - expect(annotator.modeControllers['test'].removeSelection).to.be.called; + expect(annotator.modeControllers.test.removeSelection).to.be.called; }); }); @@ -884,7 +902,9 @@ describe('doc/DocAnnotator', () => { it('should invoke highlighter.highlightSelection() with the annotated element\'s id', () => { annotator.highlightCurrentSelection(); - expect(annotator.highlighter.highlightSelection).to.be.calledWith('rangy-highlight', { containerElementId: 'doc-annotator-el' }); + expect(annotator.highlighter.highlightSelection).to.be.calledWith('rangy-highlight', { + containerElementId: 'doc-annotator-el' + }); }); }); @@ -893,17 +913,17 @@ describe('doc/DocAnnotator', () => { const thread = { type: 'highlight', location: { page: 1 }, - onMousedown: () => {}, + onMousedown: () => {} }; stubs.threadMock = sandbox.mock(thread); annotator.modeControllers = { - 'highlight': { + highlight: { threads: { 1: { '123abc': thread } }, applyActionToThreads: () => {} } }; - stubs.controllerMock = sandbox.mock(annotator.modeControllers['highlight']); + stubs.controllerMock = sandbox.mock(annotator.modeControllers.highlight); }); it('should do nothing if highlights are disabled', () => { @@ -980,8 +1000,8 @@ describe('doc/DocAnnotator', () => { beforeEach(() => { stubs.thread = { threadID: '123abc', - location: { page : 1 }, - type: TYPES.highlight, + location: { page: 1 }, + type: TYPES.highlight }; stubs.getPageInfo = stubs.getPageInfo.returns({ pageEl: {}, page: 1 }); @@ -991,18 +1011,19 @@ describe('doc/DocAnnotator', () => { let timer = 0; window.performance = window.performance || { now: () => {} }; sandbox.stub(window.performance, 'now').callsFake(() => { + // eslint-disable-next-line no-return-assign return (timer += 500); }); annotator.isCreatingHighlight = false; annotator.modeControllers = { - 'highlight': { + highlight: { threads: {}, applyActionToThreads: () => {} } }; - stubs.controllerMock = sandbox.mock(annotator.modeControllers['highlight']); + stubs.controllerMock = sandbox.mock(annotator.modeControllers.highlight); }); afterEach(() => { @@ -1029,7 +1050,7 @@ describe('doc/DocAnnotator', () => { }); it('should add delayThreads and hide innactive threads if the page is found', () => { - annotator.delayThread = [ stubs.thread ]; + annotator.delayThread = [stubs.thread]; annotator.mouseMoveEvent = { clientX: 3, clientY: 3 }; annotator.onHighlightCheck(); }); @@ -1064,14 +1085,14 @@ describe('doc/DocAnnotator', () => { it('should not trigger a highlight or creation if a point annotation is pending', () => { annotator.modeControllers = { - 'point': { hadPendingThreads: true } + point: { hadPendingThreads: true } }; annotator.highlightMouseupHandler({}); expect(stubs.create).to.not.be.called; expect(stubs.click).to.not.be.called; expect(annotator.isCreatingHighlight).to.be.false; expect(annotator.resetHighlightSelection).to.be.called; - }) + }); it('should call highlightCreateHandler if not on mobile, and the user double clicked', () => { annotator.highlightMouseupHandler({ type: 'dblclick' }); @@ -1120,15 +1141,15 @@ describe('doc/DocAnnotator', () => { annotator.highlighter = { removeAllHighlights: sandbox.stub() }; annotator.modeControllers = { - 'point': {}, - 'highlight': { + point: {}, + highlight: { applyActionToThreads: () => {} }, 'highlight-comment': { applyActionToThreads: () => {} } }; - stubs.highlightMock = sandbox.mock(annotator.modeControllers['highlight']); + stubs.highlightMock = sandbox.mock(annotator.modeControllers.highlight); stubs.commentMock = sandbox.mock(annotator.modeControllers['highlight-comment']); stubs.getSelStub = sandbox.stub(window, 'getSelection'); @@ -1152,7 +1173,7 @@ describe('doc/DocAnnotator', () => { }); it('should do nothing the the user is currently creating a point annotation', () => { - annotator.modeControllers['point'].pendingThreadID = 'something'; + annotator.modeControllers.point.pendingThreadID = 'something'; annotator.onSelectionChange(event); expect(stubs.getSelStub).to.not.be.called; }); @@ -1211,7 +1232,10 @@ describe('doc/DocAnnotator', () => { stubs.highlightMock.expects('applyActionToThreads').withArgs(sinon.match.func, 1); annotator.commentHighlightEnabled = false; - stubs.commentMock.expects('applyActionToThreads').withArgs(sinon.match.func, 1).never(); + stubs.commentMock + .expects('applyActionToThreads') + .withArgs(sinon.match.func, 1) + .never(); stubs.getSelStub.returns(selection); sandbox.stub(annotator.createHighlightDialog, 'show'); @@ -1222,7 +1246,6 @@ describe('doc/DocAnnotator', () => { describe('highlightCreateHandler()', () => { let selection; - let createDialog; let pageInfo; beforeEach(() => { @@ -1268,7 +1291,7 @@ describe('doc/DocAnnotator', () => { left: 0 }; - sandbox.stub(docUtil, 'getDialogCoordsFromRange').returns({ x: 10, y: 10 }) + sandbox.stub(docUtil, 'getDialogCoordsFromRange').returns({ x: 10, y: 10 }); pageInfo.pageEl.getBoundingClientRect = sandbox.stub().returns(pageRect); selection.rangeCount = 1; @@ -1279,7 +1302,7 @@ describe('doc/DocAnnotator', () => { }); it('should position the create highlight dialog, if not on mobile', () => { - sandbox.stub(docUtil, 'getDialogCoordsFromRange').returns({ x: 50, y: 35 }) + sandbox.stub(docUtil, 'getDialogCoordsFromRange').returns({ x: 50, y: 35 }); const pageRect = { top: 0, left: 0 @@ -1305,14 +1328,14 @@ describe('doc/DocAnnotator', () => { sandbox.stub(annotator, 'removeThreadFromSharedDialog'); annotator.modeControllers = { - 'highlight': { + highlight: { getIntersectingThreads: sandbox.stub() }, 'highlight-comment': { getIntersectingThreads: sandbox.stub() } }; - stubs.highlightApply = annotator.modeControllers['highlight'].getIntersectingThreads; + stubs.highlightApply = annotator.modeControllers.highlight.getIntersectingThreads; stubs.commentApply = annotator.modeControllers['highlight-comment'].getIntersectingThreads; }); @@ -1410,7 +1433,7 @@ describe('doc/DocAnnotator', () => { annotator.isMobile = true; stubs.threadMock.expects('hideDialog'); annotator.clickThread(stubs.thread); - }) + }); }); describe('useDefaultCursor()', () => { @@ -1522,11 +1545,10 @@ describe('doc/DocAnnotator', () => { const mode = 'something'; beforeEach(() => { - const selection = document.getSelection(); sandbox.stub(annotator, 'toggleAnnotationMode'); annotator.createHighlightDialog = { isVisible: true, - hide: sandbox.stub(), + hide: sandbox.stub() }; sandbox.stub(annotator, 'renderPage'); sandbox.stub(annotator, 'resetHighlightSelection'); @@ -1534,7 +1556,7 @@ describe('doc/DocAnnotator', () => { afterEach(() => { annotator.createHighlightDialog = null; - }) + }); it('should clear selections and hide the createHighlightDialog on togglemode if needed', () => { annotator.handleControllerEvents({ event: CONTROLLER_EVENT.toggleMode, mode }); @@ -1547,7 +1569,7 @@ describe('doc/DocAnnotator', () => { }); it('should do nothing if createHighlightDialog is hidden or does not exist on binddomlisteners', () => { - annotator.createHighlightDialog.isVisible = false + annotator.createHighlightDialog.isVisible = false; annotator.handleControllerEvents({ event: CONTROLLER_EVENT.bindDOMListeners }); expect(annotator.createHighlightDialog.hide).to.not.be.called; }); @@ -1559,14 +1581,14 @@ describe('doc/DocAnnotator', () => { it('should do nothing if deleted thread is not a highlight on unregisterthread', () => { stubs.thread.type = 'point'; - annotator.hoverThreads = [ stubs.thread ]; + annotator.hoverThreads = [stubs.thread]; annotator.handleControllerEvents({ event: CONTROLLER_EVENT.unregister, data: stubs.thread }); expect(annotator.hoverThreads).to.contain(stubs.thread); }); it('should remove the recently deleted thread from the hoverThreads array on unregisterthread', () => { - annotator.hoverThreads = [ stubs.thread ]; + annotator.hoverThreads = [stubs.thread]; annotator.handleControllerEvents({ event: CONTROLLER_EVENT.unregister, data: stubs.thread }); expect(annotator.hoverThreads).to.not.contain(stubs.thread); }); diff --git a/src/doc/__tests__/DocDrawingDialog-test.js b/src/doc/__tests__/DocDrawingDialog-test.js index 6ce568f78..b7c37bb2a 100644 --- a/src/doc/__tests__/DocDrawingDialog-test.js +++ b/src/doc/__tests__/DocDrawingDialog-test.js @@ -1,3 +1,4 @@ +/* eslint-disable no-unused-expressions */ import * as util from '../../util'; import * as constants from '../../constants'; import DocDrawingDialog from '../DocDrawingDialog'; @@ -49,7 +50,7 @@ describe('doc/DocDrawingDialog', () => { const event = { stopPropagation: sandbox.stub(), preventDefault: sandbox.stub() - } + }; sandbox.stub(dialog, 'emit'); dialog.postDrawing(event); @@ -109,14 +110,8 @@ describe('doc/DocDrawingDialog', () => { }; dialog.unbindDOMListeners(); - expect(dialog.commitButtonEl.removeEventListener).to.be.calledWith( - 'click', - dialog.postDrawing - ); - expect(dialog.commitButtonEl.removeEventListener).to.be.calledWith( - 'touchend', - dialog.postDrawing - ); + expect(dialog.commitButtonEl.removeEventListener).to.be.calledWith('click', dialog.postDrawing); + expect(dialog.commitButtonEl.removeEventListener).to.be.calledWith('touchend', dialog.postDrawing); }); it('should unbind listeners on a delete button element', () => { @@ -126,15 +121,9 @@ describe('doc/DocDrawingDialog', () => { }; dialog.unbindDOMListeners(); - expect(dialog.deleteButtonEl.removeEventListener).to.be.calledWith( - 'click', - dialog.deleteAnnotation - ); - expect(dialog.deleteButtonEl.removeEventListener).to.be.calledWith( - 'touchend', - dialog.deleteAnnotation - ); - }) + expect(dialog.deleteButtonEl.removeEventListener).to.be.calledWith('click', dialog.deleteAnnotation); + expect(dialog.deleteButtonEl.removeEventListener).to.be.calledWith('touchend', dialog.deleteAnnotation); + }); }); describe('setup()', () => { @@ -197,14 +186,14 @@ describe('doc/DocDrawingDialog', () => { top: 0 }, getBoundingClientRect: sandbox.stub().returns(rect) - } + }; dialog.position(5, 10); expect(dialog.element.getBoundingClientRect).to.be.called; expect(pageEl.contains).to.be.called; expect(pageEl.appendChild).to.be.calledWith(dialog.element); expect(dialog.annotatedElement.querySelector).to.be.called; - expect(dialog.element.style.left).to.equal(`4px`, `10px`); + expect(dialog.element.style.left).to.equal('4px', '10px'); }); }); @@ -245,7 +234,7 @@ describe('doc/DocDrawingDialog', () => { permissions: { can_delete: true } - } + }; stubs.getFirstAnnotation = sandbox.stub(util, 'getFirstAnnotation').returns(annotation); }); diff --git a/src/doc/__tests__/DocDrawingThread-test.js b/src/doc/__tests__/DocDrawingThread-test.js index cd6345d1f..4946d8e34 100644 --- a/src/doc/__tests__/DocDrawingThread-test.js +++ b/src/doc/__tests__/DocDrawingThread-test.js @@ -1,14 +1,11 @@ +/* eslint-disable no-unused-expressions */ import * as docUtil from '../docUtil'; import * as util from '../../util'; import DocDrawingThread from '../DocDrawingThread'; import DocDrawingDialog from '../DocDrawingDialog'; import AnnotationThread from '../../AnnotationThread'; import DrawingPath from '../../drawing/DrawingPath'; -import { - DRAW_STATES, - THREAD_EVENT, - STATES -} from '../../constants'; +import { DRAW_STATES, STATES } from '../../constants'; let thread; let stubs; @@ -52,18 +49,19 @@ describe('doc/DocDrawingThread', () => { addCoordinate: sandbox.stub(), isEmpty: sandbox.stub() }; + const { location } = thread; sandbox.stub(docUtil, 'getBrowserCoordinatesFromLocation').returns([location.x, location.y]); }); - it("should not add a coordinate when the state is not 'draw'", () => { + it('should not add a coordinate when the state is not \'draw\'', () => { thread.drawingFlag = DRAW_STATES.idle; thread.handleMove(thread.location); expect(thread.pendingPath.addCoordinate).to.not.be.called; }); - it("should add a coordinate frame when the state is 'draw'", () => { + it('should add a coordinate frame when the state is \'draw\'', () => { sandbox.stub(thread, 'hasPageChanged').returns(false); thread.handleMove(thread.location); @@ -82,15 +80,14 @@ describe('doc/DocDrawingThread', () => { sandbox.stub(thread, 'hasPageChanged').returns(true); sandbox.stub(thread, 'onPageChange'); - thread.handleMove({page: 1}); + thread.handleMove({ page: 1 }); expect(thread.onPageChange).to.be.called; - }) + }); }); - describe('handleStart()', () => { beforeEach(() => { - const context = "I'm a real context"; + const context = 'I\'m a real context'; sandbox.stub(window, 'requestAnimationFrame'); sandbox.stub(thread, 'checkAndHandleScaleUpdate'); @@ -131,7 +128,6 @@ describe('doc/DocDrawingThread', () => { expect(thread.checkAndHandleScaleUpdate).to.not.be.called; expect(thread.state).to.equal(STATES.inactive); }); - }); describe('handleStop()', () => { @@ -151,7 +147,7 @@ describe('doc/DocDrawingThread', () => { }; }); - it("should set the state to 'idle' and clear the pendingPath", () => { + it('should set the state to \'idle\' and clear the pendingPath', () => { thread.handleStop(); expect(stubs.emitAvailableActions).to.be.called; @@ -170,7 +166,7 @@ describe('doc/DocDrawingThread', () => { removeAllListeners: () => {}, destroy: () => {}, isVisible: () => false - } + }; thread.handleStop(); expect(stubs.createDialog).to.not.be.called; @@ -178,10 +174,10 @@ describe('doc/DocDrawingThread', () => { }); describe('onPageChange()', () => { - it('should emit an annotationevent of type pagechanged and stop a pending drawing', (done) =>{ + it('should emit an annotationevent of type pagechanged and stop a pending drawing', (done) => { sandbox.stub(thread, 'handleStop'); const location = 'location'; - thread.addListener('threadevent', (data) => { + thread.addListener('threadevent', () => { done(); }); @@ -229,14 +225,14 @@ describe('doc/DocDrawingThread', () => { y: 2 }; - sandbox.stub(docUtil, 'getBrowserCoordinatesFromLocation').returns([3,4]); + sandbox.stub(docUtil, 'getBrowserCoordinatesFromLocation').returns([3, 4]); const returnValue = thread.reconstructBrowserCoordFromLocation(documentLocation); expect(returnValue).to.deep.equal({ x: 3, y: 4 }); - }) + }); }); describe('saveAnnotation()', () => { @@ -320,7 +316,7 @@ describe('doc/DocDrawingThread', () => { page: 2 }; const location = { - page: (thread.location.page + 1) + page: thread.location.page + 1 }; const value = thread.hasPageChanged(location); expect(value).to.be.true; @@ -366,13 +362,13 @@ describe('doc/DocDrawingThread', () => { removeAllListeners: () => {}, hide: () => {}, show: sandbox.stub() - } + }; thread.show(); expect(thread.dialog.isVisible).to.be.called; expect(thread.drawBoundary).to.be.called; expect(thread.dialog.show).to.be.called; - }) + }); }); describe('selectContext()', () => { diff --git a/src/doc/__tests__/DocHighlightDialog-test.js b/src/doc/__tests__/DocHighlightDialog-test.js index 31e093e4f..1b3306bb2 100644 --- a/src/doc/__tests__/DocHighlightDialog-test.js +++ b/src/doc/__tests__/DocHighlightDialog-test.js @@ -134,7 +134,10 @@ describe('doc/DocHighlightDialog', () => { }); it('should not modify mobile ui there is no mobile header present', () => { - const headerQuery = sandbox.stub(dialog.element, 'querySelector').withArgs('.ba-annotation-mobile-header').returns(null); + sandbox + .stub(dialog.element, 'querySelector') + .withArgs('.ba-annotation-mobile-header') + .returns(null); const elRemove = sandbox.stub(dialog.element.classList, 'remove'); dialog.postAnnotation('This is the water and this is the well.'); @@ -143,12 +146,7 @@ describe('doc/DocHighlightDialog', () => { it('should show the mobile header', () => { dialog.isMobile = true; - const headerEl = { - classList: { - remove: sandbox.stub() - } - }; - const headerQuery = sandbox.stub(dialog.element, 'querySelector').withArgs('.ba-annotation-mobile-header'); + sandbox.stub(dialog.element, 'querySelector').withArgs('.ba-annotation-mobile-header'); dialog.postAnnotation('Drink full and descend.'); }); @@ -159,8 +157,10 @@ describe('doc/DocHighlightDialog', () => { remove: sandbox.stub() } }; - const headerQuery = sandbox.stub(dialog.element, 'querySelector') - .withArgs('.ba-annotation-mobile-header').returns(headerEl); + sandbox + .stub(dialog.element, 'querySelector') + .withArgs('.ba-annotation-mobile-header') + .returns(headerEl); const elRemove = sandbox.stub(dialog.element.classList, 'remove'); dialog.postAnnotation('The horse is the white of the eyes, dark within.'); @@ -188,7 +188,10 @@ describe('doc/DocHighlightDialog', () => { it('should do nothing if the comment dialog is already hidden', () => { const classAdd = sandbox.stub(dialog.element.classList, 'add'); dialog.highlightDialogEl = {}; - sandbox.stub(dialog.commentsDialogEl.classList, 'contains').withArgs(constants.CLASS_HIDDEN).returns(true); + sandbox + .stub(dialog.commentsDialogEl.classList, 'contains') + .withArgs(constants.CLASS_HIDDEN) + .returns(true); dialog.hideCommentsDialog(); expect(classAdd).to.not.be.called; diff --git a/src/doc/__tests__/DocHighlightThread-test.js b/src/doc/__tests__/DocHighlightThread-test.js index 07db3900a..23971826f 100644 --- a/src/doc/__tests__/DocHighlightThread-test.js +++ b/src/doc/__tests__/DocHighlightThread-test.js @@ -4,13 +4,7 @@ import DocHighlightThread from '../DocHighlightThread'; import AnnotationService from '../../AnnotationService'; import * as util from '../../util'; import * as docUtil from '../docUtil'; -import { - STATES, - TYPES, - HIGHLIGHT_FILL, - SELECTOR_ANNOTATION_HIGHLIGHT_DIALOG, - SELECTOR_ANNOTATION_DIALOG -} from '../../constants'; +import { STATES, TYPES, HIGHLIGHT_FILL } from '../../constants'; let thread; const sandbox = sinon.sandbox.create(); @@ -539,9 +533,7 @@ describe('doc/DocHighlightThread', () => { const dimensionScaleStub = sandbox.stub(util, 'getDimensionScale').returns(false); const quadPoint = {}; thread.location.quadPoints = [quadPoint, quadPoint, quadPoint]; - const convertStub = sandbox - .stub(docUtil, 'convertPDFSpaceToDOMSpace') - .returns([0, 0, 0, 0, 0, 0, 0, 0]); + const convertStub = sandbox.stub(docUtil, 'convertPDFSpaceToDOMSpace').returns([0, 0, 0, 0, 0, 0, 0, 0]); thread.isInHighlight({ clientX: 0, clientY: 0 }); expect(pageElStub).to.be.called; @@ -559,9 +551,7 @@ describe('doc/DocHighlightThread', () => { const dimensionScaleStub = sandbox.stub(util, 'getDimensionScale').returns(true); const quadPoint = {}; thread.location.quadPoints = [quadPoint, quadPoint, quadPoint]; - const convertStub = sandbox - .stub(docUtil, 'convertPDFSpaceToDOMSpace') - .returns([0, 0, 0, 0, 0, 0, 0, 0]); + const convertStub = sandbox.stub(docUtil, 'convertPDFSpaceToDOMSpace').returns([0, 0, 0, 0, 0, 0, 0, 0]); thread.isInHighlight({ clientX: 0, clientY: 0 }); expect(pageElStub).to.be.called; @@ -579,9 +569,7 @@ describe('doc/DocHighlightThread', () => { const dimensionScaleStub = sandbox.stub(util, 'getDimensionScale').returns(false); const quadPoint = {}; thread.location.quadPoints = [quadPoint, quadPoint, quadPoint]; - const convertStub = sandbox - .stub(docUtil, 'convertPDFSpaceToDOMSpace') - .returns([0, 0, 0, 0, 0, 0, 0, 0]); + const convertStub = sandbox.stub(docUtil, 'convertPDFSpaceToDOMSpace').returns([0, 0, 0, 0, 0, 0, 0, 0]); const pointInPolyStub = sandbox.stub(docUtil, 'isPointInPolyOpt'); thread.isInHighlight({ clientX: 0, clientY: 0 }); @@ -607,10 +595,7 @@ describe('doc/DocHighlightThread', () => { it('should set the min/max x/y values for thread location', () => { thread.location = { - quadPoints: [ - [1, 1, 1, 1, 1, 1, 1, 1], - [10, 10, 10, 10, 10, 10, 10, 10] - ] + quadPoints: [[1, 1, 1, 1, 1, 1, 1, 1], [10, 10, 10, 10, 10, 10, 10, 10]] }; thread.regenerateBoundary(); expect(thread.minX).to.equal(1); diff --git a/src/doc/__tests__/DocPointDialog-test.js b/src/doc/__tests__/DocPointDialog-test.js index 394856896..baa36e905 100644 --- a/src/doc/__tests__/DocPointDialog-test.js +++ b/src/doc/__tests__/DocPointDialog-test.js @@ -1,7 +1,6 @@ /* eslint-disable no-unused-expressions */ import DocPointDialog from '../DocPointDialog'; import * as util from '../../util'; -import * as docUtil from '../docUtil'; let dialog; const sandbox = sinon.sandbox.create(); diff --git a/src/doc/__tests__/docUtil-test.js b/src/doc/__tests__/docUtil-test.js index 719f6a83c..06905c94c 100644 --- a/src/doc/__tests__/docUtil-test.js +++ b/src/doc/__tests__/docUtil-test.js @@ -1,11 +1,6 @@ /* eslint-disable no-unused-expressions */ import * as docUtil from '../docUtil'; -import { - SELECTOR_ANNOTATION_DIALOG, - SELECTOR_ANNOTATION_CONTAINER, - CLASS_ANNOTATION_DIALOG, - DATA_TYPE_ANNOTATION_DIALOG -} from '../../constants'; +import { SELECTOR_ANNOTATION_DIALOG, CLASS_ANNOTATION_DIALOG, DATA_TYPE_ANNOTATION_DIALOG } from '../../constants'; import * as util from '../../util'; const sandbox = sinon.sandbox.create(); @@ -72,10 +67,10 @@ describe('doc/docUtil', () => { it('should return true if the previous and current selection have changed', () => { const selection = { - getRangeAt: sandbox.stub().returns({ compareBoundaryPoints: sandbox.stub().returns(false)} ) + getRangeAt: sandbox.stub().returns({ compareBoundaryPoints: sandbox.stub().returns(false) }) }; const diffSelection = { - getRangeAt: sandbox.stub().returns({ compareBoundaryPoints: sandbox.stub().returns(true)} ) + getRangeAt: sandbox.stub().returns({ compareBoundaryPoints: sandbox.stub().returns(true) }) }; expect(docUtil.hasSelectionChanged(diffSelection, selection)).to.be.true; expect(docUtil.hasSelectionChanged(selection, selection)).to.be.false; @@ -308,7 +303,7 @@ describe('doc/docUtil', () => { docUtil.getContext(stubs.pageEl, 'random-class-name', 0, 0); expect(docStub).to.be.called; expect(stubs.annotationLayer.getContext).to.be.called; - expect(stubs.annotationLayer.classList.add).to.be.called;; + expect(stubs.annotationLayer.classList.add).to.be.called; expect(stubs.pageEl.insertBefore).to.not.be.called; expect(stubs.canvasWrapper.appendChild).to.be.called; }); @@ -339,8 +334,10 @@ describe('doc/docUtil', () => { }); describe('getDialogCoordsFromRange()', () => { - let range, parentContainer; + let range; + let parentContainer; const text = 'This is some text'; + beforeEach(() => { parentContainer = document.createElement('div'); parentContainer.innerHTML = text; @@ -408,7 +405,7 @@ describe('doc/docUtil', () => { it('should use the position element\'s bounds for the x and y corrdinate', () => { const fakeSpan = document.createElement('span'); sandbox.stub(fakeSpan, 'getBoundingClientRect').callsFake(() => { - return { right: 10, bottom: 11 } + return { right: 10, bottom: 11 }; }); const createStub = sandbox.stub(document, 'createElement'); diff --git a/src/drawing/__tests__/DrawingContainer-test.js b/src/drawing/__tests__/DrawingContainer-test.js index 079b6a533..cde5a119e 100644 --- a/src/drawing/__tests__/DrawingContainer-test.js +++ b/src/drawing/__tests__/DrawingContainer-test.js @@ -1,3 +1,4 @@ +/* eslint-disable no-unused-expressions */ import DrawingContainer from '../DrawingContainer'; let drawingContainer; @@ -19,19 +20,19 @@ describe('drawing/DrawingContainer', () => { describe('destroy()', () => { it('should clear the undo and redo stack', () => { - drawingContainer.redoStack = [1,2,3]; - drawingContainer.undoStack = [1,2,3]; + drawingContainer.redoStack = [1, 2, 3]; + drawingContainer.undoStack = [1, 2, 3]; drawingContainer.destroy(); - expect(drawingContainer.undoStack.length).to.equal(0) - expect(drawingContainer.redoStack.length).to.equal(0) + expect(drawingContainer.undoStack.length).to.equal(0); + expect(drawingContainer.redoStack.length).to.equal(0); }); }); describe('insert()', () => { it('should insert an item into the undoStack and clear the redo stack', () => { - drawingContainer.redoStack = [1,2,3]; + drawingContainer.redoStack = [1, 2, 3]; expect(drawingContainer.undoStack.length).to.equal(0); drawingContainer.insert(4); expect(drawingContainer.undoStack.length).to.equal(1); @@ -47,8 +48,8 @@ describe('drawing/DrawingContainer', () => { }); it('should move an item from the top of the undo stack to the top of the redo stack', () => { - drawingContainer.undoStack = [1,2,3]; - drawingContainer.redoStack = [4,5,6]; + drawingContainer.undoStack = [1, 2, 3]; + drawingContainer.redoStack = [4, 5, 6]; const lengthBefore = drawingContainer.undoStack.length; const topUndo = drawingContainer.undoStack[lengthBefore - 1]; const val = drawingContainer.undo(); @@ -68,8 +69,8 @@ describe('drawing/DrawingContainer', () => { }); it('should move an item from the top of the redo stack to the top of the undo stack', () => { - drawingContainer.undoStack = [1,2,3]; - drawingContainer.redoStack = [4,5,6]; + drawingContainer.undoStack = [1, 2, 3]; + drawingContainer.redoStack = [4, 5, 6]; const lengthBefore = drawingContainer.redoStack.length; const topRedo = drawingContainer.redoStack[lengthBefore - 1]; const val = drawingContainer.redo(); @@ -83,8 +84,8 @@ describe('drawing/DrawingContainer', () => { describe('getNumberOfItems()', () => { it('should return the number of items on the undo stack and redo stack', () => { - drawingContainer.undoStack = [1,2,3,4]; - drawingContainer.redoStack = [1,2]; + drawingContainer.undoStack = [1, 2, 3, 4]; + drawingContainer.redoStack = [1, 2]; const val = drawingContainer.getNumberOfItems(); expect(val.undoCount).to.equal(drawingContainer.undoStack.length); @@ -94,8 +95,8 @@ describe('drawing/DrawingContainer', () => { describe('getItems()', () => { it('should get the items on the undoStack', () => { - drawingContainer.undoStack = [1,2,3,4]; - drawingContainer.redoStack = [1,2]; + drawingContainer.undoStack = [1, 2, 3, 4]; + drawingContainer.redoStack = [1, 2]; const val = drawingContainer.getItems(); expect(val).to.not.deep.equal(drawingContainer.redoStack); @@ -111,7 +112,8 @@ describe('drawing/DrawingContainer', () => { }; drawingContainer.undoStack = [counter, counter, counter, counter]; drawingContainer.redoStack = [counter]; - drawingContainer.applyToItems((item) => item.count = item.count + 1); + // eslint-disable-next-line + drawingContainer.applyToItems(item => (item.count += 1)); expect(counter.count).to.equal(drawingContainer.undoStack.length); }); @@ -122,7 +124,8 @@ describe('drawing/DrawingContainer', () => { }; drawingContainer.undoStack = [counter, counter, counter, counter]; drawingContainer.redoStack = [counter, counter]; - drawingContainer.applyToItems((item) => item.count = item.count + 1, true); + // eslint-disable-next-line + drawingContainer.applyToItems(item => (item.count += 1), true); expect(counter.count).to.equal(drawingContainer.undoStack.length + drawingContainer.redoStack.length); }); @@ -154,14 +157,14 @@ describe('drawing/DrawingContainer', () => { minY: 6, maxX: 8, maxY: 9, - path: [1,2,3,4] + path: [1, 2, 3, 4] }; const path2 = { minX: 3, minY: 7, maxX: 14, maxY: 8, - path: [1,2,3] + path: [1, 2, 3] }; getItems.returns([path1, path2]); @@ -172,10 +175,7 @@ describe('drawing/DrawingContainer', () => { maxX: path2.maxX, minY: path1.minY, maxY: path1.maxY, - paths: [ - { path: path1.path }, - { path: path2.path } - ] + paths: [{ path: path1.path }, { path: path2.path }] }); }); }); diff --git a/src/drawing/__tests__/DrawingPath-test.js b/src/drawing/__tests__/DrawingPath-test.js index 5623be063..753082a38 100644 --- a/src/drawing/__tests__/DrawingPath-test.js +++ b/src/drawing/__tests__/DrawingPath-test.js @@ -1,3 +1,4 @@ +/* eslint-disable no-unused-expressions */ import DrawingPath from '../DrawingPath'; let drawingPath; @@ -34,20 +35,26 @@ describe('drawing/DrawingPath', () => { expect(lengthAfter).to.equal(lengthBefore); lengthBefore = drawingPath.browserPath.length; - drawingPath.addCoordinate({ - x: 1, - y: 1 - }, { - x: null, - y: 1 - }); - drawingPath.addCoordinate({ - x: 1, - y: 1 - }, { - x: 1, - y: null - }); + drawingPath.addCoordinate( + { + x: 1, + y: 1 + }, + { + x: null, + y: 1 + } + ); + drawingPath.addCoordinate( + { + x: 1, + y: 1 + }, + { + x: 1, + y: null + } + ); lengthAfter = drawingPath.browserPath.length; expect(lengthAfter).to.equal(lengthBefore); }); @@ -96,16 +103,14 @@ describe('drawing/DrawingPath', () => { expect(drawingPath.isEmpty()).to.be.true; }); - it('should return false when a coordinate has been inserted', () => { const coord = { x: 1, y: 1 - } + }; drawingPath.addCoordinate(coord); expect(drawingPath.isEmpty()).to.be.false; }); - }); describe('drawPath()', () => { @@ -117,11 +122,11 @@ describe('drawing/DrawingPath', () => { const docCoord = { x: 1, y: 1 - } + }; const browserCoord = { x: 1, y: 1 - } + }; drawingPath.addCoordinate(docCoord, browserCoord); drawingPath.drawPath(context); @@ -152,6 +157,8 @@ describe('drawing/DrawingPath', () => { describe('generateBrowserPath()', () => { it('should generate the browser path', () => { const lengthBefore = drawingPath.browserPath.length; + + // eslint-disable-next-line require-jsdoc const transform = (coord) => { return { x: coord.x + 1, @@ -167,7 +174,9 @@ describe('drawing/DrawingPath', () => { drawingPath.generateBrowserPath(transform); const lengthAfter = drawingPath.browserPath.length; - const isBrowserCoord = (item => (item.x === documentCoord.x+1 && item.y === documentCoord.y+1)); + + // eslint-disable-next-line require-jsdoc + const isBrowserCoord = (item) => item.x === documentCoord.x + 1 && item.y === documentCoord.y + 1; expect(lengthBefore).to.be.lessThan(lengthAfter); expect(drawingPath.browserPath.find(isBrowserCoord)).to.not.be.undefined; }); @@ -180,7 +189,7 @@ describe('drawing/DrawingPath', () => { minX: 5, maxX: 6, minY: 7, - maxY: 8, + maxY: 8 }; const result = DrawingPath.extractDrawingInfo(drawingObjA, {}); @@ -188,17 +197,12 @@ describe('drawing/DrawingPath', () => { expect(result.minY).to.equal(drawingObjA.minY); expect(result.maxX).to.equal(drawingObjA.maxX); expect(result.maxY).to.equal(drawingObjA.maxY); - expect(result.paths).to.deep.equal([ - { path: drawingObjA.path } - ]); + expect(result.paths).to.deep.equal([{ path: drawingObjA.path }]); }); it('should add a path to the accumulator', () => { const acc = { - paths: [ - { path: 'pathA' }, - { path: 'pathB' } - ], + paths: [{ path: 'pathA' }, { path: 'pathB' }], minX: 5, maxX: 11, minY: 6, @@ -217,11 +221,7 @@ describe('drawing/DrawingPath', () => { expect(result.minY).to.equal(drawingObjC.minY); expect(result.maxX).to.equal(acc.maxX); expect(result.maxY).to.equal(acc.maxY); - expect(result.paths).to.deep.equal([ - { path: 'pathA' }, - { path: 'pathB' }, - { path: 'pathC' } - ]); + expect(result.paths).to.deep.equal([{ path: 'pathA' }, { path: 'pathB' }, { path: 'pathC' }]); }); }); }); diff --git a/src/drawing/__tests__/DrawingThread-test.js b/src/drawing/__tests__/DrawingThread-test.js index 5cc1966d6..0fa3f3fef 100644 --- a/src/drawing/__tests__/DrawingThread-test.js +++ b/src/drawing/__tests__/DrawingThread-test.js @@ -1,9 +1,7 @@ +/* eslint-disable no-unused-expressions */ import DrawingThread from '../DrawingThread'; import AnnotationService from '../../AnnotationService'; -import { - STATES, - THREAD_EVENT -} from '../../constants' +import { STATES } from '../../constants'; let thread; let stubs; @@ -24,7 +22,7 @@ describe('drawing/DrawingThread', () => { fileId: 1, token: 'someToken', canAnnotate: true, - user: 'completelyRealUser', + user: 'completelyRealUser' }), fileVersionId: 1, location: {}, @@ -61,7 +59,7 @@ describe('drawing/DrawingThread', () => { expect(window.cancelAnimationFrame).to.be.calledWith(1); expect(thread.reset).to.be.called; - }) + }); }); describe('reset()', () => { @@ -70,7 +68,7 @@ describe('drawing/DrawingThread', () => { thread.reset(); expect(thread.clearBoundary).to.be.called; }); - }) + }); describe('deleteThread()', () => { it('should delete all attached annotations, clear the drawn rectangle, and call destroy', () => { @@ -87,7 +85,6 @@ describe('drawing/DrawingThread', () => { thread.annotations = { '123abc': {} }; - thread.deleteThread(); expect(thread.getBrowserRectangularBoundary).to.be.called; expect(thread.concreteContext.clearRect).to.be.called; @@ -119,7 +116,7 @@ describe('drawing/DrawingThread', () => { lineWidth: thread.drawingContext.lineWidth }); expect(thread.drawingContext.lineWidth % config.scale).to.equal(0); - }) + }); }); describe('render()', () => { @@ -318,7 +315,7 @@ describe('drawing/DrawingThread', () => { stroke: sandbox.stub(), restore: sandbox.stub() }; - stubs.getBrowserRectangularBoundary.returns([1,2,5,6]); + stubs.getBrowserRectangularBoundary.returns([1, 2, 5, 6]); thread.location = { page: 1 }; thread.drawBoundary(); @@ -329,7 +326,7 @@ describe('drawing/DrawingThread', () => { expect(thread.drawingContext.rect).to.be.called; expect(thread.drawingContext.stroke).to.be.called; expect(thread.drawingContext.restore).to.be.called; - }) + }); }); describe('regenerateBoundary()', () => { diff --git a/src/image/__tests__/ImageAnnotator-test.js b/src/image/__tests__/ImageAnnotator-test.js index 0cbf7380f..835b790fd 100644 --- a/src/image/__tests__/ImageAnnotator-test.js +++ b/src/image/__tests__/ImageAnnotator-test.js @@ -3,7 +3,7 @@ import ImageAnnotator from '../ImageAnnotator'; import ImagePointThread from '../ImagePointThread'; import * as util from '../../util'; import * as imageUtil from '../imageUtil'; -import { TYPES, ANNOTATOR_EVENT, SELECTOR_ANNOTATION_POINT_BUTTON } from '../../constants'; +import { TYPES, ANNOTATOR_EVENT } from '../../constants'; let annotator; const sandbox = sinon.sandbox.create(); @@ -76,11 +76,13 @@ describe('image/ImageAnnotator', () => { annotator.hasTouch = false; imageEl = annotator.annotatedElement.querySelector('img'); event = { - targetTouches: [{ - clientX: x, - clientY: y, - target: imageEl - }] + targetTouches: [ + { + clientX: x, + clientY: y, + target: imageEl + } + ] }; }); @@ -114,9 +116,11 @@ describe('image/ImageAnnotator', () => { expect(location).to.be.null; event = { - targetTouches: [{ - target: imageEl - }] + targetTouches: [ + { + target: imageEl + } + ] }; expect(annotator.getLocationFromEvent(event)).to.be.null; }); @@ -211,7 +215,7 @@ describe('image/ImageAnnotator', () => { getButton: () => {} }; stubs.controllerMock = sandbox.mock(stubs.controller); - annotator.modeControllers['point'] = stubs.controller; + annotator.modeControllers.point = stubs.controller; }); afterEach(() => { diff --git a/src/image/__tests__/ImagePointDialog-test.js b/src/image/__tests__/ImagePointDialog-test.js index 8d8fe94e2..3e1acf358 100644 --- a/src/image/__tests__/ImagePointDialog-test.js +++ b/src/image/__tests__/ImagePointDialog-test.js @@ -1,7 +1,6 @@ /* eslint-disable no-unused-expressions */ import ImagePointDialog from '../ImagePointDialog'; import * as util from '../../util'; -import * as imageUtil from '../imageUtil'; let dialog; const sandbox = sinon.sandbox.create(); diff --git a/src/image/__tests__/ImagePointThread-test.js b/src/image/__tests__/ImagePointThread-test.js index bc36255a2..7fe18b6ef 100644 --- a/src/image/__tests__/ImagePointThread-test.js +++ b/src/image/__tests__/ImagePointThread-test.js @@ -71,7 +71,7 @@ describe('image/ImagePointThread', () => { expect(thread.showDialog).to.not.be.called; }); - + it('should not show dialog if user is on a mobile device and the thread has no annotations yet', () => { thread.isMobile = true; thread.annotations = {};