Skip to content

Commit

Permalink
Chore: Run eslint on test files (#149)
Browse files Browse the repository at this point in the history
* Chore: Run eslint on test files
* Chore: Fix tests
  • Loading branch information
pramodsum authored Mar 29, 2018
1 parent abbaf03 commit 75277fc
Show file tree
Hide file tree
Showing 28 changed files with 376 additions and 396 deletions.
4 changes: 3 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }]
Expand Down
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
src/third-party/*
dist/*
docs/*
lib/*
**/__tests__/*
index.js
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"sinon": false,
"assert": false,
"fixture": false,
"__": false
"__": false,
"Assert": false
},
"rules": {
"quotes": [
Expand Down
1 change: 0 additions & 1 deletion src/__tests__/AnnotationDialog-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
17 changes: 13 additions & 4 deletions src/__tests__/AnnotationService-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
});
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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;
});
});
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
3 changes: 0 additions & 3 deletions src/__tests__/AnnotationThread-test.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
134 changes: 64 additions & 70 deletions src/__tests__/Annotator-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand Down Expand Up @@ -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,
Expand All @@ -67,7 +52,7 @@ describe('Annotator', () => {
loadError: 'load error',
createError: 'create error',
deleteError: 'delete error',
authError: 'auth error',
authError: 'auth error'
}
});

Expand Down Expand Up @@ -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);
});
});
});

Expand All @@ -243,16 +232,16 @@ 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);
annotator.setupControllers();
});

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');
Expand All @@ -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');
Expand All @@ -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;
});
});

Expand Down Expand Up @@ -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', () => {
Expand All @@ -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', () => {
Expand All @@ -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;
});
});
});

Expand Down Expand Up @@ -519,7 +513,7 @@ describe('Annotator', () => {

describe('handleControllerEvents()', () => {
const mode = 'something';
let data = { mode };
const data = { mode };

beforeEach(() => {
sandbox.stub(annotator, 'emit');
Expand Down Expand Up @@ -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');
});
Expand All @@ -614,7 +608,7 @@ describe('Annotator', () => {
stubs.thread.dialog = { postAnnotation: sandbox.stub() };

annotator.modeControllers = {
'point': stubs.controller
point: stubs.controller
};
});

Expand Down Expand Up @@ -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 } }
}
Expand Down Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 75277fc

Please sign in to comment.