update runCase at once
This commit is contained in:
@@ -39,7 +39,7 @@ module.exports = function (sequelize) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
model: RunCase,
|
model: RunCase,
|
||||||
attributes: ['runId', 'status'],
|
attributes: ['id', 'runId', 'status'],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -21,18 +21,11 @@ import {
|
|||||||
import { Save, ArrowLeft, Folder, ChevronDown, CopyPlus, CopyMinus, RotateCw } from 'lucide-react';
|
import { Save, ArrowLeft, Folder, ChevronDown, CopyPlus, CopyMinus, RotateCw } from 'lucide-react';
|
||||||
import RunProgressChart from './RunPregressDonutChart';
|
import RunProgressChart from './RunPregressDonutChart';
|
||||||
import TestCaseSelector from './TestCaseSelector';
|
import TestCaseSelector from './TestCaseSelector';
|
||||||
import { testRunStatus } from '@/config/selection';
|
import { testRunCaseStatus, testRunStatus } from '@/config/selection';
|
||||||
import { RunType, RunStatusCountType, RunMessages } from '@/types/run';
|
import { RunType, RunStatusCountType, RunMessages } from '@/types/run';
|
||||||
import { CaseType } from '@/types/case';
|
import { CaseType } from '@/types/case';
|
||||||
import { FolderType } from '@/types/folder';
|
import { FolderType } from '@/types/folder';
|
||||||
import {
|
import { fetchRun, updateRun, updateRunCases, fetchProjectCases, processTestCases } from '../runsControl';
|
||||||
fetchRun,
|
|
||||||
updateRun,
|
|
||||||
updateRunCases,
|
|
||||||
processRunCases,
|
|
||||||
fetchProjectCases,
|
|
||||||
processTestCases,
|
|
||||||
} from '../runsControl';
|
|
||||||
import { fetchFolders } from '../../folders/foldersControl';
|
import { fetchFolders } from '../../folders/foldersControl';
|
||||||
import { TokenContext } from '@/utils/TokenProvider';
|
import { TokenContext } from '@/utils/TokenProvider';
|
||||||
import { useTheme } from 'next-themes';
|
import { useTheme } from 'next-themes';
|
||||||
@@ -122,14 +115,13 @@ export default function RunEditor({ projectId, runId, messages, locale }: Props)
|
|||||||
|
|
||||||
const handleChangeStatus = async (changeCaseId: number, status: number) => {
|
const handleChangeStatus = async (changeCaseId: number, status: number) => {
|
||||||
setIsDirty(true);
|
setIsDirty(true);
|
||||||
setTestCases((prevTestCases) => {
|
const newTestCases = [...testCases];
|
||||||
return prevTestCases.map((testCase) => {
|
const found = newTestCases.find((testCase) => testCase.id === changeCaseId);
|
||||||
if (testCase.id === changeCaseId) {
|
if (found && found.RunCases && testRunCaseStatus.length > 0) {
|
||||||
return { ...testCase, runStatus: status, editState: 'changed' };
|
found.RunCases[0].status = status;
|
||||||
}
|
found.RunCases[0].editState = 'changed';
|
||||||
return testCase;
|
}
|
||||||
});
|
setTestCases(newTestCases);
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleIncludeExcludeCase = async (isInclude: boolean, clickedTestCaseId: number) => {
|
const handleIncludeExcludeCase = async (isInclude: boolean, clickedTestCaseId: number) => {
|
||||||
|
|||||||
@@ -156,7 +156,7 @@ export default function TestCaseSelector({
|
|||||||
startContent={renderStatusIcon(runCaseStatus.uid)}
|
startContent={renderStatusIcon(runCaseStatus.uid)}
|
||||||
onPress={() => onStatusChange(testCase.id, index)}
|
onPress={() => onStatusChange(testCase.id, index)}
|
||||||
>
|
>
|
||||||
{messages[runStatus.uid]}
|
{messages[runCaseStatus.uid]}
|
||||||
</DropdownItem>
|
</DropdownItem>
|
||||||
))}
|
))}
|
||||||
</DropdownMenu>
|
</DropdownMenu>
|
||||||
@@ -250,12 +250,14 @@ export default function TestCaseSelector({
|
|||||||
</TableColumn>
|
</TableColumn>
|
||||||
)}
|
)}
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
<TableBody emptyContent={messages.noCasesFound} items={sortedItems}>
|
<TableBody emptyContent={messages.noCasesFound}>
|
||||||
{(item) => (
|
{sortedItems.map((item) => (
|
||||||
<TableRow key={item.id} className={isCaseIncluded(item) ? '' : notIncludedCaseClass}>
|
<TableRow key={item.id} className={isCaseIncluded(item) ? '' : notIncludedCaseClass}>
|
||||||
{(columnKey) => <TableCell key={`${item.id} + ${columnKey}`}>{renderCell(item, columnKey)}</TableCell>}
|
{headerColumns.map((column) => (
|
||||||
|
<TableCell key={column.uid}>{renderCell(item, column.uid)}</TableCell>
|
||||||
|
))}
|
||||||
</TableRow>
|
</TableRow>
|
||||||
)}
|
))}
|
||||||
</TableBody>
|
</TableBody>
|
||||||
</Table>
|
</Table>
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -1,41 +1,75 @@
|
|||||||
import { describe, expect, test } from 'vitest';
|
import { describe, expect, test } from 'vitest';
|
||||||
import { processRunCases } from './runsControl';
|
import { processTestCases } from './runsControl';
|
||||||
import { RunCaseType } from '@/types/run';
|
import { CaseType } from '@/types/case';
|
||||||
|
|
||||||
const initialRuncases: RunCaseType[] = [
|
const sampleTestCase: CaseType = {
|
||||||
{ id: 1, runId: 1, caseId: 1, editState: 'notChanged', status: 0 },
|
id: 1,
|
||||||
{ id: 2, runId: 1, caseId: 2, editState: 'notChanged', status: 0 },
|
title: '',
|
||||||
{ id: 3, runId: 1, caseId: 3, editState: 'notChanged', status: 0 },
|
state: 0,
|
||||||
|
priority: 0,
|
||||||
|
type: 0,
|
||||||
|
automationStatus: 0,
|
||||||
|
description: '',
|
||||||
|
template: 0,
|
||||||
|
preConditions: '',
|
||||||
|
expectedResults: '',
|
||||||
|
folderId: 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
const initialTestCases: CaseType[] = [
|
||||||
|
{
|
||||||
|
...sampleTestCase,
|
||||||
|
id: 1,
|
||||||
|
RunCases: [
|
||||||
|
{
|
||||||
|
id: 1,
|
||||||
|
runId: 1,
|
||||||
|
caseId: 1,
|
||||||
|
status: 0,
|
||||||
|
editState: 'notChanged',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
...sampleTestCase,
|
||||||
|
id: 2,
|
||||||
|
RunCases: [
|
||||||
|
{
|
||||||
|
id: 2,
|
||||||
|
runId: 1,
|
||||||
|
caseId: 2,
|
||||||
|
status: 0,
|
||||||
|
editState: 'notChanged',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
...sampleTestCase,
|
||||||
|
id: 3,
|
||||||
|
RunCases: [],
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
describe('runsControl', () => {
|
describe('runsControl', () => {
|
||||||
test('Add test cases not yet included in the test run', () => {
|
test('include test case', () => {
|
||||||
const isInclude = true;
|
const isInclude = true;
|
||||||
const keys: number[] = [4, 5];
|
const keys: number[] = [3];
|
||||||
const runId = 1;
|
const runId = 1;
|
||||||
const currentRunCases = [...initialRuncases];
|
const currentRunCases = [...initialTestCases];
|
||||||
const newRunCases = processRunCases(isInclude, keys, runId, currentRunCases);
|
const newTestCases = processTestCases(isInclude, keys, runId, currentRunCases);
|
||||||
|
|
||||||
expect(newRunCases).toStrictEqual([
|
expect(newTestCases[2].RunCases?.length).toBe(1);
|
||||||
{ id: 1, runId: 1, caseId: 1, editState: 'notChanged', status: 0 },
|
expect(newTestCases[2].RunCases[0].editState).toBe('new');
|
||||||
{ id: 2, runId: 1, caseId: 2, editState: 'notChanged', status: 0 },
|
|
||||||
{ id: 3, runId: 1, caseId: 3, editState: 'notChanged', status: 0 },
|
|
||||||
{ id: -1, runId: runId, caseId: 4, status: -1, editState: 'new' },
|
|
||||||
{ id: -1, runId: runId, caseId: 5, status: -1, editState: 'new' },
|
|
||||||
]);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Exclude test cases already included in the test run', () => {
|
test('Exclude test cases already included in the test run', () => {
|
||||||
const isInclude = false;
|
const isInclude = false;
|
||||||
const keys: number[] = [1, 3];
|
const keys: number[] = [1, 3];
|
||||||
const runId = 1;
|
const runId = 1;
|
||||||
const currentRunCases = [...initialRuncases];
|
const currentRunCases = [...initialTestCases];
|
||||||
const newRunCases = processRunCases(isInclude, keys, runId, currentRunCases);
|
const newTestCases = processTestCases(isInclude, keys, runId, currentRunCases);
|
||||||
|
|
||||||
expect(newRunCases).toStrictEqual([
|
expect(newTestCases[0].RunCases[0].editState).toBe('deleted');
|
||||||
{ id: 1, runId: 1, caseId: 1, editState: 'deleted', status: 0 },
|
expect(newTestCases[2].RunCases[0].editState).toBe('deleted');
|
||||||
{ id: 2, runId: 1, caseId: 2, editState: 'notChanged', status: 0 },
|
|
||||||
{ id: 3, runId: 1, caseId: 3, editState: 'deleted', status: 0 },
|
|
||||||
]);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -209,66 +209,12 @@ function processTestCases(isInclude: boolean, keys: number[], runId: number, cur
|
|||||||
return updatedTestCases;
|
return updatedTestCases;
|
||||||
}
|
}
|
||||||
|
|
||||||
// function processRunCases(
|
|
||||||
// isInclude: boolean,
|
|
||||||
// keys: number[],
|
|
||||||
// runId: number,
|
|
||||||
// currentRunCases: RunCaseType[]
|
|
||||||
// ): RunCaseType[] {
|
|
||||||
// const updatedRunCases = [...currentRunCases];
|
|
||||||
|
|
||||||
// if (isInclude) {
|
|
||||||
// keys.forEach((caseId) => {
|
|
||||||
// const existingRunCase = currentRunCases.find((runCase) => runCase.caseId === caseId);
|
|
||||||
// if (existingRunCase) {
|
|
||||||
// // already included
|
|
||||||
// if (existingRunCase.editState === 'notChanged') {
|
|
||||||
// // do nothing
|
|
||||||
// } else if (existingRunCase.editState === 'changed') {
|
|
||||||
// // do nothing
|
|
||||||
// } else if (existingRunCase.editState === 'new') {
|
|
||||||
// // do nothing
|
|
||||||
// } else if (existingRunCase.editState === 'deleted') {
|
|
||||||
// existingRunCase.editState = 'changed';
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// updatedRunCases.push({
|
|
||||||
// id: -1,
|
|
||||||
// runId: runId,
|
|
||||||
// caseId: caseId,
|
|
||||||
// status: 0,
|
|
||||||
// editState: 'new',
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// } else {
|
|
||||||
// keys.forEach((caseId) => {
|
|
||||||
// const existingRunCase = currentRunCases.find((runCase) => runCase.caseId === caseId);
|
|
||||||
// if (!existingRunCase) {
|
|
||||||
// // already excluded
|
|
||||||
// } else {
|
|
||||||
// if (existingRunCase.editState === 'notChanged') {
|
|
||||||
// existingRunCase.editState = 'deleted';
|
|
||||||
// } else if (existingRunCase.editState === 'changed') {
|
|
||||||
// existingRunCase.editState = 'deleted';
|
|
||||||
// } else if (existingRunCase.editState === 'new') {
|
|
||||||
// existingRunCase.editState = 'deleted';
|
|
||||||
// } else if (existingRunCase.editState === 'deleted') {
|
|
||||||
// // do nothing
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
|
|
||||||
// return updatedRunCases;
|
|
||||||
// }
|
|
||||||
|
|
||||||
async function updateRunCases(jwt: string, runId: number, testCases: CaseType[]) {
|
async function updateRunCases(jwt: string, runId: number, testCases: CaseType[]) {
|
||||||
const runCases: RunCaseType[] = [];
|
const runCases: RunCaseType[] = [];
|
||||||
testCases.forEach((itr) => {
|
testCases.forEach((itr) => {
|
||||||
if (itr.RunCases && itr.RunCases.length > 0) {
|
if (itr.RunCases && itr.RunCases.length > 0) {
|
||||||
runCases.push({
|
runCases.push({
|
||||||
id: -1,
|
id: itr.RunCases[0].id,
|
||||||
caseId: itr.id,
|
caseId: itr.id,
|
||||||
runId: runId,
|
runId: runId,
|
||||||
status: itr.RunCases[0].status,
|
status: itr.RunCases[0].status,
|
||||||
@@ -277,8 +223,6 @@ async function updateRunCases(jwt: string, runId: number, testCases: CaseType[])
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(testCases, runCases);
|
|
||||||
|
|
||||||
const fetchOptions = {
|
const fetchOptions = {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
|
|||||||
@@ -35,7 +35,9 @@ type StepType = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
type RunCaseType = {
|
type RunCaseType = {
|
||||||
|
id: number;
|
||||||
runId: number;
|
runId: number;
|
||||||
|
caseId: number;
|
||||||
status: number;
|
status: number;
|
||||||
editState: 'notChanged' | 'changed' | 'new' | 'deleted';
|
editState: 'notChanged' | 'changed' | 'new' | 'deleted';
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user