Skip to content

Commit

Permalink
feat: Add backend support for minimum and exact AT versions (#1055)
Browse files Browse the repository at this point in the history
* Add minimum or exact at version to reports

* Quick tweak

* Revert home copy change

* Remove unused field from createTestPlanReport

* Fix undefined var

* Prevent API from creating duplicate reports

* Add atVersion frontend

* Make sure automation dialog always shows when valid

* Make sure existing reports have a minimum at version

* Simplify jsx string

Co-authored-by: Howard Edwards <[email protected]>

---------

Co-authored-by: Howard Edwards <[email protected]>
  • Loading branch information
alflennik and howard-e authored May 2, 2024
1 parent cab502d commit 58fb718
Show file tree
Hide file tree
Showing 22 changed files with 522 additions and 1,449 deletions.
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

0 comments on commit 58fb718

Please sign in to comment.