@@ -14,11 +14,16 @@ import {
14
14
SCHEDULE_COLLECTION_JOB_MUTATION ,
15
15
EXISTING_TEST_PLAN_REPORTS
16
16
} from './queries' ;
17
+ import { TEST_QUEUE_PAGE_QUERY } from '../TestQueue2/queries' ;
18
+ import { TEST_PLAN_REPORT_STATUS_DIALOG_QUERY } from '../TestPlanReportStatusDialog/queries' ;
19
+ import { ME_QUERY } from '../App/queries' ;
17
20
18
21
function AddTestToQueueWithConfirmation ( {
19
22
testPlanVersion,
20
23
browser,
21
24
at,
25
+ exactAtVersion,
26
+ minimumAtVersion,
22
27
disabled = false ,
23
28
buttonText = 'Add to Test Queue' ,
24
29
triggerUpdate = ( ) => { }
@@ -27,8 +32,27 @@ function AddTestToQueueWithConfirmation({
27
32
useState ( false ) ;
28
33
const [ showConfirmation , setShowConfirmation ] = useState ( false ) ;
29
34
const [ canUseOldResults , setCanUseOldResults ] = useState ( false ) ;
30
- const [ addTestPlanReport ] = useMutation ( ADD_TEST_QUEUE_MUTATION ) ;
31
- const [ scheduleCollection ] = useMutation ( SCHEDULE_COLLECTION_JOB_MUTATION ) ;
35
+
36
+ const [ addTestPlanReport ] = useMutation ( ADD_TEST_QUEUE_MUTATION , {
37
+ refetchQueries : [
38
+ ME_QUERY ,
39
+ EXISTING_TEST_PLAN_REPORTS ,
40
+ TEST_QUEUE_PAGE_QUERY ,
41
+ TEST_PLAN_REPORT_STATUS_DIALOG_QUERY
42
+ ] ,
43
+ awaitRefetchQueries : true
44
+ } ) ;
45
+
46
+ const [ scheduleCollection ] = useMutation ( SCHEDULE_COLLECTION_JOB_MUTATION , {
47
+ refetchQueries : [
48
+ ME_QUERY ,
49
+ EXISTING_TEST_PLAN_REPORTS ,
50
+ TEST_QUEUE_PAGE_QUERY ,
51
+ TEST_PLAN_REPORT_STATUS_DIALOG_QUERY
52
+ ] ,
53
+ awaitRefetchQueries : true
54
+ } ) ;
55
+
32
56
const { data : existingTestPlanReportsData } = useQuery (
33
57
EXISTING_TEST_PLAN_REPORTS ,
34
58
{
@@ -44,28 +68,26 @@ function AddTestToQueueWithConfirmation({
44
68
const existingTestPlanReports =
45
69
existingTestPlanReportsData ?. existingTestPlanVersion ?. testPlanReports ;
46
70
47
- const conflictingReportExists = existingTestPlanReports ?. some ( report => {
48
- return (
49
- report . at . id === at ?. id &&
50
- report . browser . id === browser ?. id &&
51
- report . isFinal
52
- ) ;
53
- } ) ;
54
-
55
71
let latestOldVersion ;
56
72
let oldReportToCopyResultsFrom ;
57
73
58
- // Prioritize a conflicting report for the current version, otherwise
59
- // check if any results data available from a previous result
60
- if (
61
- ! conflictingReportExists &&
62
- existingTestPlanReportsData ?. oldTestPlanVersions ?. length
63
- ) {
64
- latestOldVersion =
65
- existingTestPlanReportsData ?. oldTestPlanVersions ?. reduce ( ( a , b ) =>
66
- new Date ( a . updatedAt ) > new Date ( b . updatedAt ) ? a : b
67
- ) ;
74
+ // Check if any results data available from a previous result using the
75
+ // same testFormatVersion
76
+ const oldTestPlanVersions =
77
+ existingTestPlanReportsData ?. oldTestPlanVersions ?. filter (
78
+ ( { metadata } ) => {
79
+ return (
80
+ metadata . testFormatVersion ===
81
+ existingTestPlanReportsData ?. existingTestPlanVersion
82
+ ?. metadata . testFormatVersion
83
+ ) ;
84
+ }
85
+ ) || [ ] ;
68
86
87
+ if ( oldTestPlanVersions ?. length ) {
88
+ latestOldVersion = oldTestPlanVersions ?. reduce ( ( a , b ) =>
89
+ new Date ( a . updatedAt ) > new Date ( b . updatedAt ) ? a : b
90
+ ) ;
69
91
if (
70
92
new Date ( latestOldVersion ?. updatedAt ) <
71
93
new Date ( testPlanVersion ?. updatedAt )
@@ -132,32 +154,40 @@ function AddTestToQueueWithConfirmation({
132
154
actions . push ( {
133
155
label : 'Add and run later' ,
134
156
onClick : async ( ) => {
135
- await addTestToQueue (
136
- canUseOldResults
137
- ? {
138
- copyResultsFromTestPlanReportId :
139
- latestOldVersion . id
140
- }
141
- : { }
142
- ) ;
143
- await closeWithUpdate ( ) ;
144
- }
145
- } ) ;
146
-
147
- if ( ! alreadyHasBotInTestPlanReport ) {
148
- actions . push ( {
149
- label : 'Add and run with bot' ,
150
- onClick : async ( ) => {
151
- const testPlanReport = await addTestToQueue (
157
+ try {
158
+ await addTestToQueue (
152
159
canUseOldResults
153
160
? {
154
- copyResultsFromTestPlanReportId :
161
+ copyResultsFromTestPlanVersionId :
155
162
latestOldVersion . id
156
163
}
157
164
: { }
158
165
) ;
159
- await scheduleCollectionJob ( testPlanReport ) ;
160
166
await closeWithUpdate ( ) ;
167
+ } catch ( e ) {
168
+ console . error ( e ) ;
169
+ }
170
+ }
171
+ } ) ;
172
+
173
+ if ( ! alreadyHasBotInTestPlanReport ) {
174
+ actions . push ( {
175
+ label : 'Add and run with bot' ,
176
+ onClick : async ( ) => {
177
+ try {
178
+ const testPlanReport = await addTestToQueue (
179
+ canUseOldResults
180
+ ? {
181
+ copyResultsFromTestPlanVersionId :
182
+ latestOldVersion . id
183
+ }
184
+ : { }
185
+ ) ;
186
+ await scheduleCollectionJob ( testPlanReport ) ;
187
+ await closeWithUpdate ( ) ;
188
+ } catch ( e ) {
189
+ console . error ( e ) ;
190
+ }
161
191
}
162
192
} ) ;
163
193
}
@@ -184,76 +214,47 @@ function AddTestToQueueWithConfirmation({
184
214
} ;
185
215
186
216
const renderPreserveReportDataDialog = ( ) => {
187
- let title ;
188
- let content ;
189
- let actions = [ ] ;
190
-
191
- if ( oldReportToCopyResultsFrom ) {
192
- title = 'Older Results Data Found' ;
193
- content =
194
- 'Older results with the same AT, browser and test plan ' +
195
- 'were found for the report being created. Would you like ' +
196
- 'to copy the older results into the report or create a ' +
197
- 'completely new report?' ;
198
- actions = [
199
- {
200
- label : 'Create empty report' ,
201
- onClick : async ( ) => {
202
- setShowPreserveReportDataMessage ( false ) ;
203
- if ( hasAutomationSupport ) {
204
- setShowConfirmation ( true ) ;
205
- } else {
206
- await addTestToQueue ( ) ;
207
- }
208
- }
209
- } ,
210
- {
211
- label : 'Copy older results' ,
212
- onClick : async ( ) => {
213
- setShowPreserveReportDataMessage ( false ) ;
214
- setCanUseOldResults ( true ) ;
215
-
216
- if ( hasAutomationSupport ) {
217
- setShowConfirmation ( true ) ;
218
- } else {
219
- await addTestToQueue ( {
220
- copyResultsFromTestPlanReportId :
221
- latestOldVersion . id
222
- } ) ;
223
- }
224
- }
225
- }
226
- ] ;
227
- } else {
228
- title = 'Conflicting Report Found' ;
229
- content =
230
- 'The report could not be created because an existing ' +
231
- 'report was found on the reports page with the same AT, ' +
232
- 'browser and test plan version. Would you like to return ' +
233
- 'the existing report back to the test queue?' ;
234
- actions = [
235
- {
236
- label : 'Proceed' ,
237
- onClick : async ( ) => {
238
- setShowPreserveReportDataMessage ( false ) ;
239
- if ( hasAutomationSupport ) {
240
- setShowConfirmation ( true ) ;
241
- } else {
242
- await addTestToQueue ( ) ;
243
- }
244
- }
245
- }
246
- ] ;
247
- }
248
-
249
217
return (
250
218
< BasicModal
251
219
show = { showPreserveReportDataMessage }
252
- title = { title }
253
- content = { content }
220
+ title = "Older Results Data Found"
221
+ content = {
222
+ 'Older results with the same AT, browser and test plan ' +
223
+ 'were found for the report being created. Would you like ' +
224
+ 'to copy the older results into the report or create a ' +
225
+ 'completely new report?'
226
+ }
254
227
closeLabel = "Cancel"
255
228
staticBackdrop = { true }
256
- actions = { actions }
229
+ actions = { [
230
+ {
231
+ label : 'Create empty report' ,
232
+ onClick : async ( ) => {
233
+ setShowPreserveReportDataMessage ( false ) ;
234
+ if ( hasAutomationSupport ) {
235
+ setShowConfirmation ( true ) ;
236
+ } else {
237
+ await addTestToQueue ( ) ;
238
+ }
239
+ }
240
+ } ,
241
+ {
242
+ label : 'Copy older results' ,
243
+ onClick : async ( ) => {
244
+ setShowPreserveReportDataMessage ( false ) ;
245
+ setCanUseOldResults ( true ) ;
246
+
247
+ if ( hasAutomationSupport ) {
248
+ setShowConfirmation ( true ) ;
249
+ } else {
250
+ await addTestToQueue ( {
251
+ copyResultsFromTestPlanVersionId :
252
+ latestOldVersion . id
253
+ } ) ;
254
+ }
255
+ }
256
+ }
257
+ ] }
257
258
useOnHide
258
259
handleClose = { async ( ) => {
259
260
setShowPreserveReportDataMessage ( false ) ;
@@ -262,20 +263,23 @@ function AddTestToQueueWithConfirmation({
262
263
) ;
263
264
} ;
264
265
265
- const addTestToQueue = async ( { copyResultsFromTestPlanReportId } = { } ) => {
266
+ const addTestToQueue = async ( {
267
+ copyResultsFromTestPlanVersionId
268
+ } = { } ) => {
266
269
let tpr ;
267
270
await triggerLoad ( async ( ) => {
268
271
const res = await addTestPlanReport ( {
269
272
variables : {
270
273
testPlanVersionId : testPlanVersion . id ,
271
274
atId : at . id ,
275
+ minimumAtVersionId : minimumAtVersion ?. id ,
276
+ exactAtVersionId : exactAtVersion ?. id ,
272
277
browserId : browser . id ,
273
- copyResultsFromTestPlanReportId
278
+ copyResultsFromTestPlanVersionId
274
279
}
275
280
} ) ;
276
281
const testPlanReport =
277
- res ?. data ?. findOrCreateTestPlanReport ?. populatedData
278
- ?. testPlanReport ?? null ;
282
+ res ?. data ?. createTestPlanReport ?. testPlanReport ?? null ;
279
283
tpr = testPlanReport ;
280
284
} , 'Adding Test Plan to Test Queue' ) ;
281
285
setShowConfirmation ( true ) ;
@@ -300,7 +304,7 @@ function AddTestToQueueWithConfirmation({
300
304
disabled = { disabled }
301
305
variant = "secondary"
302
306
onClick = { async ( ) => {
303
- if ( conflictingReportExists || oldReportToCopyResultsFrom ) {
307
+ if ( oldReportToCopyResultsFrom ) {
304
308
setShowPreserveReportDataMessage ( true ) ;
305
309
} else {
306
310
if ( hasAutomationSupport ) {
@@ -333,6 +337,8 @@ AddTestToQueueWithConfirmation.propTypes = {
333
337
key : PropTypes . string . isRequired ,
334
338
name : PropTypes . string . isRequired
335
339
} ) ,
340
+ exactAtVersion : PropTypes . object ,
341
+ minimumAtVersion : PropTypes . object ,
336
342
buttonRef : PropTypes . object ,
337
343
onFocus : PropTypes . func ,
338
344
onBlur : PropTypes . func ,
0 commit comments