Skip to content

Commit a2b8253

Browse files
authored
Merge pull request #1133 from w3c/development
Includes the following changes: * #1123, addresses #791 and #792 with: * #1055 * #1001 * #1065 * #1052 * #1087 * #1098 * #1092 * #1131 * #1124 * #1128, addresses #1100 * #1102, addresses #957 * #1132
2 parents b720653 + af8f492 commit a2b8253

File tree

102 files changed

+10266
-4554
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+10266
-4554
lines changed

client/components/AddTestToQueueWithConfirmation/index.jsx

+115-109
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,16 @@ import {
1414
SCHEDULE_COLLECTION_JOB_MUTATION,
1515
EXISTING_TEST_PLAN_REPORTS
1616
} 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';
1720

1821
function AddTestToQueueWithConfirmation({
1922
testPlanVersion,
2023
browser,
2124
at,
25+
exactAtVersion,
26+
minimumAtVersion,
2227
disabled = false,
2328
buttonText = 'Add to Test Queue',
2429
triggerUpdate = () => {}
@@ -27,8 +32,27 @@ function AddTestToQueueWithConfirmation({
2732
useState(false);
2833
const [showConfirmation, setShowConfirmation] = useState(false);
2934
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+
3256
const { data: existingTestPlanReportsData } = useQuery(
3357
EXISTING_TEST_PLAN_REPORTS,
3458
{
@@ -44,28 +68,26 @@ function AddTestToQueueWithConfirmation({
4468
const existingTestPlanReports =
4569
existingTestPlanReportsData?.existingTestPlanVersion?.testPlanReports;
4670

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-
5571
let latestOldVersion;
5672
let oldReportToCopyResultsFrom;
5773

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+
) || [];
6886

87+
if (oldTestPlanVersions?.length) {
88+
latestOldVersion = oldTestPlanVersions?.reduce((a, b) =>
89+
new Date(a.updatedAt) > new Date(b.updatedAt) ? a : b
90+
);
6991
if (
7092
new Date(latestOldVersion?.updatedAt) <
7193
new Date(testPlanVersion?.updatedAt)
@@ -132,32 +154,40 @@ function AddTestToQueueWithConfirmation({
132154
actions.push({
133155
label: 'Add and run later',
134156
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(
152159
canUseOldResults
153160
? {
154-
copyResultsFromTestPlanReportId:
161+
copyResultsFromTestPlanVersionId:
155162
latestOldVersion.id
156163
}
157164
: {}
158165
);
159-
await scheduleCollectionJob(testPlanReport);
160166
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+
}
161191
}
162192
});
163193
}
@@ -184,76 +214,47 @@ function AddTestToQueueWithConfirmation({
184214
};
185215

186216
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-
249217
return (
250218
<BasicModal
251219
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+
}
254227
closeLabel="Cancel"
255228
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+
]}
257258
useOnHide
258259
handleClose={async () => {
259260
setShowPreserveReportDataMessage(false);
@@ -262,20 +263,23 @@ function AddTestToQueueWithConfirmation({
262263
);
263264
};
264265

265-
const addTestToQueue = async ({ copyResultsFromTestPlanReportId } = {}) => {
266+
const addTestToQueue = async ({
267+
copyResultsFromTestPlanVersionId
268+
} = {}) => {
266269
let tpr;
267270
await triggerLoad(async () => {
268271
const res = await addTestPlanReport({
269272
variables: {
270273
testPlanVersionId: testPlanVersion.id,
271274
atId: at.id,
275+
minimumAtVersionId: minimumAtVersion?.id,
276+
exactAtVersionId: exactAtVersion?.id,
272277
browserId: browser.id,
273-
copyResultsFromTestPlanReportId
278+
copyResultsFromTestPlanVersionId
274279
}
275280
});
276281
const testPlanReport =
277-
res?.data?.findOrCreateTestPlanReport?.populatedData
278-
?.testPlanReport ?? null;
282+
res?.data?.createTestPlanReport?.testPlanReport ?? null;
279283
tpr = testPlanReport;
280284
}, 'Adding Test Plan to Test Queue');
281285
setShowConfirmation(true);
@@ -300,7 +304,7 @@ function AddTestToQueueWithConfirmation({
300304
disabled={disabled}
301305
variant="secondary"
302306
onClick={async () => {
303-
if (conflictingReportExists || oldReportToCopyResultsFrom) {
307+
if (oldReportToCopyResultsFrom) {
304308
setShowPreserveReportDataMessage(true);
305309
} else {
306310
if (hasAutomationSupport) {
@@ -333,6 +337,8 @@ AddTestToQueueWithConfirmation.propTypes = {
333337
key: PropTypes.string.isRequired,
334338
name: PropTypes.string.isRequired
335339
}),
340+
exactAtVersion: PropTypes.object,
341+
minimumAtVersion: PropTypes.object,
336342
buttonRef: PropTypes.object,
337343
onFocus: PropTypes.func,
338344
onBlur: PropTypes.func,

client/components/AddTestToQueueWithConfirmation/queries.js

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export const EXISTING_TEST_PLAN_REPORTS = gql`
3030
id
3131
}
3232
}
33+
metadata
3334
}
3435
oldTestPlanVersions: testPlanVersions(
3536
phases: [CANDIDATE, RECOMMENDED]
@@ -46,6 +47,7 @@ export const EXISTING_TEST_PLAN_REPORTS = gql`
4647
id
4748
}
4849
}
50+
metadata
4951
}
5052
}
5153
`;

0 commit comments

Comments
 (0)