Commit fc9f0266 authored by Nick Stenning's avatar Nick Stenning

Merge pull request #2978 from hypothesis/reply-should-not-reset-search-on-stream

Do not clear selection and reset search when creating a reply
parents bfd9c7e5 b9027a0b
...@@ -125,12 +125,6 @@ module.exports = class AppController ...@@ -125,12 +125,6 @@ module.exports = class AppController
$scope.search.query = '' $scope.search.query = ''
annotationUI.clearSelectedAnnotations() annotationUI.clearSelectedAnnotations()
$rootScope.$on('beforeAnnotationCreated', (event, data) ->
if data.$highlight
return
$scope.clearSelection()
)
$scope.search = $scope.search =
query: $location.search()['q'] query: $location.search()['q']
......
...@@ -168,30 +168,6 @@ describe 'AppController', -> ...@@ -168,30 +168,6 @@ describe 'AppController', ->
$scope.$broadcast(events.USER_CHANGED, {initialLoad: false}) $scope.$broadcast(events.USER_CHANGED, {initialLoad: false})
assert.calledOnce(fakeRoute.reload) assert.calledOnce(fakeRoute.reload)
describe 'on "beforeAnnotationCreated"', ->
###*
# It should clear any selection that exists in the sidebar before
# creating a new annotation. Otherwise the new annotation with its
# form open for the user to type in won't be visible because it's
# not part of the selection.
###
it 'calls $scope.clearSelection()', ->
createController()
sandbox.spy($scope, 'clearSelection')
$rootScope.$emit('beforeAnnotationCreated', {})
assert.called($scope.clearSelection)
it 'doesn\'t call $scope.clearSelection() when a highlight is created', ->
createController()
sandbox.spy($scope, 'clearSelection')
$rootScope.$emit('beforeAnnotationCreated', {$highlight: true})
assert.notCalled($scope.clearSelection)
describe 'logout()', -> describe 'logout()', ->
it 'prompts the user if there are drafts', -> it 'prompts the user if there are drafts', ->
fakeDrafts.count.returns(1) fakeDrafts.count.returns(1)
......
...@@ -4,6 +4,7 @@ events = require('../events') ...@@ -4,6 +4,7 @@ events = require('../events')
describe 'WidgetController', -> describe 'WidgetController', ->
$scope = null $scope = null
$rootScope = null
fakeAnnotationMapper = null fakeAnnotationMapper = null
fakeAnnotationUI = null fakeAnnotationUI = null
fakeAuth = null fakeAuth = null
...@@ -84,7 +85,8 @@ describe 'WidgetController', -> ...@@ -84,7 +85,8 @@ describe 'WidgetController', ->
$provide.value 'groups', fakeGroups $provide.value 'groups', fakeGroups
return return
beforeEach inject ($controller, $rootScope) -> beforeEach inject ($controller, _$rootScope_) ->
$rootScope = _$rootScope_
$scope = $rootScope.$new() $scope = $rootScope.$new()
viewer = $controller 'WidgetController', {$scope} viewer = $controller 'WidgetController', {$scope}
...@@ -143,3 +145,27 @@ describe 'WidgetController', -> ...@@ -143,3 +145,27 @@ describe 'WidgetController', ->
assert.calledWith(fakeAnnotationMapper.loadAnnotations, assert.calledWith(fakeAnnotationMapper.loadAnnotations,
searchResult.rows) searchResult.rows)
assert.calledWith(fakeThreading.thread, fakeDrafts.unsaved()) assert.calledWith(fakeThreading.thread, fakeDrafts.unsaved())
describe 'when a new annotation is created', ->
###*
# It should clear any selection that exists in the sidebar before
# creating a new annotation. Otherwise the new annotation with its
# form open for the user to type in won't be visible because it's
# not part of the selection.
###
it 'clears the selection', ->
$scope.clearSelection = sinon.stub()
$rootScope.$emit('beforeAnnotationCreated', {})
assert.called($scope.clearSelection)
it 'does not clear the selection if the new annotation is a highlight', ->
$scope.clearSelection = sinon.stub()
$rootScope.$emit('beforeAnnotationCreated', {$highlight: true})
assert.notCalled($scope.clearSelection)
it 'does not clear the selection if the new annotation is a reply', ->
$scope.clearSelection = sinon.stub()
$rootScope.$emit('beforeAnnotationCreated', {
references: ['parent-id']
})
assert.notCalled($scope.clearSelection)
...@@ -4,12 +4,12 @@ events = require('./events') ...@@ -4,12 +4,12 @@ events = require('./events')
module.exports = class WidgetController module.exports = class WidgetController
this.$inject = [ this.$inject = [
'$scope', 'annotationUI', 'crossframe', 'annotationMapper', 'drafts', 'groups', '$scope', '$rootScope', 'annotationUI', 'crossframe', 'annotationMapper',
'streamer', 'streamFilter', 'store', 'threading' 'drafts', 'groups', 'streamer', 'streamFilter', 'store', 'threading'
] ]
constructor: ( constructor: (
$scope, annotationUI, crossframe, annotationMapper, drafts, groups, $scope, $rootScope, annotationUI, crossframe, annotationMapper,
streamer, streamFilter, store, threading drafts, groups, streamer, streamFilter, store, threading
) -> ) ->
$scope.threadRoot = threading.root $scope.threadRoot = threading.root
$scope.sortOptions = ['Newest', 'Oldest', 'Location'] $scope.sortOptions = ['Newest', 'Oldest', 'Location']
...@@ -72,3 +72,9 @@ module.exports = class WidgetController ...@@ -72,3 +72,9 @@ module.exports = class WidgetController
$scope.hasFocus = (annotation) -> $scope.hasFocus = (annotation) ->
!!($scope.focusedAnnotations ? {})[annotation?.$$tag] !!($scope.focusedAnnotations ? {})[annotation?.$$tag]
$rootScope.$on('beforeAnnotationCreated', (event, data) ->
if data.$highlight || (data.references && data.references.length > 0)
return
$scope.clearSelection()
)
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