Commit a8a74a25 authored by Randall Leeds's avatar Randall Leeds

Disable page search on /stream

This should speed up the stream and ensure that results coming back
from the server are not filtered out due to a mismatch between the
page search and elasticsearch query treatment.
parent 7a5fca6a
angular = require('angular')
mail = require('./vendor/jwz')
module.exports = class StreamController
this.inject = [
'$scope', '$rootScope', '$routeParams',
'queryParser', 'searchFilter', 'store',
'streamer', 'streamFilter', 'annotationMapper'
'streamer', 'streamFilter', 'threading', 'annotationMapper'
]
constructor: (
$scope, $rootScope, $routeParams
queryParser, searchFilter, store,
streamer, streamFilter, annotationMapper
streamer, streamFilter, threading, annotationMapper
) ->
# XXX: disable page search
$scope.search = {}
# XXX: Reset the threading service
threading.createIdTable([])
$scope.threadRoot = threading.root = mail.messageContainer()
# Initialize the base filter
streamFilter
.resetFilter()
.setMatchPolicyIncludeAll()
# Apply query clauses
$scope.search.query = $routeParams.q
terms = searchFilter.generateFacetedFilter $scope.search.query
terms = searchFilter.generateFacetedFilter $routeParams.q
queryParser.populateFilter streamFilter, terms
streamer.send({filter: streamFilter.getFilter()})
# Perform the search
searchParams = searchFilter.toObject $scope.search.query
searchParams = searchFilter.toObject $routeParams.q
query = angular.extend limit: 20, searchParams
store.SearchResource.get query, ({rows}) ->
annotationMapper.loadAnnotations(rows)
......@@ -35,6 +42,3 @@ module.exports = class StreamController
$scope.sort.name = 'Newest'
$scope.shouldShowThread = (container) -> true
$scope.$on '$destroy', ->
$scope.search.query = ''
{module, inject} = require('angular-mock')
assert = chai.assert
sinon.assert.expose assert, prefix: null
describe 'StreamController', ->
$controller = null
$scope = null
fakeAnnotationMapper = null
fakeParams = null
fakeQueryParser = null
fakeStore = null
fakeStreamer = null
fakeStreamFilter = null
fakeThreading = null
sandbox = null
createController = ->
$controller('StreamController', {$scope: $scope})
before ->
angular.module('h', [])
.controller('StreamController', require('../stream-controller'))
beforeEach module('h')
beforeEach module ($provide) ->
sandbox = sinon.sandbox.create()
fakeAnnotationMapper = {
loadAnnotations: sandbox.spy()
}
fakeParams = {id: 'test'}
fakeQueryParser = {
populateFilter: sandbox.spy()
}
fakeSearchFilter = {
generateFacetedFilter: sandbox.stub()
toObject: sandbox.stub().returns({})
}
fakeStore = {
SearchResource: {
get: sandbox.spy()
}
}
fakeStreamer = {
open: sandbox.spy()
close: sandbox.spy()
send: sandbox.spy()
}
fakeStreamFilter = {
resetFilter: sandbox.stub().returnsThis()
setMatchPolicyIncludeAll: sandbox.stub().returnsThis()
getFilter: sandbox.stub()
}
fakeThreading = {
createIdTable: sandbox.spy()
}
$provide.value 'annotationMapper', fakeAnnotationMapper
$provide.value '$routeParams', fakeParams
$provide.value 'queryParser', fakeQueryParser
$provide.value 'searchFilter', fakeSearchFilter
$provide.value 'store', fakeStore
$provide.value 'streamer', fakeStreamer
$provide.value 'streamFilter', fakeStreamFilter
$provide.value 'threading', fakeThreading
return
beforeEach inject (_$controller_, $rootScope) ->
$controller = _$controller_
$scope = $rootScope.$new()
$scope.sort = {}
afterEach ->
sandbox.restore()
it 'disables page search by shadowing the search field', ->
createController()
assert.match($scope.search, {})
it 'resets the threading service', ->
createController()
assert.calledOnce(fakeThreading.createIdTable)
assert.calledWith(fakeThreading.createIdTable, [])
assert.isObject(fakeThreading.root)
assert.strictEqual(fakeThreading.root, $scope.threadRoot)
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