Commit 93ab3162 authored by Robert Knight's avatar Robert Knight

Rename "fakeAnnotationUI" => "fakeStore"

Rename the fake/stub implementations of the Redux store used in various
component and service tests.
parent 284149f9
...@@ -101,7 +101,7 @@ describe('annotation', function() { ...@@ -101,7 +101,7 @@ describe('annotation', function() {
}; };
var fakeAnalytics; var fakeAnalytics;
var fakeAnnotationMapper; var fakeAnnotationMapper;
var fakeAnnotationUI; var fakeStore;
var fakeDrafts; var fakeDrafts;
var fakeFlash; var fakeFlash;
var fakeGroups; var fakeGroups;
...@@ -177,7 +177,7 @@ describe('annotation', function() { ...@@ -177,7 +177,7 @@ describe('annotation', function() {
flagAnnotation: sandbox.stub(), flagAnnotation: sandbox.stub(),
}; };
fakeAnnotationUI = { fakeStore = {
updateFlagStatus: sandbox.stub().returns(true), updateFlagStatus: sandbox.stub().returns(true),
}; };
...@@ -244,7 +244,7 @@ describe('annotation', function() { ...@@ -244,7 +244,7 @@ describe('annotation', function() {
$provide.value('analytics', fakeAnalytics); $provide.value('analytics', fakeAnalytics);
$provide.value('annotationMapper', fakeAnnotationMapper); $provide.value('annotationMapper', fakeAnnotationMapper);
$provide.value('store', fakeAnnotationUI); $provide.value('store', fakeStore);
$provide.value('api', fakeApi); $provide.value('api', fakeApi);
$provide.value('drafts', fakeDrafts); $provide.value('drafts', fakeDrafts);
$provide.value('flash', fakeFlash); $provide.value('flash', fakeFlash);
......
...@@ -3,12 +3,12 @@ ...@@ -3,12 +3,12 @@
var angular = require('angular'); var angular = require('angular');
describe('helpPanel', function () { describe('helpPanel', function () {
var fakeAnnotationUI; var fakeStore;
var $componentController; var $componentController;
var $rootScope; var $rootScope;
beforeEach(function () { beforeEach(function () {
fakeAnnotationUI = { fakeStore = {
frames: sinon.stub().returns([]), frames: sinon.stub().returns([]),
}; };
...@@ -16,7 +16,7 @@ describe('helpPanel', function () { ...@@ -16,7 +16,7 @@ describe('helpPanel', function () {
.component('helpPanel', require('../help-panel')); .component('helpPanel', require('../help-panel'));
angular.mock.module('h', { angular.mock.module('h', {
store: fakeAnnotationUI, store: fakeStore,
serviceUrl: sinon.stub(), serviceUrl: sinon.stub(),
}); });
...@@ -27,7 +27,7 @@ describe('helpPanel', function () { ...@@ -27,7 +27,7 @@ describe('helpPanel', function () {
}); });
it('displays the URL and fingerprint of the first connected frame', function () { it('displays the URL and fingerprint of the first connected frame', function () {
fakeAnnotationUI.frames.returns([{ fakeStore.frames.returns([{
uri: 'https://publisher.org/article.pdf', uri: 'https://publisher.org/article.pdf',
metadata: { metadata: {
documentFingerprint: '12345', documentFingerprint: '12345',
......
...@@ -12,7 +12,7 @@ describe('sidebar.components.hypothesis-app', function () { ...@@ -12,7 +12,7 @@ describe('sidebar.components.hypothesis-app', function () {
var $scope = null; var $scope = null;
var $rootScope = null; var $rootScope = null;
var fakeAnnotationMetadata = null; var fakeAnnotationMetadata = null;
var fakeAnnotationUI = null; var fakeStore = null;
var fakeAnalytics = null; var fakeAnalytics = null;
var fakeAuth = null; var fakeAuth = null;
var fakeBridge = null; var fakeBridge = null;
...@@ -64,7 +64,7 @@ describe('sidebar.components.hypothesis-app', function () { ...@@ -64,7 +64,7 @@ describe('sidebar.components.hypothesis-app', function () {
beforeEach(angular.mock.module('h')); beforeEach(angular.mock.module('h'));
beforeEach(angular.mock.module(function ($provide) { beforeEach(angular.mock.module(function ($provide) {
fakeAnnotationUI = { fakeStore = {
tool: 'comment', tool: 'comment',
clearSelectedAnnotations: sandbox.spy(), clearSelectedAnnotations: sandbox.spy(),
}; };
...@@ -130,7 +130,7 @@ describe('sidebar.components.hypothesis-app', function () { ...@@ -130,7 +130,7 @@ describe('sidebar.components.hypothesis-app', function () {
call: sandbox.stub(), call: sandbox.stub(),
}; };
$provide.value('store', fakeAnnotationUI); $provide.value('store', fakeStore);
$provide.value('auth', fakeAuth); $provide.value('auth', fakeAuth);
$provide.value('analytics', fakeAnalytics); $provide.value('analytics', fakeAnalytics);
$provide.value('drafts', fakeDrafts); $provide.value('drafts', fakeDrafts);
......
...@@ -10,7 +10,7 @@ var moderatedAnnotation = fixtures.moderatedAnnotation; ...@@ -10,7 +10,7 @@ var moderatedAnnotation = fixtures.moderatedAnnotation;
describe('moderationBanner', function () { describe('moderationBanner', function () {
var bannerEl; var bannerEl;
var fakeAnnotationUI; var fakeStore;
var fakeFlash; var fakeFlash;
var fakeApi; var fakeApi;
...@@ -20,7 +20,7 @@ describe('moderationBanner', function () { ...@@ -20,7 +20,7 @@ describe('moderationBanner', function () {
}); });
beforeEach(function () { beforeEach(function () {
fakeAnnotationUI = { fakeStore = {
hideAnnotation: sinon.stub(), hideAnnotation: sinon.stub(),
unhideAnnotation: sinon.stub(), unhideAnnotation: sinon.stub(),
}; };
...@@ -37,7 +37,7 @@ describe('moderationBanner', function () { ...@@ -37,7 +37,7 @@ describe('moderationBanner', function () {
}; };
angular.mock.module('app', { angular.mock.module('app', {
store: fakeAnnotationUI, store: fakeStore,
api: fakeApi, api: fakeApi,
flash: fakeFlash, flash: fakeFlash,
}); });
......
...@@ -8,7 +8,7 @@ var util = require('../../directive/test/util'); ...@@ -8,7 +8,7 @@ var util = require('../../directive/test/util');
describe('newNoteBtn', function () { describe('newNoteBtn', function () {
var $rootScope; var $rootScope;
var sandbox = sinon.sandbox.create(); var sandbox = sinon.sandbox.create();
var fakeAnnotationUI = { var fakeStore = {
frames: sinon.stub().returns([{ id: null, uri: 'www.example.org'}, { id: '1', uri: 'www.example.org'}]), frames: sinon.stub().returns([{ id: null, uri: 'www.example.org'}, { id: '1', uri: 'www.example.org'}]),
}; };
...@@ -25,7 +25,7 @@ describe('newNoteBtn', function () { ...@@ -25,7 +25,7 @@ describe('newNoteBtn', function () {
var fakeSettings = { theme: 'clean' }; var fakeSettings = { theme: 'clean' };
angular.mock.module('app', { angular.mock.module('app', {
store: fakeAnnotationUI, store: fakeStore,
features: fakeFeatures, features: fakeFeatures,
settings: fakeSettings, settings: fakeSettings,
}); });
...@@ -45,7 +45,7 @@ describe('newNoteBtn', function () { ...@@ -45,7 +45,7 @@ describe('newNoteBtn', function () {
uri: 'www.example.org', uri: 'www.example.org',
}; };
var elem = util.createDirective(document, 'newNoteBtn', { var elem = util.createDirective(document, 'newNoteBtn', {
store: fakeAnnotationUI, store: fakeStore,
}); });
sandbox.spy($rootScope, '$broadcast'); sandbox.spy($rootScope, '$broadcast');
elem.ctrl.onNewNoteBtnClick(); elem.ctrl.onNewNoteBtnClick();
......
...@@ -22,13 +22,13 @@ describe('selectionTabs', function () { ...@@ -22,13 +22,13 @@ describe('selectionTabs', function () {
}); });
beforeEach(function () { beforeEach(function () {
var fakeAnnotationUI = {}; var fakeStore = {};
var fakeFeatures = { var fakeFeatures = {
flagEnabled: sinon.stub().returns(true), flagEnabled: sinon.stub().returns(true),
}; };
angular.mock.module('app', { angular.mock.module('app', {
store: fakeAnnotationUI, store: fakeStore,
features: fakeFeatures, features: fakeFeatures,
session: fakeSession, session: fakeSession,
settings: fakeSettings, settings: fakeSettings,
......
...@@ -6,33 +6,33 @@ var util = require('../../directive/test/util'); ...@@ -6,33 +6,33 @@ var util = require('../../directive/test/util');
describe('shareDialog', function () { describe('shareDialog', function () {
var fakeAnalytics; var fakeAnalytics;
var fakeAnnotationUI; var fakeStore;
beforeEach(function () { beforeEach(function () {
fakeAnalytics = { fakeAnalytics = {
track: sinon.stub(), track: sinon.stub(),
events: {}, events: {},
}; };
fakeAnnotationUI = { frames: sinon.stub().returns([]) }; fakeStore = { frames: sinon.stub().returns([]) };
angular.module('h', []) angular.module('h', [])
.component('shareDialog', require('../share-dialog')) .component('shareDialog', require('../share-dialog'))
.value('analytics', fakeAnalytics) .value('analytics', fakeAnalytics)
.value('store', fakeAnnotationUI) .value('store', fakeStore)
.value('urlEncodeFilter', function (val) { return val; }); .value('urlEncodeFilter', function (val) { return val; });
angular.mock.module('h'); angular.mock.module('h');
}); });
it('generates new via link', function () { it('generates new via link', function () {
var element = util.createDirective(document, 'shareDialog', {}); var element = util.createDirective(document, 'shareDialog', {});
fakeAnnotationUI.frames.returns([{ uri: 'http://example.com' }]); fakeStore.frames.returns([{ uri: 'http://example.com' }]);
element.scope.$digest(); element.scope.$digest();
assert.equal(element.ctrl.viaPageLink, 'https://via.hypothes.is/http://example.com'); assert.equal(element.ctrl.viaPageLink, 'https://via.hypothes.is/http://example.com');
}); });
it('does not generate new via link if already on via', function () { it('does not generate new via link if already on via', function () {
var element = util.createDirective(document, 'shareDialog', {}); var element = util.createDirective(document, 'shareDialog', {});
fakeAnnotationUI.frames.returns([{ fakeStore.frames.returns([{
uri: 'https://via.hypothes.is/http://example.com', uri: 'https://via.hypothes.is/http://example.com',
}]); }]);
element.scope.$digest(); element.scope.$digest();
......
...@@ -15,7 +15,7 @@ describe('StreamContentController', function () { ...@@ -15,7 +15,7 @@ describe('StreamContentController', function () {
var fakeRoute; var fakeRoute;
var fakeRouteParams; var fakeRouteParams;
var fakeAnnotationMapper; var fakeAnnotationMapper;
var fakeAnnotationUI; var fakeStore;
var fakeQueryParser; var fakeQueryParser;
var fakeRootThread; var fakeRootThread;
var fakeSearchFilter; var fakeSearchFilter;
...@@ -35,7 +35,7 @@ describe('StreamContentController', function () { ...@@ -35,7 +35,7 @@ describe('StreamContentController', function () {
loadAnnotations: sinon.spy(), loadAnnotations: sinon.spy(),
}; };
fakeAnnotationUI = { fakeStore = {
clearAnnotations: sinon.spy(), clearAnnotations: sinon.spy(),
setAppIsSidebar: sinon.spy(), setAppIsSidebar: sinon.spy(),
setCollapsed: sinon.spy(), setCollapsed: sinon.spy(),
...@@ -84,7 +84,7 @@ describe('StreamContentController', function () { ...@@ -84,7 +84,7 @@ describe('StreamContentController', function () {
$route: fakeRoute, $route: fakeRoute,
$routeParams: fakeRouteParams, $routeParams: fakeRouteParams,
annotationMapper: fakeAnnotationMapper, annotationMapper: fakeAnnotationMapper,
store: fakeAnnotationUI, store: fakeStore,
api: fakeApi, api: fakeApi,
queryParser: fakeQueryParser, queryParser: fakeQueryParser,
rootThread: fakeRootThread, rootThread: fakeRootThread,
...@@ -136,7 +136,7 @@ describe('StreamContentController', function () { ...@@ -136,7 +136,7 @@ describe('StreamContentController', function () {
createController(); createController();
fakeRouteParams.q = 'new query'; fakeRouteParams.q = 'new query';
$rootScope.$broadcast('$routeUpdate'); $rootScope.$broadcast('$routeUpdate');
assert.called(fakeAnnotationUI.clearAnnotations); assert.called(fakeStore.clearAnnotations);
assert.calledOnce(fakeRoute.reload); assert.calledOnce(fakeRoute.reload);
}); });
...@@ -144,7 +144,7 @@ describe('StreamContentController', function () { ...@@ -144,7 +144,7 @@ describe('StreamContentController', function () {
fakeRouteParams.q = 'test query'; fakeRouteParams.q = 'test query';
createController(); createController();
$rootScope.$broadcast('$routeUpdate'); $rootScope.$broadcast('$routeUpdate');
assert.notCalled(fakeAnnotationUI.clearAnnotations); assert.notCalled(fakeStore.clearAnnotations);
assert.notCalled(fakeRoute.reload); assert.notCalled(fakeRoute.reload);
}); });
}); });
......
...@@ -51,7 +51,7 @@ var fixtures = { ...@@ -51,7 +51,7 @@ var fixtures = {
}; };
describe('sidebar.frame-sync', function () { describe('sidebar.frame-sync', function () {
var fakeAnnotationUI; var fakeStore;
var fakeBridge; var fakeBridge;
var frameSync; var frameSync;
var $rootScope; var $rootScope;
...@@ -62,7 +62,7 @@ describe('sidebar.frame-sync', function () { ...@@ -62,7 +62,7 @@ describe('sidebar.frame-sync', function () {
}); });
beforeEach(function () { beforeEach(function () {
fakeAnnotationUI = fakeStore({annotations: []}, { fakeStore = fakeStore({annotations: []}, {
connectFrame: sinon.stub(), connectFrame: sinon.stub(),
destroyFrame: sinon.stub(), destroyFrame: sinon.stub(),
findIDsForTags: sinon.stub(), findIDsForTags: sinon.stub(),
...@@ -92,7 +92,7 @@ describe('sidebar.frame-sync', function () { ...@@ -92,7 +92,7 @@ describe('sidebar.frame-sync', function () {
angular.mock.module('app', { angular.mock.module('app', {
Discovery: FakeDiscovery, Discovery: FakeDiscovery,
store: fakeAnnotationUI, store: fakeStore,
bridge: fakeBridge, bridge: fakeBridge,
}); });
...@@ -108,7 +108,7 @@ describe('sidebar.frame-sync', function () { ...@@ -108,7 +108,7 @@ describe('sidebar.frame-sync', function () {
context('when annotations are loaded into the sidebar', function () { context('when annotations are loaded into the sidebar', function () {
it('sends a "loadAnnotations" message to the frame', function () { it('sends a "loadAnnotations" message to the frame', function () {
fakeAnnotationUI.setState({annotations: [fixtures.ann]}); fakeStore.setState({annotations: [fixtures.ann]});
assert.calledWithMatch(fakeBridge.call, 'loadAnnotations', sinon.match([ assert.calledWithMatch(fakeBridge.call, 'loadAnnotations', sinon.match([
formatAnnot(fixtures.ann), formatAnnot(fixtures.ann),
])); ]));
...@@ -116,10 +116,10 @@ describe('sidebar.frame-sync', function () { ...@@ -116,10 +116,10 @@ describe('sidebar.frame-sync', function () {
it('sends a "loadAnnotations" message only for new annotations', function () { it('sends a "loadAnnotations" message only for new annotations', function () {
var ann2 = Object.assign({}, fixtures.ann, {$tag: 't2', id: 'a2'}); var ann2 = Object.assign({}, fixtures.ann, {$tag: 't2', id: 'a2'});
fakeAnnotationUI.setState({annotations: [fixtures.ann]}); fakeStore.setState({annotations: [fixtures.ann]});
fakeBridge.call.reset(); fakeBridge.call.reset();
fakeAnnotationUI.setState({annotations: [fixtures.ann, ann2]}); fakeStore.setState({annotations: [fixtures.ann, ann2]});
assert.calledWithMatch(fakeBridge.call, 'loadAnnotations', sinon.match([ assert.calledWithMatch(fakeBridge.call, 'loadAnnotations', sinon.match([
formatAnnot(ann2), formatAnnot(ann2),
...@@ -127,37 +127,37 @@ describe('sidebar.frame-sync', function () { ...@@ -127,37 +127,37 @@ describe('sidebar.frame-sync', function () {
}); });
it('does not send a "loadAnnotations" message for replies', function () { it('does not send a "loadAnnotations" message for replies', function () {
fakeAnnotationUI.setState({annotations: [annotationFixtures.newReply()]}); fakeStore.setState({annotations: [annotationFixtures.newReply()]});
assert.isFalse(fakeBridge.call.calledWith('loadAnnotations')); assert.isFalse(fakeBridge.call.calledWith('loadAnnotations'));
}); });
}); });
context('when annotation count has changed', function () { context('when annotation count has changed', function () {
it('sends a "publicAnnotationCountChanged" message to the frame when there are public annotations', function () { it('sends a "publicAnnotationCountChanged" message to the frame when there are public annotations', function () {
fakeAnnotationUI.setState({ fakeStore.setState({
annotations: [annotationFixtures.publicAnnotation()], annotations: [annotationFixtures.publicAnnotation()],
}); });
assert.calledWithMatch(fakeBridge.call, 'publicAnnotationCountChanged', sinon.match(1)); assert.calledWithMatch(fakeBridge.call, 'publicAnnotationCountChanged', sinon.match(1));
}); });
it('sends a "publicAnnotationCountChanged" message to the frame when there are only private annotations', function () { it('sends a "publicAnnotationCountChanged" message to the frame when there are only private annotations', function () {
fakeAnnotationUI.setState({ fakeStore.setState({
annotations: [annotationFixtures.defaultAnnotation()], annotations: [annotationFixtures.defaultAnnotation()],
}); });
assert.calledWithMatch(fakeBridge.call, 'publicAnnotationCountChanged', sinon.match(0)); assert.calledWithMatch(fakeBridge.call, 'publicAnnotationCountChanged', sinon.match(0));
}); });
it('does not send a "publicAnnotationCountChanged" message to the frame if annotation fetch is not complete', function () { it('does not send a "publicAnnotationCountChanged" message to the frame if annotation fetch is not complete', function () {
fakeAnnotationUI.frames.returns([{uri: 'http://example.com'}]); fakeStore.frames.returns([{uri: 'http://example.com'}]);
fakeAnnotationUI.setState({ fakeStore.setState({
annotations: [annotationFixtures.publicAnnotation()], annotations: [annotationFixtures.publicAnnotation()],
}); });
assert.isFalse(fakeBridge.call.calledWith('publicAnnotationCountChanged')); assert.isFalse(fakeBridge.call.calledWith('publicAnnotationCountChanged'));
}); });
it('does not send a "publicAnnotationCountChanged" message if there are no connected frames', function () { it('does not send a "publicAnnotationCountChanged" message if there are no connected frames', function () {
fakeAnnotationUI.frames.returns([]); fakeStore.frames.returns([]);
fakeAnnotationUI.setState({ fakeStore.setState({
annotations: [annotationFixtures.publicAnnotation()], annotations: [annotationFixtures.publicAnnotation()],
}); });
assert.isFalse(fakeBridge.call.calledWith('publicAnnotationCountChanged')); assert.isFalse(fakeBridge.call.calledWith('publicAnnotationCountChanged'));
...@@ -166,8 +166,8 @@ describe('sidebar.frame-sync', function () { ...@@ -166,8 +166,8 @@ describe('sidebar.frame-sync', function () {
context('when annotations are removed from the sidebar', function () { context('when annotations are removed from the sidebar', function () {
it('sends a "deleteAnnotation" message to the frame', function () { it('sends a "deleteAnnotation" message to the frame', function () {
fakeAnnotationUI.setState({annotations: [fixtures.ann]}); fakeStore.setState({annotations: [fixtures.ann]});
fakeAnnotationUI.setState({annotations: []}); fakeStore.setState({annotations: []});
assert.calledWithMatch(fakeBridge.call, 'deleteAnnotation', assert.calledWithMatch(fakeBridge.call, 'deleteAnnotation',
sinon.match(formatAnnot(fixtures.ann))); sinon.match(formatAnnot(fixtures.ann)));
}); });
...@@ -210,7 +210,7 @@ describe('sidebar.frame-sync', function () { ...@@ -210,7 +210,7 @@ describe('sidebar.frame-sync', function () {
expireDebounceTimeout(); expireDebounceTimeout();
assert.calledWith(fakeAnnotationUI.updateAnchorStatus, { t1: 'anchored' }); assert.calledWith(fakeStore.updateAnchorStatus, { t1: 'anchored' });
}); });
it('coalesces multiple "sync" messages', () => { it('coalesces multiple "sync" messages', () => {
...@@ -219,7 +219,7 @@ describe('sidebar.frame-sync', function () { ...@@ -219,7 +219,7 @@ describe('sidebar.frame-sync', function () {
expireDebounceTimeout(); expireDebounceTimeout();
assert.calledWith(fakeAnnotationUI.updateAnchorStatus, { assert.calledWith(fakeStore.updateAnchorStatus, {
t1: 'anchored', t1: 'anchored',
t2: 'orphan', t2: 'orphan',
}); });
...@@ -249,7 +249,7 @@ describe('sidebar.frame-sync', function () { ...@@ -249,7 +249,7 @@ describe('sidebar.frame-sync', function () {
fakeBridge.emit('connect', fakeChannel); fakeBridge.emit('connect', fakeChannel);
assert.calledWith(fakeAnnotationUI.connectFrame, { assert.calledWith(fakeStore.connectFrame, {
id: frameInfo.frameIdentifier, id: frameInfo.frameIdentifier,
metadata: frameInfo.metadata, metadata: frameInfo.metadata,
uri: frameInfo.uri, uri: frameInfo.uri,
...@@ -263,32 +263,32 @@ describe('sidebar.frame-sync', function () { ...@@ -263,32 +263,32 @@ describe('sidebar.frame-sync', function () {
it('removes the frame from the frames list', function () { it('removes the frame from the frames list', function () {
fakeBridge.emit('destroyFrame', frameId); fakeBridge.emit('destroyFrame', frameId);
assert.calledWith(fakeAnnotationUI.destroyFrame, fixtures.framesListEntry); assert.calledWith(fakeStore.destroyFrame, fixtures.framesListEntry);
}); });
}); });
describe('on "showAnnotations" message', function () { describe('on "showAnnotations" message', function () {
it('selects annotations which have an ID', function () { it('selects annotations which have an ID', function () {
fakeAnnotationUI.findIDsForTags.returns(['id1','id2','id3']); fakeStore.findIDsForTags.returns(['id1','id2','id3']);
fakeBridge.emit('showAnnotations', ['tag1', 'tag2', 'tag3']); fakeBridge.emit('showAnnotations', ['tag1', 'tag2', 'tag3']);
assert.calledWith(fakeAnnotationUI.selectAnnotations, ['id1', 'id2', 'id3']); assert.calledWith(fakeStore.selectAnnotations, ['id1', 'id2', 'id3']);
assert.calledWith(fakeAnnotationUI.selectTab, uiConstants.TAB_ANNOTATIONS); assert.calledWith(fakeStore.selectTab, uiConstants.TAB_ANNOTATIONS);
}); });
}); });
describe('on "focusAnnotations" message', function () { describe('on "focusAnnotations" message', function () {
it('focuses the annotations', function () { it('focuses the annotations', function () {
fakeBridge.emit('focusAnnotations', ['tag1', 'tag2', 'tag3']); fakeBridge.emit('focusAnnotations', ['tag1', 'tag2', 'tag3']);
assert.calledWith(fakeAnnotationUI.focusAnnotations, ['tag1', 'tag2', 'tag3']); assert.calledWith(fakeStore.focusAnnotations, ['tag1', 'tag2', 'tag3']);
}); });
}); });
describe('on "toggleAnnotationSelection" message', function () { describe('on "toggleAnnotationSelection" message', function () {
it('toggles the selected state of the annotations', function () { it('toggles the selected state of the annotations', function () {
fakeAnnotationUI.findIDsForTags.returns(['id1','id2','id3']); fakeStore.findIDsForTags.returns(['id1','id2','id3']);
fakeBridge.emit('toggleAnnotationSelection', ['tag1', 'tag2', 'tag3']); fakeBridge.emit('toggleAnnotationSelection', ['tag1', 'tag2', 'tag3']);
assert.calledWith(fakeAnnotationUI.toggleSelectedAnnotations, ['id1', 'id2', 'id3']); assert.calledWith(fakeStore.toggleSelectedAnnotations, ['id1', 'id2', 'id3']);
}); });
}); });
......
...@@ -13,7 +13,7 @@ var sessionWithThreeGroups = function() { ...@@ -13,7 +13,7 @@ var sessionWithThreeGroups = function() {
}; };
describe('groups', function() { describe('groups', function() {
var fakeAnnotationUI; var fakeStore;
var fakeIsSidebar; var fakeIsSidebar;
var fakeSession; var fakeSession;
var fakeSettings; var fakeSettings;
...@@ -26,7 +26,7 @@ describe('groups', function() { ...@@ -26,7 +26,7 @@ describe('groups', function() {
beforeEach(function() { beforeEach(function() {
sandbox = sinon.sandbox.create(); sandbox = sinon.sandbox.create();
fakeAnnotationUI = fakeReduxStore({ fakeStore = fakeReduxStore({
searchUris: ['http://example.org'], searchUris: ['http://example.org'],
},{ },{
searchUris() { searchUris() {
...@@ -77,7 +77,7 @@ describe('groups', function() { ...@@ -77,7 +77,7 @@ describe('groups', function() {
}); });
function service() { function service() {
return groups(fakeRootScope, fakeAnnotationUI, fakeApi, fakeIsSidebar, fakeLocalStorage, fakeServiceUrl, return groups(fakeRootScope, fakeStore, fakeApi, fakeIsSidebar, fakeLocalStorage, fakeServiceUrl,
fakeSession, fakeSettings); fakeSession, fakeSettings);
} }
...@@ -134,9 +134,9 @@ describe('groups', function() { ...@@ -134,9 +134,9 @@ describe('groups', function() {
it('waits for the document URL to be determined', () => { it('waits for the document URL to be determined', () => {
var svc = service(); var svc = service();
fakeAnnotationUI.setState({ searchUris: [] }); fakeStore.setState({ searchUris: [] });
var loaded = svc.load(); var loaded = svc.load();
fakeAnnotationUI.setState({ searchUris: ['https://asite.com'] }); fakeStore.setState({ searchUris: ['https://asite.com'] });
return loaded.then(() => { return loaded.then(() => {
assert.calledWith(fakeApi.groups.list, { document_uri: 'https://asite.com' }); assert.calledWith(fakeApi.groups.list, { document_uri: 'https://asite.com' });
...@@ -150,7 +150,7 @@ describe('groups', function() { ...@@ -150,7 +150,7 @@ describe('groups', function() {
}); });
it('does not wait for the document URL', () => { it('does not wait for the document URL', () => {
fakeAnnotationUI.setState({ searchUris: [] }); fakeStore.setState({ searchUris: [] });
var svc = service(); var svc = service();
return svc.load().then(() => { return svc.load().then(() => {
assert.calledWith(fakeApi.groups.list, {}); assert.calledWith(fakeApi.groups.list, {});
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
var proxyquire = require('proxyquire'); var proxyquire = require('proxyquire');
/** Return a fake store object. */ /** Return a fake store object. */
function fakeAnnotationUI() { function fakeStore() {
var links = null; var links = null;
return { return {
updateLinks: function(newLinks) { updateLinks: function(newLinks) {
...@@ -24,7 +24,7 @@ function createServiceUrl(linksPromise) { ...@@ -24,7 +24,7 @@ function createServiceUrl(linksPromise) {
'../util/url-util': { replaceURLParams: replaceURLParams }, '../util/url-util': { replaceURLParams: replaceURLParams },
}); });
var store = fakeAnnotationUI(); var store = fakeStore();
var apiRoutes = { var apiRoutes = {
links: sinon.stub().returns(linksPromise), links: sinon.stub().returns(linksPromise),
......
...@@ -32,7 +32,7 @@ describe('sidebar.session', function () { ...@@ -32,7 +32,7 @@ describe('sidebar.session', function () {
track: sinon.stub(), track: sinon.stub(),
events: require('../analytics')().events, events: require('../analytics')().events,
}; };
var fakeAnnotationUI = { var fakeStore = {
getState: function () { getState: function () {
return {session: state}; return {session: state};
}, },
...@@ -60,7 +60,7 @@ describe('sidebar.session', function () { ...@@ -60,7 +60,7 @@ describe('sidebar.session', function () {
mock.module('h', { mock.module('h', {
analytics: fakeAnalytics, analytics: fakeAnalytics,
store: fakeAnnotationUI, store: fakeStore,
api: fakeApi, api: fakeApi,
auth: fakeAuth, auth: fakeAuth,
flash: fakeFlash, flash: fakeFlash,
......
...@@ -67,7 +67,7 @@ inherits(FakeSocket, EventEmitter); ...@@ -67,7 +67,7 @@ inherits(FakeSocket, EventEmitter);
describe('Streamer', function () { describe('Streamer', function () {
var fakeAnnotationMapper; var fakeAnnotationMapper;
var fakeAnnotationUI; var fakeStore;
var fakeAuth; var fakeAuth;
var fakeGroups; var fakeGroups;
var fakeRootScope; var fakeRootScope;
...@@ -80,7 +80,7 @@ describe('Streamer', function () { ...@@ -80,7 +80,7 @@ describe('Streamer', function () {
activeStreamer = new Streamer( activeStreamer = new Streamer(
fakeRootScope, fakeRootScope,
fakeAnnotationMapper, fakeAnnotationMapper,
fakeAnnotationUI, fakeStore,
fakeAuth, fakeAuth,
fakeGroups, fakeGroups,
fakeSession, fakeSession,
...@@ -112,7 +112,7 @@ describe('Streamer', function () { ...@@ -112,7 +112,7 @@ describe('Streamer', function () {
unloadAnnotations: sinon.stub(), unloadAnnotations: sinon.stub(),
}; };
fakeAnnotationUI = { fakeStore = {
annotationExists: sinon.stub().returns(false), annotationExists: sinon.stub().returns(false),
isSidebar: sinon.stub().returns(true), isSidebar: sinon.stub().returns(true),
getState: sinon.stub().returns({ getState: sinon.stub().returns({
...@@ -254,7 +254,7 @@ describe('Streamer', function () { ...@@ -254,7 +254,7 @@ describe('Streamer', function () {
context('when the app is the stream', function () { context('when the app is the stream', function () {
beforeEach(function () { beforeEach(function () {
fakeAnnotationUI.isSidebar.returns(false); fakeStore.isSidebar.returns(false);
}); });
it('does not defer updates', function () { it('does not defer updates', function () {
...@@ -288,7 +288,7 @@ describe('Streamer', function () { ...@@ -288,7 +288,7 @@ describe('Streamer', function () {
it('saves pending deletions if the annotation is loaded', function () { it('saves pending deletions if the annotation is loaded', function () {
var id = fixtures.deleteNotification.payload[0].id; var id = fixtures.deleteNotification.payload[0].id;
fakeAnnotationUI.annotationExists.returns(true); fakeStore.annotationExists.returns(true);
fakeWebSocket.notify(fixtures.deleteNotification); fakeWebSocket.notify(fixtures.deleteNotification);
...@@ -298,7 +298,7 @@ describe('Streamer', function () { ...@@ -298,7 +298,7 @@ describe('Streamer', function () {
it('discards pending deletions if the annotation is not loaded', function () { it('discards pending deletions if the annotation is not loaded', function () {
var id = fixtures.deleteNotification.payload[0].id; var id = fixtures.deleteNotification.payload[0].id;
fakeAnnotationUI.annotationExists.returns(false); fakeStore.annotationExists.returns(false);
fakeWebSocket.notify(fixtures.deleteNotification); fakeWebSocket.notify(fixtures.deleteNotification);
...@@ -312,7 +312,7 @@ describe('Streamer', function () { ...@@ -312,7 +312,7 @@ describe('Streamer', function () {
}); });
it('discards pending updates if an unloaded annotation is deleted', function () { it('discards pending updates if an unloaded annotation is deleted', function () {
fakeAnnotationUI.annotationExists.returns(false); fakeStore.annotationExists.returns(false);
fakeWebSocket.notify(fixtures.createNotification); fakeWebSocket.notify(fixtures.createNotification);
fakeWebSocket.notify(fixtures.deleteNotification); fakeWebSocket.notify(fixtures.deleteNotification);
...@@ -346,7 +346,7 @@ describe('Streamer', function () { ...@@ -346,7 +346,7 @@ describe('Streamer', function () {
}); });
it('applies pending deletions', function () { it('applies pending deletions', function () {
fakeAnnotationUI.annotationExists.returns(true); fakeStore.annotationExists.returns(true);
fakeWebSocket.notify(fixtures.deleteNotification); fakeWebSocket.notify(fixtures.deleteNotification);
activeStreamer.applyPendingUpdates(); activeStreamer.applyPendingUpdates();
...@@ -382,7 +382,7 @@ describe('Streamer', function () { ...@@ -382,7 +382,7 @@ describe('Streamer', function () {
}, changeEvents); }, changeEvents);
unroll('discards pending deletions when #event occurs', function (testCase) { unroll('discards pending deletions when #event occurs', function (testCase) {
fakeAnnotationUI.annotationExists.returns(true); fakeStore.annotationExists.returns(true);
fakeWebSocket.notify(fixtures.deleteNotification); fakeWebSocket.notify(fixtures.deleteNotification);
fakeRootScope.$broadcast(testCase.event, {id: 'an-id'}); fakeRootScope.$broadcast(testCase.event, {id: 'an-id'});
...@@ -432,7 +432,7 @@ describe('Streamer', function () { ...@@ -432,7 +432,7 @@ describe('Streamer', function () {
}); });
unroll('does nothing if the userid matches the logged-in userid', function (testCase) { unroll('does nothing if the userid matches the logged-in userid', function (testCase) {
fakeAnnotationUI.getState.returns({ fakeStore.getState.returns({
session: { session: {
userid: testCase.userid, userid: testCase.userid,
}, },
...@@ -454,7 +454,7 @@ describe('Streamer', function () { ...@@ -454,7 +454,7 @@ describe('Streamer', function () {
}]); }]);
unroll('logs a warning if the userid does not match the logged-in userid', function (testCase) { unroll('logs a warning if the userid does not match the logged-in userid', function (testCase) {
fakeAnnotationUI.getState.returns({ fakeStore.getState.returns({
session: { session: {
userid: testCase.userid, userid: testCase.userid,
}, },
......
...@@ -5,13 +5,13 @@ var crossOriginRPC = require('../cross-origin-rpc'); ...@@ -5,13 +5,13 @@ var crossOriginRPC = require('../cross-origin-rpc');
describe('crossOriginRPC', function() { describe('crossOriginRPC', function() {
describe('server', function() { describe('server', function() {
let addedListener; // The postMessage() listener that the server adds. let addedListener; // The postMessage() listener that the server adds.
let fakeAnnotationUI; let fakeStore;
let fakeWindow; let fakeWindow;
let settings; let settings;
let source; let source;
beforeEach(function() { beforeEach(function() {
fakeAnnotationUI = { fakeStore = {
searchUris: sinon.stub().returns('THE_SEARCH_URIS'), searchUris: sinon.stub().returns('THE_SEARCH_URIS'),
}; };
...@@ -40,14 +40,14 @@ describe('crossOriginRPC', function() { ...@@ -40,14 +40,14 @@ describe('crossOriginRPC', function() {
} }
it('adds a postMessage() event listener function', function() { it('adds a postMessage() event listener function', function() {
crossOriginRPC.server.start(fakeAnnotationUI, {}, fakeWindow); crossOriginRPC.server.start(fakeStore, {}, fakeWindow);
assert.isTrue(fakeWindow.addEventListener.calledOnce); assert.isTrue(fakeWindow.addEventListener.calledOnce);
assert.isTrue(fakeWindow.addEventListener.calledWith('message')); assert.isTrue(fakeWindow.addEventListener.calledWith('message'));
}); });
it('sends a response with the result from the called method', function() { it('sends a response with the result from the called method', function() {
crossOriginRPC.server.start(fakeAnnotationUI, settings, fakeWindow); crossOriginRPC.server.start(fakeStore, settings, fakeWindow);
postMessage({ postMessage({
data: { method: 'searchUris', id: 42 }, data: { method: 'searchUris', id: 42 },
...@@ -72,7 +72,7 @@ describe('crossOriginRPC', function() { ...@@ -72,7 +72,7 @@ describe('crossOriginRPC', function() {
{ rpcAllowedOrigins: ['https://allowed1.com', 'https://allowed2.com'] }, { rpcAllowedOrigins: ['https://allowed1.com', 'https://allowed2.com'] },
].forEach(function(settings) { ].forEach(function(settings) {
it("doesn't respond if the origin isn't allowed", function() { it("doesn't respond if the origin isn't allowed", function() {
crossOriginRPC.server.start(fakeAnnotationUI, settings, fakeWindow); crossOriginRPC.server.start(fakeStore, settings, fakeWindow);
postMessage({ postMessage({
origin: 'https://notallowed.com', origin: 'https://notallowed.com',
...@@ -85,7 +85,7 @@ describe('crossOriginRPC', function() { ...@@ -85,7 +85,7 @@ describe('crossOriginRPC', function() {
}); });
it("responds with an error if there's no method", function() { it("responds with an error if there's no method", function() {
crossOriginRPC.server.start(fakeAnnotationUI, settings, fakeWindow); crossOriginRPC.server.start(fakeStore, settings, fakeWindow);
let jsonRpcRequest = { id: 42 }; // No "method" member. let jsonRpcRequest = { id: 42 }; // No "method" member.
postMessage({ postMessage({
...@@ -113,7 +113,7 @@ describe('crossOriginRPC', function() { ...@@ -113,7 +113,7 @@ describe('crossOriginRPC', function() {
null, null,
].forEach(function(method) { ].forEach(function(method) {
it('responds with an error if the method is unknown', function() { it('responds with an error if the method is unknown', function() {
crossOriginRPC.server.start(fakeAnnotationUI, settings, fakeWindow); crossOriginRPC.server.start(fakeStore, settings, fakeWindow);
postMessage({ postMessage({
origin: 'https://allowed1.com', origin: 'https://allowed1.com',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment