Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minimum and Exact AT Version #1055

Merged
merged 12 commits into from
May 2, 2024
138 changes: 52 additions & 86 deletions client/components/AddTestToQueueWithConfirmation/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ function AddTestToQueueWithConfirmation({
testPlanVersion,
browser,
at,
exactAtVersion,
minimumAtVersion,
disabled = false,
buttonText = 'Add to Test Queue',
triggerUpdate = () => {}
Expand All @@ -44,23 +46,11 @@ function AddTestToQueueWithConfirmation({
const existingTestPlanReports =
existingTestPlanReportsData?.existingTestPlanVersion?.testPlanReports;

const conflictingReportExists = existingTestPlanReports?.some(report => {
return (
report.at.id === at?.id &&
report.browser.id === browser?.id &&
report.isFinal
);
});

let latestOldVersion;
let oldReportToCopyResultsFrom;

// Prioritize a conflicting report for the current version, otherwise
// check if any results data available from a previous result
if (
!conflictingReportExists &&
existingTestPlanReportsData?.oldTestPlanVersions?.length
) {
// Check if any results data available from a previous result
if (existingTestPlanReportsData?.oldTestPlanVersions?.length) {
latestOldVersion =
existingTestPlanReportsData?.oldTestPlanVersions?.reduce((a, b) =>
new Date(a.updatedAt) > new Date(b.updatedAt) ? a : b
Expand Down Expand Up @@ -135,7 +125,7 @@ function AddTestToQueueWithConfirmation({
await addTestToQueue(
canUseOldResults
? {
copyResultsFromTestPlanReportId:
copyResultsFromTestPlanVersionId:
latestOldVersion.id
}
: {}
Expand All @@ -151,7 +141,7 @@ function AddTestToQueueWithConfirmation({
const testPlanReport = await addTestToQueue(
canUseOldResults
? {
copyResultsFromTestPlanReportId:
copyResultsFromTestPlanVersionId:
latestOldVersion.id
}
: {}
Expand Down Expand Up @@ -184,76 +174,47 @@ function AddTestToQueueWithConfirmation({
};

const renderPreserveReportDataDialog = () => {
let title;
let content;
let actions = [];

if (oldReportToCopyResultsFrom) {
title = 'Older Results Data Found';
content =
'Older results with the same AT, browser and test plan ' +
'were found for the report being created. Would you like ' +
'to copy the older results into the report or create a ' +
'completely new report?';
actions = [
{
label: 'Create empty report',
onClick: async () => {
setShowPreserveReportDataMessage(false);
if (hasAutomationSupport) {
setShowConfirmation(true);
} else {
await addTestToQueue();
}
}
},
{
label: 'Copy older results',
onClick: async () => {
setShowPreserveReportDataMessage(false);
setCanUseOldResults(true);

if (hasAutomationSupport) {
setShowConfirmation(true);
} else {
await addTestToQueue({
copyResultsFromTestPlanReportId:
latestOldVersion.id
});
}
}
}
];
} else {
title = 'Conflicting Report Found';
content =
'The report could not be created because an existing ' +
'report was found on the reports page with the same AT, ' +
'browser and test plan version. Would you like to return ' +
'the existing report back to the test queue?';
actions = [
{
label: 'Proceed',
onClick: async () => {
setShowPreserveReportDataMessage(false);
if (hasAutomationSupport) {
setShowConfirmation(true);
} else {
await addTestToQueue();
}
}
}
];
}

return (
<BasicModal
show={showPreserveReportDataMessage}
title={title}
content={content}
title="Older Results Data Found"
content={
'Older results with the same AT, browser and test plan ' +
'were found for the report being created. Would you like ' +
'to copy the older results into the report or create a ' +
'completely new report?'
}
closeLabel="Cancel"
staticBackdrop={true}
actions={actions}
actions={[
{
label: 'Create empty report',
onClick: async () => {
setShowPreserveReportDataMessage(false);
if (hasAutomationSupport) {
setShowConfirmation(true);
} else {
await addTestToQueue();
}
}
},
{
label: 'Copy older results',
onClick: async () => {
setShowPreserveReportDataMessage(false);
setCanUseOldResults(true);

if (hasAutomationSupport) {
setShowConfirmation(true);
} else {
await addTestToQueue({
copyResultsFromTestPlanVersionId:
latestOldVersion.id
});
}
}
}
]}
useOnHide
handleClose={async () => {
setShowPreserveReportDataMessage(false);
Expand All @@ -262,20 +223,23 @@ function AddTestToQueueWithConfirmation({
);
};

const addTestToQueue = async ({ copyResultsFromTestPlanReportId } = {}) => {
const addTestToQueue = async ({
copyResultsFromTestPlanVersionId
} = {}) => {
let tpr;
await triggerLoad(async () => {
const res = await addTestPlanReport({
variables: {
testPlanVersionId: testPlanVersion.id,
atId: at.id,
minimumAtVersionId: minimumAtVersion?.id,
exactAtVersionId: exactAtVersion?.id,
browserId: browser.id,
copyResultsFromTestPlanReportId
copyResultsFromTestPlanVersionId
}
});
const testPlanReport =
res?.data?.findOrCreateTestPlanReport?.populatedData
?.testPlanReport ?? null;
res?.data?.createTestPlanReport?.testPlanReport ?? null;
tpr = testPlanReport;
}, 'Adding Test Plan to Test Queue');
setShowConfirmation(true);
Expand All @@ -300,7 +264,7 @@ function AddTestToQueueWithConfirmation({
disabled={disabled}
variant="secondary"
onClick={async () => {
if (conflictingReportExists || oldReportToCopyResultsFrom) {
if (oldReportToCopyResultsFrom) {
setShowPreserveReportDataMessage(true);
} else {
if (hasAutomationSupport) {
Expand All @@ -325,6 +289,8 @@ AddTestToQueueWithConfirmation.propTypes = {
testPlanVersion: PropTypes.object,
browser: PropTypes.object,
at: PropTypes.object,
exactAtVersion: PropTypes.object,
minimumAtVersion: PropTypes.object,
buttonRef: PropTypes.object,
onFocus: PropTypes.func,
onBlur: PropTypes.func,
Expand Down
Loading
Loading