1+ import { expect } from 'chai' ;
2+ import { defaultPreferencesInstance } from 'compass-preferences-model' ;
3+ import sinon from 'sinon' ;
4+
15import reducer , {
26 toggleInputDocumentsCollapsed ,
37 updateInputDocuments ,
48 loadingInputDocuments ,
9+ refreshInputDocuments ,
510 ActionTypes ,
611} from './input-documents' ;
7- import { expect } from 'chai' ;
12+ import type { RootState } from '.' ;
13+ import type { DataService } from './data-service' ;
814
915describe ( 'input documents module' , function ( ) {
16+ afterEach ( function ( ) {
17+ sinon . restore ( ) ;
18+ } ) ;
19+
1020 describe ( '#toggleInputDocumentsCollapsed' , function ( ) {
1121 it ( 'returns the ActionTypes.CollapseToggled action' , function ( ) {
1222 expect ( toggleInputDocumentsCollapsed ( ) ) . to . deep . equal ( {
@@ -33,6 +43,53 @@ describe('input documents module', function () {
3343 } ) ;
3444 } ) ;
3545
46+ describe ( '#refreshInputDocuments' , function ( ) {
47+ it ( 'should apply maxTimeMS to the aggregation when it is set' , async function ( ) {
48+ const refreshInputDocumentsThunk = refreshInputDocuments ( ) ;
49+
50+ const mockAggregate = sinon . stub ( ) . resolves ( [ ] ) ;
51+ const mockState : Partial < RootState > = {
52+ dataService : {
53+ dataService : {
54+ aggregate : mockAggregate ,
55+ } as unknown as DataService ,
56+ } ,
57+ namespace : 'test.namespace' ,
58+ maxTimeMS : undefined ,
59+ settings : {
60+ isExpanded : false ,
61+ isCommentMode : false ,
62+ isDirty : false ,
63+ limit : 10 ,
64+ sampleSize : 10 ,
65+ } ,
66+ } ;
67+
68+ await refreshInputDocumentsThunk (
69+ sinon . stub ( ) ,
70+ ( ) => mockState as RootState ,
71+ { preferences : defaultPreferencesInstance } as any
72+ ) ;
73+
74+ expect ( mockAggregate . calledOnce ) . to . be . true ;
75+ expect ( mockAggregate . firstCall . args [ 2 ] ) . to . deep . equal ( {
76+ maxTimeMS : 60_000 ,
77+ } ) ;
78+
79+ mockState . maxTimeMS = 1000 ;
80+ await refreshInputDocumentsThunk (
81+ sinon . stub ( ) ,
82+ ( ) => mockState as RootState ,
83+ { preferences : defaultPreferencesInstance } as any
84+ ) ;
85+
86+ expect ( mockAggregate . calledTwice ) . to . be . true ;
87+ expect ( mockAggregate . secondCall . args [ 2 ] ) . to . deep . equal ( {
88+ maxTimeMS : 1000 ,
89+ } ) ;
90+ } ) ;
91+ } ) ;
92+
3693 describe ( '#reducer' , function ( ) {
3794 context (
3895 'when the action is not toggle input documents collapsed' ,
0 commit comments