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