Skip to content

Commit c313993

Browse files
committed
Merge branch 'hotfix/18.1.2'
2 parents 4f0382e + 5b8414f commit c313993

File tree

5 files changed

+92
-5
lines changed

5 files changed

+92
-5
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7+
## [18.1.2] - 2018-11-05
8+
- Engines:
9+
- `registries/discover` - reset to first page on user search input
10+
711
## [18.1.1] - 2018-11-05
812
- Routes:
913
- `guid-node/registrations` - fix sorting of registration schema on new registration modal

lib/registries/addon/components/registries-header/template.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
<div class="row m-t-md m-b-lg text-center">
1313
<div class="col-xs-12 col-sm-8 col-sm-offset-2">
1414
<div class="input-group input-group-lg">
15-
{{input value=value class="form-control" placeholder=(t 'registries.header.search_placeholder')}}
15+
{{input data-test-search-box value=value class="form-control" placeholder=(t 'registries.header.search_placeholder')}}
1616
<span class="input-group-btn">
1717
{{#if showHelp}}
1818
<button class="btn btn-default" type="button" {{action "toggleHelp"}}>{{fa-icon "question" class="text-muted"}}</button>
1919
{{/if}}
20-
<button class="btn btn-default" type="button" {{action "onClick"}}>{{t 'registries.header.search'}}</button>
20+
<button data-test-search-button class="btn btn-default" type="button" {{action "onClick"}}>{{t 'registries.header.search'}}</button>
2121
</span>
2222
</div>
2323
<p class="p-l-md text-left">

lib/registries/addon/discover/controller.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,12 @@ export default class Discover extends Controller.extend(discoverQueryParams.Mixi
214214
this.set('registrationTypes', A([]));
215215
}
216216

217+
// If query has changed but page has not changed reset page to 1.
218+
// The page check stops other tests from breaking
219+
if (this.searchOptions && this.searchOptions.query !== this.query && this.searchOptions.page === this.page) {
220+
this.set('page', 1);
221+
}
222+
217223
let options = new SearchOptions({
218224
query: this.query,
219225
size: this.size,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ember-osf-web",
3-
"version": "18.1.1",
3+
"version": "18.1.2",
44
"description": "Ember front-end for the Open Science Framework",
55
"license": "Apache-2.0",
66
"author": "Center for Open Science <[email protected]>",

tests/engines/registries/integration/discover/discover-test.ts

Lines changed: 79 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import EngineInstance from '@ember/engine/instance';
2-
import { click, getRootElement, visit } from '@ember/test-helpers';
2+
import { click, fillIn, getRootElement, visit } from '@ember/test-helpers';
33
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
44
import Analytics from 'ember-osf-web/services/analytics';
55
import { setupEngineApplicationTest } from 'ember-osf-web/tests/helpers/engines';
66
import { TestContext } from 'ember-test-helpers';
7-
import { OrderedSet } from 'immutable';
7+
import { OrderedSet, ValueObject } from 'immutable';
88
import $ from 'jquery';
99
import { module, test } from 'qunit';
1010
import { SearchOptions, SearchOrder, SearchResults } from 'registries/services/search';
@@ -15,6 +15,10 @@ import ShareSearch, {
1515
} from 'registries/services/share-search';
1616
import sinon from 'sinon';
1717

18+
const equals = (expected: ValueObject) => {
19+
return sinon.match((x: any) => expected.equals(x));
20+
};
21+
1822
const emptyResults: SearchResults<ShareRegistration> = {
1923
total: 0,
2024
results: [],
@@ -525,6 +529,79 @@ module('Registries | Integration | discover', hooks => {
525529
}));
526530
});
527531

532+
test('page resets on typing query', async function(this: TestContext) {
533+
const stub = sinon.stub(this.owner.lookup('service:share-search'), 'registrations').returns({
534+
total: 0,
535+
results: [],
536+
aggregations: {
537+
sources: {
538+
buckets: [{ key: 'OSF', doc_count: 10 }],
539+
},
540+
},
541+
});
542+
543+
await visit('/registries/discover?page=10');
544+
545+
sinon.assert.calledWith(stub, equals(new SearchOptions({
546+
query: '',
547+
page: 10,
548+
order: new SearchOrder({
549+
display: 'registries.discover.order.relevance',
550+
ascending: false,
551+
key: 'date_modified',
552+
}),
553+
})));
554+
555+
await fillIn('[data-test-search-box]', 'Test Query');
556+
557+
sinon.assert.calledWith(stub, equals(new SearchOptions({
558+
query: 'Test Query',
559+
page: 1,
560+
order: new SearchOrder({
561+
display: 'registries.discover.order.relevance',
562+
ascending: true,
563+
key: undefined,
564+
}),
565+
})));
566+
});
567+
568+
test('page resets on clicking search', async function(this: TestContext) {
569+
sinon.stub(this.owner.lookup('service:analytics'), 'click');
570+
const stub = sinon.stub(this.owner.lookup('service:share-search'), 'registrations').returns({
571+
total: 0,
572+
results: [],
573+
aggregations: {
574+
sources: {
575+
buckets: [{ key: 'OSF', doc_count: 10 }],
576+
},
577+
},
578+
});
579+
580+
await visit('/registries/discover?page=10&q=Testing');
581+
582+
sinon.assert.calledWith(stub, equals(new SearchOptions({
583+
query: 'Testing',
584+
page: 10,
585+
order: new SearchOrder({
586+
display: 'registries.discover.order.relevance',
587+
ascending: true,
588+
key: undefined,
589+
}),
590+
})));
591+
592+
await click('[data-test-search-button]');
593+
594+
sinon.assert.calledWith(stub, equals(new SearchOptions({
595+
query: 'Testing',
596+
page: 1,
597+
order: new SearchOrder({
598+
display: 'registries.discover.order.relevance',
599+
ascending: true,
600+
key: undefined,
601+
}),
602+
})));
603+
});
604+
528605
test('scroll top on pagination', async function(this: TestContext, assert: Assert) {
529606
const results = {
530607
total: 21,

0 commit comments

Comments
 (0)