feat: Test case movement (#290)
This commit is contained in:
@@ -125,6 +125,28 @@ async function updateCase(jwt: string, updateCaseData: CaseType) {
|
||||
}
|
||||
}
|
||||
|
||||
export async function moveCases(jwt: string, moveCaseIds: number[], targetFolderId: number, projectId: number) {
|
||||
const fetchOptions = {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${jwt}`,
|
||||
},
|
||||
body: JSON.stringify({ caseIds: moveCaseIds, targetFolderId }),
|
||||
};
|
||||
const url = `${apiServer}/cases/move?projectId=${projectId}`;
|
||||
try {
|
||||
const response = await fetch(url, fetchOptions);
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! Status: ${response.status}`);
|
||||
}
|
||||
const data = await response.json();
|
||||
return data;
|
||||
} catch (error: unknown) {
|
||||
logError('Error updating project', error);
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteCases(jwt: string, deleteCaseIds: number[], projectId: number) {
|
||||
const fetchOptions = {
|
||||
method: 'POST',
|
||||
|
||||
19
frontend/utils/testCaseMoveEvent.ts
Normal file
19
frontend/utils/testCaseMoveEvent.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
const eventBus = new EventTarget();
|
||||
const TEST_CASE_MOVE = 'testCasesMove';
|
||||
|
||||
type MoveEventDetail = {
|
||||
testCaseIds: number[];
|
||||
targetFolderId: number;
|
||||
};
|
||||
|
||||
export const emitMoveEvent = (ids: number[], targetFolderId: number) => {
|
||||
eventBus.dispatchEvent(
|
||||
new CustomEvent(TEST_CASE_MOVE, { detail: { testCaseIds: ids, targetFolderId: targetFolderId } })
|
||||
);
|
||||
};
|
||||
|
||||
export const onMoveEvent = (listener: (event: CustomEvent<MoveEventDetail>) => void) => {
|
||||
const handler = (e: Event) => listener(e as CustomEvent);
|
||||
eventBus.addEventListener(TEST_CASE_MOVE, handler);
|
||||
return () => eventBus.removeEventListener(TEST_CASE_MOVE, handler);
|
||||
};
|
||||
Reference in New Issue
Block a user