-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor removeAccountDataHook to ease the testing
- Loading branch information
1 parent
0c56a09
commit b13a5dd
Showing
9 changed files
with
173 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { useRemoveAccountsDependencies } from "./removeAccountDependenciesHooks"; | ||
import { mockImplicitAccount, mockTezOperation } from "../../mocks/factories"; | ||
import { renderHook } from "../../mocks/testUtils"; | ||
import { makeAccountOperations } from "../../types/AccountOperations"; | ||
import { MAINNET } from "../../types/Network"; | ||
import { batchesActions } from "../redux/slices/batches"; | ||
import { store } from "../redux/store"; | ||
|
||
describe("useRemoveAccountsDependencies", () => { | ||
it("removes batches related to the given accounts", () => { | ||
const accountOperations1 = makeAccountOperations( | ||
mockImplicitAccount(1), | ||
mockImplicitAccount(1), | ||
[mockTezOperation(0), mockTezOperation(1)] | ||
); | ||
const accountOperations2 = makeAccountOperations( | ||
mockImplicitAccount(2), | ||
mockImplicitAccount(2), | ||
[mockTezOperation(1), mockTezOperation(3)] | ||
); | ||
const accountOperations3 = makeAccountOperations( | ||
mockImplicitAccount(3), | ||
mockImplicitAccount(3), | ||
[mockTezOperation(0)] | ||
); | ||
store.dispatch(batchesActions.add({ operations: accountOperations1, network: MAINNET })); | ||
store.dispatch(batchesActions.add({ operations: accountOperations2, network: MAINNET })); | ||
store.dispatch(batchesActions.add({ operations: accountOperations3, network: MAINNET })); | ||
|
||
const { | ||
result: { current: removeAccountsDependencies }, | ||
} = renderHook(() => useRemoveAccountsDependencies()); | ||
removeAccountsDependencies([mockImplicitAccount(2), mockImplicitAccount(3)]); | ||
|
||
expect(store.getState().batches[MAINNET.name]).toEqual([accountOperations1]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Account } from "../../types/Account"; | ||
import { useAppDispatch } from "../redux/hooks"; | ||
import { batchesSlice } from "../redux/slices/batches"; | ||
|
||
/** | ||
* Hook for removing all stored accounts' dependencies. | ||
* | ||
* That means: | ||
* - removing all batches related to the given accounts | ||
*/ | ||
export const useRemoveAccountsDependencies = () => { | ||
const dispatch = useAppDispatch(); | ||
|
||
return (accounts: Account[]) => { | ||
const pkhs = accounts.map(account => account.address.pkh); | ||
dispatch(batchesSlice.actions.removeByAccounts({ pkhs })); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters