update runCase at once
This commit is contained in:
@@ -39,7 +39,7 @@ module.exports = function (sequelize) {
|
||||
},
|
||||
{
|
||||
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 RunProgressChart from './RunPregressDonutChart';
|
||||
import TestCaseSelector from './TestCaseSelector';
|
||||
import { testRunStatus } from '@/config/selection';
|
||||
import { testRunCaseStatus, testRunStatus } from '@/config/selection';
|
||||
import { RunType, RunStatusCountType, RunMessages } from '@/types/run';
|
||||
import { CaseType } from '@/types/case';
|
||||
import { FolderType } from '@/types/folder';
|
||||
import {
|
||||
fetchRun,
|
||||
updateRun,
|
||||
updateRunCases,
|
||||
processRunCases,
|
||||
fetchProjectCases,
|
||||
processTestCases,
|
||||
} from '../runsControl';
|
||||
import { fetchRun, updateRun, updateRunCases, fetchProjectCases, processTestCases } from '../runsControl';
|
||||
import { fetchFolders } from '../../folders/foldersControl';
|
||||
import { TokenContext } from '@/utils/TokenProvider';
|
||||
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) => {
|
||||
setIsDirty(true);
|
||||
setTestCases((prevTestCases) => {
|
||||
return prevTestCases.map((testCase) => {
|
||||
if (testCase.id === changeCaseId) {
|
||||
return { ...testCase, runStatus: status, editState: 'changed' };
|
||||
}
|
||||
return testCase;
|
||||
});
|
||||
});
|
||||
const newTestCases = [...testCases];
|
||||
const found = newTestCases.find((testCase) => testCase.id === changeCaseId);
|
||||
if (found && found.RunCases && testRunCaseStatus.length > 0) {
|
||||
found.RunCases[0].status = status;
|
||||
found.RunCases[0].editState = 'changed';
|
||||
}
|
||||
setTestCases(newTestCases);
|
||||
};
|
||||
|
||||
const handleIncludeExcludeCase = async (isInclude: boolean, clickedTestCaseId: number) => {
|
||||
|
||||
@@ -156,7 +156,7 @@ export default function TestCaseSelector({
|
||||
startContent={renderStatusIcon(runCaseStatus.uid)}
|
||||
onPress={() => onStatusChange(testCase.id, index)}
|
||||
>
|
||||
{messages[runStatus.uid]}
|
||||
{messages[runCaseStatus.uid]}
|
||||
</DropdownItem>
|
||||
))}
|
||||
</DropdownMenu>
|
||||
@@ -250,12 +250,14 @@ export default function TestCaseSelector({
|
||||
</TableColumn>
|
||||
)}
|
||||
</TableHeader>
|
||||
<TableBody emptyContent={messages.noCasesFound} items={sortedItems}>
|
||||
{(item) => (
|
||||
<TableBody emptyContent={messages.noCasesFound}>
|
||||
{sortedItems.map((item) => (
|
||||
<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>
|
||||
)}
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</>
|
||||
|
||||
@@ -1,41 +1,75 @@
|
||||
import { describe, expect, test } from 'vitest';
|
||||
import { processRunCases } from './runsControl';
|
||||
import { RunCaseType } from '@/types/run';
|
||||
import { processTestCases } from './runsControl';
|
||||
import { CaseType } from '@/types/case';
|
||||
|
||||
const initialRuncases: RunCaseType[] = [
|
||||
{ id: 1, runId: 1, caseId: 1, editState: 'notChanged', status: 0 },
|
||||
{ id: 2, runId: 1, caseId: 2, editState: 'notChanged', status: 0 },
|
||||
{ id: 3, runId: 1, caseId: 3, editState: 'notChanged', status: 0 },
|
||||
const sampleTestCase: CaseType = {
|
||||
id: 1,
|
||||
title: '',
|
||||
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', () => {
|
||||
test('Add test cases not yet included in the test run', () => {
|
||||
test('include test case', () => {
|
||||
const isInclude = true;
|
||||
const keys: number[] = [4, 5];
|
||||
const keys: number[] = [3];
|
||||
const runId = 1;
|
||||
const currentRunCases = [...initialRuncases];
|
||||
const newRunCases = processRunCases(isInclude, keys, runId, currentRunCases);
|
||||
const currentRunCases = [...initialTestCases];
|
||||
const newTestCases = processTestCases(isInclude, keys, runId, currentRunCases);
|
||||
|
||||
expect(newRunCases).toStrictEqual([
|
||||
{ id: 1, runId: 1, caseId: 1, editState: 'notChanged', status: 0 },
|
||||
{ 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' },
|
||||
]);
|
||||
expect(newTestCases[2].RunCases?.length).toBe(1);
|
||||
expect(newTestCases[2].RunCases[0].editState).toBe('new');
|
||||
});
|
||||
|
||||
test('Exclude test cases already included in the test run', () => {
|
||||
const isInclude = false;
|
||||
const keys: number[] = [1, 3];
|
||||
const runId = 1;
|
||||
const currentRunCases = [...initialRuncases];
|
||||
const newRunCases = processRunCases(isInclude, keys, runId, currentRunCases);
|
||||
const currentRunCases = [...initialTestCases];
|
||||
const newTestCases = processTestCases(isInclude, keys, runId, currentRunCases);
|
||||
|
||||
expect(newRunCases).toStrictEqual([
|
||||
{ id: 1, runId: 1, caseId: 1, editState: 'deleted', status: 0 },
|
||||
{ id: 2, runId: 1, caseId: 2, editState: 'notChanged', status: 0 },
|
||||
{ id: 3, runId: 1, caseId: 3, editState: 'deleted', status: 0 },
|
||||
]);
|
||||
expect(newTestCases[0].RunCases[0].editState).toBe('deleted');
|
||||
expect(newTestCases[2].RunCases[0].editState).toBe('deleted');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -209,66 +209,12 @@ function processTestCases(isInclude: boolean, keys: number[], runId: number, cur
|
||||
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[]) {
|
||||
const runCases: RunCaseType[] = [];
|
||||
testCases.forEach((itr) => {
|
||||
if (itr.RunCases && itr.RunCases.length > 0) {
|
||||
runCases.push({
|
||||
id: -1,
|
||||
id: itr.RunCases[0].id,
|
||||
caseId: itr.id,
|
||||
runId: runId,
|
||||
status: itr.RunCases[0].status,
|
||||
@@ -277,8 +223,6 @@ async function updateRunCases(jwt: string, runId: number, testCases: CaseType[])
|
||||
}
|
||||
});
|
||||
|
||||
console.log(testCases, runCases);
|
||||
|
||||
const fetchOptions = {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
|
||||
@@ -35,7 +35,9 @@ type StepType = {
|
||||
};
|
||||
|
||||
type RunCaseType = {
|
||||
id: number;
|
||||
runId: number;
|
||||
caseId: number;
|
||||
status: number;
|
||||
editState: 'notChanged' | 'changed' | 'new' | 'deleted';
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user