@@ -7,9 +7,15 @@ describe('QuerySettingsConfig', () => {
7
7
it ( 'should render' , ( ) => {
8
8
const result = render (
9
9
< QuerySettingsConfig
10
- dialTimeout = '10'
11
- queryTimeout = '10'
12
- validateSql
10
+ connMaxLifetime = { '5' }
11
+ dialTimeout = { '5' }
12
+ maxIdleConns = { '5' }
13
+ maxOpenConns = { '5' }
14
+ queryTimeout = { '5' }
15
+ validateSql = { true }
16
+ onConnMaxIdleConnsChange = { ( ) => { } }
17
+ onConnMaxLifetimeChange = { ( ) => { } }
18
+ onConnMaxOpenConnsChange = { ( ) => { } }
13
19
onDialTimeoutChange = { ( ) => { } }
14
20
onQueryTimeoutChange = { ( ) => { } }
15
21
onValidateSqlChange = { ( ) => { } }
@@ -22,6 +28,9 @@ describe('QuerySettingsConfig', () => {
22
28
const onDialTimeout = jest . fn ( ) ;
23
29
const result = render (
24
30
< QuerySettingsConfig
31
+ onConnMaxIdleConnsChange = { ( ) => { } }
32
+ onConnMaxLifetimeChange = { ( ) => { } }
33
+ onConnMaxOpenConnsChange = { ( ) => { } }
25
34
onDialTimeoutChange = { onDialTimeout }
26
35
onQueryTimeoutChange = { ( ) => { } }
27
36
onValidateSqlChange = { ( ) => { } }
@@ -33,14 +42,17 @@ describe('QuerySettingsConfig', () => {
33
42
expect ( input ) . toBeInTheDocument ( ) ;
34
43
fireEvent . change ( input , { target : { value : '10' } } ) ;
35
44
fireEvent . blur ( input ) ;
36
- expect ( onDialTimeout ) . toBeCalledTimes ( 1 ) ;
37
- expect ( onDialTimeout ) . toBeCalledWith ( expect . any ( Object ) ) ;
45
+ expect ( onDialTimeout ) . toHaveBeenCalledTimes ( 1 ) ;
46
+ expect ( onDialTimeout ) . toHaveBeenCalledWith ( expect . any ( Object ) ) ;
38
47
} ) ;
39
48
40
49
it ( 'should call onQueryTimeout when changed' , ( ) => {
41
50
const onQueryTimeout = jest . fn ( ) ;
42
51
const result = render (
43
52
< QuerySettingsConfig
53
+ onConnMaxIdleConnsChange = { ( ) => { } }
54
+ onConnMaxLifetimeChange = { ( ) => { } }
55
+ onConnMaxOpenConnsChange = { ( ) => { } }
44
56
onDialTimeoutChange = { ( ) => { } }
45
57
onQueryTimeoutChange = { onQueryTimeout }
46
58
onValidateSqlChange = { ( ) => { } }
@@ -52,14 +64,17 @@ describe('QuerySettingsConfig', () => {
52
64
expect ( input ) . toBeInTheDocument ( ) ;
53
65
fireEvent . change ( input , { target : { value : '10' } } ) ;
54
66
fireEvent . blur ( input ) ;
55
- expect ( onQueryTimeout ) . toBeCalledTimes ( 1 ) ;
56
- expect ( onQueryTimeout ) . toBeCalledWith ( expect . any ( Object ) ) ;
67
+ expect ( onQueryTimeout ) . toHaveBeenCalledTimes ( 1 ) ;
68
+ expect ( onQueryTimeout ) . toHaveBeenCalledWith ( expect . any ( Object ) ) ;
57
69
} ) ;
58
70
59
71
it ( 'should call onValidateSqlChange when changed' , ( ) => {
60
72
const onValidateSqlChange = jest . fn ( ) ;
61
73
const result = render (
62
74
< QuerySettingsConfig
75
+ onConnMaxIdleConnsChange = { ( ) => { } }
76
+ onConnMaxLifetimeChange = { ( ) => { } }
77
+ onConnMaxOpenConnsChange = { ( ) => { } }
63
78
onDialTimeoutChange = { ( ) => { } }
64
79
onQueryTimeoutChange = { ( ) => { } }
65
80
onValidateSqlChange = { onValidateSqlChange }
@@ -70,7 +85,73 @@ describe('QuerySettingsConfig', () => {
70
85
const input = result . getByRole ( 'checkbox' ) ;
71
86
expect ( input ) . toBeInTheDocument ( ) ;
72
87
fireEvent . click ( input ) ;
73
- expect ( onValidateSqlChange ) . toBeCalledTimes ( 1 ) ;
74
- expect ( onValidateSqlChange ) . toBeCalledWith ( expect . any ( Object ) ) ;
88
+ expect ( onValidateSqlChange ) . toHaveBeenCalledTimes ( 1 ) ;
89
+ expect ( onValidateSqlChange ) . toHaveBeenCalledWith ( expect . any ( Object ) ) ;
90
+ } ) ;
91
+
92
+ it ( 'should call onConnMaxIdleConnsChange when changed' , ( ) => {
93
+ const onConnMaxIdleConnsChange = jest . fn ( ) ;
94
+ const result = render (
95
+ < QuerySettingsConfig
96
+ onConnMaxIdleConnsChange = { onConnMaxIdleConnsChange }
97
+ onConnMaxLifetimeChange = { ( ) => { } }
98
+ onConnMaxOpenConnsChange = { ( ) => { } }
99
+ onDialTimeoutChange = { ( ) => { } }
100
+ onQueryTimeoutChange = { ( ) => { } }
101
+ onValidateSqlChange = { ( ) => { } }
102
+ />
103
+ ) ;
104
+ expect ( result . container . firstChild ) . not . toBeNull ( ) ;
105
+
106
+ const input = result . getByPlaceholderText ( allLabels . components . Config . QuerySettingsConfig . maxIdleConns . placeholder ) ;
107
+ expect ( input ) . toBeInTheDocument ( ) ;
108
+ fireEvent . change ( input , { target : { value : '10' } } ) ;
109
+ fireEvent . blur ( input ) ;
110
+ expect ( onConnMaxIdleConnsChange ) . toHaveBeenCalledTimes ( 1 ) ;
111
+ expect ( onConnMaxIdleConnsChange ) . toHaveBeenCalledWith ( expect . any ( Object ) ) ;
112
+ } ) ;
113
+
114
+ it ( 'should call onConnMaxLifetimeChange when changed' , ( ) => {
115
+ const onConnMaxLifetimeChange = jest . fn ( ) ;
116
+ const result = render (
117
+ < QuerySettingsConfig
118
+ onConnMaxIdleConnsChange = { ( ) => { } }
119
+ onConnMaxLifetimeChange = { onConnMaxLifetimeChange }
120
+ onConnMaxOpenConnsChange = { ( ) => { } }
121
+ onDialTimeoutChange = { ( ) => { } }
122
+ onQueryTimeoutChange = { ( ) => { } }
123
+ onValidateSqlChange = { ( ) => { } }
124
+ />
125
+ ) ;
126
+ expect ( result . container . firstChild ) . not . toBeNull ( ) ;
127
+
128
+ const input = result . getByPlaceholderText ( allLabels . components . Config . QuerySettingsConfig . connMaxLifetime . placeholder ) ;
129
+ expect ( input ) . toBeInTheDocument ( ) ;
130
+ fireEvent . change ( input , { target : { value : '10' } } ) ;
131
+ fireEvent . blur ( input ) ;
132
+ expect ( onConnMaxLifetimeChange ) . toHaveBeenCalledTimes ( 1 ) ;
133
+ expect ( onConnMaxLifetimeChange ) . toHaveBeenCalledWith ( expect . any ( Object ) ) ;
134
+ } ) ;
135
+
136
+ it ( 'should call onConnMaxOpenConnsChange when changed' , ( ) => {
137
+ const onConnMaxOpenConnsChange = jest . fn ( ) ;
138
+ const result = render (
139
+ < QuerySettingsConfig
140
+ onConnMaxIdleConnsChange = { ( ) => { } }
141
+ onConnMaxLifetimeChange = { ( ) => { } }
142
+ onConnMaxOpenConnsChange = { onConnMaxOpenConnsChange }
143
+ onDialTimeoutChange = { ( ) => { } }
144
+ onQueryTimeoutChange = { ( ) => { } }
145
+ onValidateSqlChange = { ( ) => { } }
146
+ />
147
+ ) ;
148
+ expect ( result . container . firstChild ) . not . toBeNull ( ) ;
149
+
150
+ const input = result . getByPlaceholderText ( allLabels . components . Config . QuerySettingsConfig . maxOpenConns . placeholder ) ;
151
+ expect ( input ) . toBeInTheDocument ( ) ;
152
+ fireEvent . change ( input , { target : { value : '10' } } ) ;
153
+ fireEvent . blur ( input ) ;
154
+ expect ( onConnMaxOpenConnsChange ) . toHaveBeenCalledTimes ( 1 ) ;
155
+ expect ( onConnMaxOpenConnsChange ) . toHaveBeenCalledWith ( expect . any ( Object ) ) ;
75
156
} ) ;
76
157
} ) ;
0 commit comments