1
+ import { expect } from 'chai' ;
2
+ import { defaultPreferencesInstance } from 'compass-preferences-model' ;
3
+ import sinon from 'sinon' ;
4
+
1
5
import reducer , {
2
6
toggleInputDocumentsCollapsed ,
3
7
updateInputDocuments ,
4
8
loadingInputDocuments ,
9
+ refreshInputDocuments ,
5
10
ActionTypes ,
6
11
} from './input-documents' ;
7
- import { expect } from 'chai' ;
12
+ import type { RootState } from '.' ;
13
+ import type { DataService } from './data-service' ;
8
14
9
15
describe ( 'input documents module' , function ( ) {
16
+ afterEach ( function ( ) {
17
+ sinon . restore ( ) ;
18
+ } ) ;
19
+
10
20
describe ( '#toggleInputDocumentsCollapsed' , function ( ) {
11
21
it ( 'returns the ActionTypes.CollapseToggled action' , function ( ) {
12
22
expect ( toggleInputDocumentsCollapsed ( ) ) . to . deep . equal ( {
@@ -33,6 +43,53 @@ describe('input documents module', function () {
33
43
} ) ;
34
44
} ) ;
35
45
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
+
36
93
describe ( '#reducer' , function ( ) {
37
94
context (
38
95
'when the action is not toggle input documents collapsed' ,
0 commit comments