Commit 7ee3c828 authored by Robert Knight's avatar Robert Knight

Couple of minor simplifications

 * Avoid a loop over an array with a single entry

 * Avoid an unnecessary variable shared between multiple
   tests
parent a0b4e76b
...@@ -47,12 +47,9 @@ module.exports = class AppController ...@@ -47,12 +47,9 @@ module.exports = class AppController
} }
# Reload the view when the user switches accounts # Reload the view when the user switches accounts
reloadEvents = [events.USER_CHANGED]; $scope.$on(events.USER_CHANGED, (event, data) ->
reloadEvents.forEach((eventName) -> if !data || !data.initialLoad
$scope.$on(eventName, (event, data) -> $route.reload()
if !data || !data.initialLoad
$route.reload()
)
); );
identity.watch({ identity.watch({
......
...@@ -42,8 +42,6 @@ describe 'WidgetController', -> ...@@ -42,8 +42,6 @@ describe 'WidgetController', ->
unsaved: sandbox.stub() unsaved: sandbox.stub()
} }
lastSearchResult = null
fakeStore = { fakeStore = {
SearchResource: SearchResource:
get: (query, callback) -> get: (query, callback) ->
...@@ -52,7 +50,6 @@ describe 'WidgetController', -> ...@@ -52,7 +50,6 @@ describe 'WidgetController', ->
result = result =
total: 100 total: 100
rows: [offset..offset+limit-1] rows: [offset..offset+limit-1]
lastSearchResult = result
callback result callback result
} }
...@@ -112,11 +109,15 @@ describe 'WidgetController', -> ...@@ -112,11 +109,15 @@ describe 'WidgetController', ->
it 'should load annotations for the new group', -> it 'should load annotations for the new group', ->
fakeThreading.annotationList = sandbox.stub().returns([{id: '1'}]) fakeThreading.annotationList = sandbox.stub().returns([{id: '1'}])
fakeCrossFrame.frames.push({uri: 'http://example.com'}) fakeCrossFrame.frames.push({uri: 'http://example.com'})
searchResult = {total: 10, rows: [0..10]}
fakeStore.SearchResource.get = (query, callback) ->
callback(searchResult)
$scope.$broadcast(events.GROUP_FOCUSED) $scope.$broadcast(events.GROUP_FOCUSED)
assert.calledWith(fakeAnnotationMapper.unloadAnnotations, assert.calledWith(fakeAnnotationMapper.unloadAnnotations,
[{id: '1'}]) [{id: '1'}])
$scope.$digest(); $scope.$digest();
assert.calledWith(fakeAnnotationMapper.loadAnnotations, assert.calledWith(fakeAnnotationMapper.loadAnnotations,
lastSearchResult.rows) searchResult.rows)
assert.calledWith(fakeThreading.thread, fakeDrafts.unsaved()) assert.calledWith(fakeThreading.thread, fakeDrafts.unsaved())
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