11import EngineInstance from '@ember/engine/instance' ;
2- import { click , getRootElement , visit } from '@ember/test-helpers' ;
2+ import { click , fillIn , getRootElement , visit } from '@ember/test-helpers' ;
33import setupMirage from 'ember-cli-mirage/test-support/setup-mirage' ;
44import Analytics from 'ember-osf-web/services/analytics' ;
55import { setupEngineApplicationTest } from 'ember-osf-web/tests/helpers/engines' ;
66import { TestContext } from 'ember-test-helpers' ;
7- import { OrderedSet } from 'immutable' ;
7+ import { OrderedSet , ValueObject } from 'immutable' ;
88import $ from 'jquery' ;
99import { module , test } from 'qunit' ;
1010import { SearchOptions , SearchOrder , SearchResults } from 'registries/services/search' ;
@@ -15,6 +15,10 @@ import ShareSearch, {
1515} from 'registries/services/share-search' ;
1616import sinon from 'sinon' ;
1717
18+ const equals = ( expected : ValueObject ) => {
19+ return sinon . match ( ( x : any ) => expected . equals ( x ) ) ;
20+ } ;
21+
1822const 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