test: add test suite for personal workspace provider service

This commit is contained in:
jamesgeorge007
2024-05-16 15:04:50 +05:30
parent e0083aa70d
commit 86b17e2bd3
3 changed files with 2231 additions and 24 deletions

View File

@@ -91,11 +91,9 @@ export class PersonalWorkspaceProviderService
workspaceSelectorPriority: 100, workspaceSelectorPriority: 100,
}) })
private restCollectionState: Ref<{ state: HoppCollection[] }> public restCollectionState: Ref<{ state: HoppCollection[] }>
private issuedHandles: WritableHandleRef< public issuedHandles: WritableHandleRef<WorkspaceRequest>[] = []
WorkspaceCollection | WorkspaceRequest
>[] = []
public constructor() { public constructor() {
super() super()
@@ -337,7 +335,7 @@ export class PersonalWorkspaceProviderService
if (isRootCollection) { if (isRootCollection) {
const collectionToRemove = navigateToFolderWithIndexPath( const collectionToRemove = navigateToFolderWithIndexPath(
restCollectionStore.value.state, this.restCollectionState.value.state,
[collectionIndexPos] [collectionIndexPos]
) )
@@ -348,7 +346,7 @@ export class PersonalWorkspaceProviderService
} else { } else {
const folderToRemove = path const folderToRemove = path
? navigateToFolderWithIndexPath( ? navigateToFolderWithIndexPath(
restCollectionStore.value.state, this.restCollectionState.value.state,
removedCollectionID.split("/").map((id) => parseInt(id)) removedCollectionID.split("/").map((id) => parseInt(id))
) )
: undefined : undefined
@@ -548,7 +546,7 @@ export class PersonalWorkspaceProviderService
const requestIndexPos = parseInt(requestID.split("/").slice(-1)[0]) const requestIndexPos = parseInt(requestID.split("/").slice(-1)[0])
const requestToRemove = navigateToFolderWithIndexPath( const requestToRemove = navigateToFolderWithIndexPath(
restCollectionStore.value.state, this.restCollectionState.value.state,
collectionID.split("/").map((id) => parseInt(id)) collectionID.split("/").map((id) => parseInt(id))
)?.requests[requestIndexPos] )?.requests[requestIndexPos]
@@ -1079,7 +1077,7 @@ export class PersonalWorkspaceProviderService
requestHandleRef.value.data requestHandleRef.value.data
const collectionRequestCount = getRequestsByPath( const collectionRequestCount = getRequestsByPath(
restCollectionStore.value.state, this.restCollectionState.value.state,
collectionID collectionID
).length ).length
@@ -1140,6 +1138,12 @@ export class PersonalWorkspaceProviderService
return { affectedRequestHandleIdx, newRequestIndexPos } return { affectedRequestHandleIdx, newRequestIndexPos }
}) })
updateRESTRequestOrder(
this.pathToLastIndex(draggedRequestID),
destinationRequestID ? destinationRequestIndexPos : null,
destinationCollectionID
)
affectedRequestHandleUpdateInfo.forEach( affectedRequestHandleUpdateInfo.forEach(
({ affectedRequestHandleIdx, newRequestIndexPos }) => { ({ affectedRequestHandleIdx, newRequestIndexPos }) => {
const handle = this.issuedHandles[affectedRequestHandleIdx] const handle = this.issuedHandles[affectedRequestHandleIdx]
@@ -1156,12 +1160,6 @@ export class PersonalWorkspaceProviderService
} }
) )
updateRESTRequestOrder(
this.pathToLastIndex(draggedRequestID),
destinationRequestID ? destinationRequestIndexPos : null,
destinationCollectionID
)
return Promise.resolve(E.right(undefined)) return Promise.resolve(E.right(undefined))
} }
@@ -1183,7 +1181,7 @@ export class PersonalWorkspaceProviderService
const draggedRequestIndexPos = this.pathToLastIndex(draggedRequestID) const draggedRequestIndexPos = this.pathToLastIndex(draggedRequestID)
const movedRequestHandle = this.issuedHandles.find((handle) => { const draggedRequestHandle = this.issuedHandles.find((handle) => {
if (handle.value.type === "invalid") { if (handle.value.type === "invalid") {
return return
} }
@@ -1196,15 +1194,15 @@ export class PersonalWorkspaceProviderService
}) })
if ( if (
!movedRequestHandle || !draggedRequestHandle ||
movedRequestHandle.value.type === "invalid" || draggedRequestHandle.value.type === "invalid" ||
!("requestID" in movedRequestHandle.value.data) !("requestID" in draggedRequestHandle.value.data)
) { ) {
return Promise.resolve(E.left("INVALID_REQUEST_HANDLE" as const)) return Promise.resolve(E.left("INVALID_REQUEST_HANDLE" as const))
} }
const draggedCollectionReqCountBeforeMove = getRequestsByPath( const draggedCollectionReqCountBeforeMove = getRequestsByPath(
restCollectionStore.value.state, this.restCollectionState.value.state,
sourceCollectionID sourceCollectionID
).length ).length
@@ -1227,12 +1225,12 @@ export class PersonalWorkspaceProviderService
) )
const destinationCollectionReqCount = getRequestsByPath( const destinationCollectionReqCount = getRequestsByPath(
restCollectionStore.value.state, this.restCollectionState.value.state,
destinationCollectionID destinationCollectionID
).length ).length
movedRequestHandle.value.data.collectionID = destinationCollectionID draggedRequestHandle.value.data.collectionID = destinationCollectionID
movedRequestHandle.value.data.requestID = `${destinationCollectionID}/${ draggedRequestHandle.value.data.requestID = `${destinationCollectionID}/${
destinationCollectionReqCount - 1 destinationCollectionReqCount - 1
}` }`

View File

@@ -580,8 +580,6 @@ describe("PersistenceService", () => {
invokeSetupLocalPersistence() invokeSetupLocalPersistence()
// toastErrorFn = vi.fn()
expect(getItemSpy).toHaveBeenCalledWith(settingsKey) expect(getItemSpy).toHaveBeenCalledWith(settingsKey)
expect(toastErrorFn).not.toHaveBeenCalledWith(settingsKey) expect(toastErrorFn).not.toHaveBeenCalledWith(settingsKey)