Skip to content

Commit af5129f

Browse files
committed
Fix broken tests
1 parent 4844e0e commit af5129f

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

src/client/js/controllers/search-ctrl.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ module fng.controllers {
66
export function SearchCtrl($scope, $http, $location, routingService) {
77

88
var lastSearchSent;
9-
109
var _isNotMobile;
1110

1211
_isNotMobile = (function () {
@@ -89,7 +88,7 @@ module fng.controllers {
8988

9089
$scope.$watch('searchTarget', function (newValue) {
9190
if (newValue && newValue.length > 0) {
92-
lastSearchSent = new Date().valueOf();
91+
lastSearchSent = $scope.testTime || new Date().valueOf();
9392
$http.get('/api/search?q=' + newValue + '&sentAt=' + lastSearchSent).then(function (response) {
9493
let data: any = response.data;
9594
// Check that we haven't fired off a subsequent request, in which

test/unit/searchSpec.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ describe('search', function () {
1818
scope = $rootScope;
1919
$compile(elm)(scope);
2020
scope.$digest();
21+
scope.testTime = new Date().valueOf();
2122
}));
2223

2324
describe('form generation', function () {
@@ -38,7 +39,7 @@ describe('search', function () {
3839
describe('results list', function () {
3940

4041
it('displays one result when there is one', function () {
41-
$httpBackend.whenGET('/api/search?q=hello').respond({results: [
42+
$httpBackend.whenGET(`/api/search?q=hello&sentAt=${scope.testTime}`).respond({results: [
4243
{id: '1', resource: 'resource', resourceText: 'Resource', text: 'Hello 1'}
4344
]});
4445
scope.searchTarget = 'hello';
@@ -49,7 +50,7 @@ describe('search', function () {
4950
});
5051

5152
it('displays two results when there are two', function () {
52-
$httpBackend.whenGET('/api/search?q=hello').respond({results: [
53+
$httpBackend.whenGET(`/api/search?q=hello&sentAt=${scope.testTime}`).respond({results: [
5354
{id: '1', resource: 'resource', resourceText: 'Resource', text: 'Hello 1'},
5455
{id: '2', resource: 'resource', resourceText: 'Resource', text: 'Hello 2'}
5556
]});
@@ -63,7 +64,7 @@ describe('search', function () {
6364
});
6465

6566
it('should have an error class in the search box when the string is not found', function () {
66-
$httpBackend.whenGET('/api/search?q=hello').respond({results: []});
67+
$httpBackend.whenGET(`/api/search?q=hello&sentAt=${scope.testTime}`).respond({results: []});
6768
scope.searchTarget = 'hello';
6869
scope.$digest();
6970
$httpBackend.flush();
@@ -77,7 +78,7 @@ describe('search', function () {
7778
});
7879

7980
it('formats results', function () {
80-
$httpBackend.whenGET('/api/search?q=hello').respond({'results': [
81+
$httpBackend.whenGET(`/api/search?q=hello&sentAt=${scope.testTime}`).respond({results: [
8182
{'resource': 'f_nested_schema', 'resourceText': 'Exams', 'id': '51c583d5b5c51226db418f15', 'text': 'Brown, John', 'searchImportance': 99},
8283
{'resource': 'f_nested_schema', 'resourceText': 'Exams', 'id': '51c583d5b5c51226db418f17', 'text': 'Brown, Jenny', 'searchImportance': 99}
8384
], 'moreCount': 0});
@@ -93,7 +94,7 @@ describe('search', function () {
9394
});
9495

9596
it('should focus on the first result returned', function () {
96-
$httpBackend.whenGET('/api/search?q=hello').respond({'results': [
97+
$httpBackend.whenGET(`/api/search?q=hello&sentAt=${scope.testTime}`).respond({results: [
9798
{'resource': 'f_nested_schema', 'resourceText': 'Exams', 'id': '51c583d5b5c51226db418f15', 'text': 'Brown, John', 'searchImportance': 99},
9899
{'resource': 'f_nested_schema', 'resourceText': 'Exams', 'id': '51c583d5b5c51226db418f17', 'text': 'Brown, Jenny', 'searchImportance': 99}
99100
], 'moreCount': 0});
@@ -165,7 +166,7 @@ describe('search', function () {
165166
});
166167

167168
it('should clear the target and the reults when Esc is pressed', function () {
168-
$httpBackend.whenGET('/api/search?q=hello').respond({'results': [
169+
$httpBackend.whenGET(`/api/search?q=hello&sentAt=${scope.testTime}`).respond({results: [
169170
{'resource': 'f_nested_schema', 'resourceText': 'Exams', 'id': '51c583d5b5c51226db418f15', 'text': 'Brown, John', 'searchImportance': 99},
170171
{'resource': 'f_nested_schema', 'resourceText': 'Exams', 'id': '51c583d5b5c51226db418f17', 'text': 'Brown, Jenny', 'searchImportance': 99}
171172
], 'moreCount': 0});
@@ -179,5 +180,4 @@ describe('search', function () {
179180

180181
});
181182

182-
183183
});

0 commit comments

Comments
 (0)