fix: update error when editing run cases
This commit is contained in:
@@ -163,6 +163,18 @@ export default function RunEditor({
|
||||
setSelectedKeys(new Set([]));
|
||||
};
|
||||
|
||||
const resetEditStateAll = () => {
|
||||
const newTestCases = [...testCases];
|
||||
newTestCases.forEach((itr) => {
|
||||
if (itr.RunCases && itr.RunCases.length > 0) {
|
||||
itr.RunCases[0].editState = 'notChanged';
|
||||
}
|
||||
});
|
||||
|
||||
setTestCases(newTestCases);
|
||||
setSelectedKeys(new Set([]));
|
||||
};
|
||||
|
||||
const baseClass = '';
|
||||
const selectedClass = `${baseClass} bg-neutral-200 dark:bg-neutral-700`;
|
||||
|
||||
@@ -192,6 +204,7 @@ export default function RunEditor({
|
||||
setIsUpdating(true);
|
||||
await updateRun(context.token.access_token, testRun);
|
||||
await updateRunCases(context.token.access_token, Number(runId), testCases);
|
||||
resetEditStateAll();
|
||||
setIsUpdating(false);
|
||||
setIsDirty(false);
|
||||
}}
|
||||
|
||||
@@ -46,12 +46,33 @@ const initialTestCases: CaseType[] = [
|
||||
{
|
||||
...sampleTestCase,
|
||||
id: 3,
|
||||
RunCases: [],
|
||||
RunCases: [
|
||||
{
|
||||
id: 3,
|
||||
runId: 1,
|
||||
caseId: 3,
|
||||
status: 0,
|
||||
editState: 'new',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
...sampleTestCase,
|
||||
id: 4,
|
||||
RunCases: [
|
||||
{
|
||||
id: 4,
|
||||
runId: 1,
|
||||
caseId: 4,
|
||||
status: 0,
|
||||
editState: 'deleted',
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
describe('runsControl', () => {
|
||||
test('Exclude test cases already included in the test run', () => {
|
||||
test('update test case which has not changed yet', () => {
|
||||
const changeCaseId = 1;
|
||||
const newStatus = 1;
|
||||
const currentRunCases = [...initialTestCases];
|
||||
@@ -65,7 +86,52 @@ describe('runsControl', () => {
|
||||
}
|
||||
});
|
||||
|
||||
test('include test case', () => {
|
||||
test('update test case which has already changed', () => {
|
||||
const changeCaseId = 1;
|
||||
const newStatus = 1;
|
||||
const currentRunCases = [...initialTestCases];
|
||||
const newTestCases = changeStatus(changeCaseId, newStatus, currentRunCases);
|
||||
|
||||
const overwriteStatus = 2;
|
||||
const overwrittenCases = changeStatus(changeCaseId, overwriteStatus, newTestCases);
|
||||
|
||||
if (overwrittenCases[0] && overwrittenCases[0].RunCases && overwrittenCases[0].RunCases[0]) {
|
||||
expect(overwrittenCases[0].RunCases[0].status).toBe(2);
|
||||
expect(overwrittenCases[0].RunCases[0].editState).toBe('changed');
|
||||
} else {
|
||||
assert.fail("RunCases isn't exist");
|
||||
}
|
||||
});
|
||||
|
||||
test('when update test case whose editState is "new", the editState remains "new"', () => {
|
||||
const changeCaseId = 3;
|
||||
const newStatus = 1;
|
||||
const currentRunCases = [...initialTestCases];
|
||||
const newTestCases = changeStatus(changeCaseId, newStatus, currentRunCases);
|
||||
|
||||
if (newTestCases[2] && newTestCases[2].RunCases && newTestCases[2].RunCases[0]) {
|
||||
expect(newTestCases[2].RunCases[0].status).toBe(1);
|
||||
expect(newTestCases[2].RunCases[0].editState).toBe('new');
|
||||
} else {
|
||||
assert.fail("RunCases isn't exist");
|
||||
}
|
||||
});
|
||||
|
||||
test('when update test case whose editState is "deleted", the editState remains "deleted" and status not changed', () => {
|
||||
const changeCaseId = 4;
|
||||
const newStatus = 1;
|
||||
const currentRunCases = [...initialTestCases];
|
||||
const newTestCases = changeStatus(changeCaseId, newStatus, currentRunCases);
|
||||
|
||||
if (newTestCases[3] && newTestCases[3].RunCases && newTestCases[3].RunCases[0]) {
|
||||
expect(newTestCases[3].RunCases[0].status).toBe(0);
|
||||
expect(newTestCases[3].RunCases[0].editState).toBe('deleted');
|
||||
} else {
|
||||
assert.fail("RunCases isn't exist");
|
||||
}
|
||||
});
|
||||
|
||||
test("included test case's editState is 'new'", () => {
|
||||
const isInclude = true;
|
||||
const keys: number[] = [3];
|
||||
const runId = 1;
|
||||
@@ -79,7 +145,21 @@ describe('runsControl', () => {
|
||||
}
|
||||
});
|
||||
|
||||
test('Exclude test cases which already included', () => {
|
||||
test('when include test case, whose editState is "new"', () => {
|
||||
const isInclude = true;
|
||||
const keys: number[] = [3];
|
||||
const runId = 1;
|
||||
const currentRunCases = [...initialTestCases];
|
||||
const newTestCases = includeExcludeTestCases(isInclude, keys, runId, currentRunCases);
|
||||
|
||||
if (newTestCases[2] && newTestCases[2].RunCases && newTestCases[2].RunCases[0]) {
|
||||
expect(newTestCases[2].RunCases[0].editState).toBe('new');
|
||||
} else {
|
||||
assert.fail("RunCases isn't exist");
|
||||
}
|
||||
});
|
||||
|
||||
test("excluded test cases's editState are 'deleted'", () => {
|
||||
const isInclude = false;
|
||||
const keys: number[] = [1, 3];
|
||||
const runId = 1;
|
||||
|
||||
@@ -198,10 +198,17 @@ function includeExcludeTestCases(
|
||||
} else if (targetCase.RunCases[0].editState === 'new') {
|
||||
// do nothing
|
||||
} else if (targetCase.RunCases[0].editState === 'deleted') {
|
||||
targetCase.RunCases[0].editState = 'changed';
|
||||
if (targetCase.RunCases[0].id > 0) {
|
||||
// when id is valid (already included)
|
||||
targetCase.RunCases[0].editState = 'changed';
|
||||
} else {
|
||||
// when id is invalid (has not included)
|
||||
targetCase.RunCases[0].editState = 'new';
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const newRunCase = {
|
||||
id: -1,
|
||||
runId: runId,
|
||||
status: 0,
|
||||
editState: 'new',
|
||||
|
||||
Reference in New Issue
Block a user