-
Notifications
You must be signed in to change notification settings - Fork 273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: keep polishing onStatus lifecycle #1055
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
8087aad
feat: keep polishing onStatus lifecycle
Zizzamia 61176d1
ok
Zizzamia 42abe37
dope
Zizzamia d2a8dee
ok
Zizzamia 9cbcf8c
ok
Zizzamia 8532b4f
dope
Zizzamia b77cf96
ok
Zizzamia a1ec415
ok
Zizzamia 08ac841
ok
Zizzamia 612cccc
ok
Zizzamia 54f1680
ok
Zizzamia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,12 +37,20 @@ vi.mock('../hooks/useWriteContracts', () => ({ | |
|
||
const TestComponent = () => { | ||
const context = useTransactionContext(); | ||
const handleSetLifeCycleStatus = async () => { | ||
const handleStatusError = async () => { | ||
context.setLifeCycleStatus({ | ||
statusName: 'error', | ||
statusData: { code: 'code', error: 'error_long_messages' }, | ||
}); | ||
}; | ||
const handleStatusTransactionLegacyExecuted = async () => { | ||
context.setLifeCycleStatus({ | ||
statusName: 'transactionLegacyExecuted', | ||
statusData: { | ||
transactionHashList: ['hash12345678'], | ||
}, | ||
}); | ||
}; | ||
return ( | ||
<div data-testid="test-component"> | ||
<button type="button" onClick={context.onSubmit}> | ||
|
@@ -55,9 +63,12 @@ const TestComponent = () => { | |
<span data-testid="context-value-isToastVisible"> | ||
{`${context.isToastVisible}`} | ||
</span> | ||
<button type="button" onClick={handleSetLifeCycleStatus}> | ||
<button type="button" onClick={handleStatusError}> | ||
setLifeCycleStatus.error | ||
</button> | ||
<button type="button" onClick={handleStatusTransactionLegacyExecuted}> | ||
setLifeCycleStatus.transactionLegacyExecuted | ||
</button> | ||
</div> | ||
); | ||
}; | ||
|
@@ -99,7 +110,7 @@ describe('TransactionProvider', () => { | |
expect(onErrorMock).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should emit onStatus when setLifeCycleStatus is called', async () => { | ||
it('should emit onStatus when setLifeCycleStatus is called with transactionLegacyExecuted', async () => { | ||
const onStatusMock = vi.fn(); | ||
render( | ||
<TransactionProvider | ||
|
@@ -110,41 +121,46 @@ describe('TransactionProvider', () => { | |
<TestComponent /> | ||
</TransactionProvider>, | ||
); | ||
const button = screen.getByText('setLifeCycleStatus.error'); | ||
const button = screen.getByText( | ||
'setLifeCycleStatus.transactionLegacyExecuted', | ||
); | ||
fireEvent.click(button); | ||
expect(onStatusMock).toHaveBeenCalled(); | ||
expect(onStatusMock).toHaveBeenCalledWith({ | ||
statusName: 'transactionLegacyExecuted', | ||
statusData: { | ||
transactionHashList: ['hash12345678'], | ||
}, | ||
}); | ||
}); | ||
|
||
it('should update context on handleSubmit', async () => { | ||
const writeContractsAsyncMock = vi.fn(); | ||
(useWriteContracts as ReturnType<typeof vi.fn>).mockReturnValue({ | ||
statusWriteContracts: 'IDLE', | ||
writeContractsAsync: writeContractsAsyncMock, | ||
}); | ||
it('should emit onStatus when setLifeCycleStatus is called', async () => { | ||
const onStatusMock = vi.fn(); | ||
render( | ||
<TransactionProvider address="0x123" contracts={[]}> | ||
<TransactionProvider | ||
address="0x123" | ||
contracts={[]} | ||
onStatus={onStatusMock} | ||
> | ||
<TestComponent /> | ||
</TransactionProvider>, | ||
); | ||
const button = screen.getByText('Submit'); | ||
const button = screen.getByText('setLifeCycleStatus.error'); | ||
fireEvent.click(button); | ||
await waitFor(() => { | ||
expect(writeContractsAsyncMock).toHaveBeenCalled(); | ||
}); | ||
expect(onStatusMock).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should call onsuccess when receipt exists', async () => { | ||
it('should emit onSuccess when one receipt exist', async () => { | ||
const onSuccessMock = vi.fn(); | ||
(useWaitForTransactionReceipt as ReturnType<typeof vi.fn>).mockReturnValue({ | ||
data: '123', | ||
data: { status: 'success' }, | ||
}); | ||
(useCallsStatus as ReturnType<typeof vi.fn>).mockReturnValue({ | ||
transactionHash: 'hash', | ||
}); | ||
render( | ||
<TransactionProvider | ||
address="0x123" | ||
contracts={[]} | ||
contracts={[{ address: '0x123', method: 'method' }]} | ||
onSuccess={onSuccessMock} | ||
> | ||
<TestComponent /> | ||
|
@@ -154,6 +170,27 @@ describe('TransactionProvider', () => { | |
fireEvent.click(button); | ||
await waitFor(() => { | ||
expect(onSuccessMock).toHaveBeenCalled(); | ||
expect(onSuccessMock).toHaveBeenCalledWith({ | ||
transactionReceipts: [{ status: 'success' }], | ||
}); | ||
}); | ||
}); | ||
|
||
it('should update context on handleSubmit', async () => { | ||
const writeContractsAsyncMock = vi.fn(); | ||
(useWriteContracts as ReturnType<typeof vi.fn>).mockReturnValue({ | ||
statusWriteContracts: 'IDLE', | ||
writeContractsAsync: writeContractsAsyncMock, | ||
}); | ||
render( | ||
<TransactionProvider address="0x123" contracts={[]}> | ||
<TestComponent /> | ||
</TransactionProvider>, | ||
); | ||
const button = screen.getByText('Submit'); | ||
fireEvent.click(button); | ||
await waitFor(() => { | ||
expect(writeContractsAsyncMock).toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
|
@@ -252,30 +289,6 @@ describe('TransactionProvider', () => { | |
}); | ||
}); | ||
|
||
it('should call onSuccess when receipts are available', async () => { | ||
const onSuccessMock = vi.fn(); | ||
(useWaitForTransactionReceipt as ReturnType<typeof vi.fn>).mockReturnValue({ | ||
data: { status: 'success' }, | ||
}); | ||
(useCallsStatus as ReturnType<typeof vi.fn>).mockReturnValue({ | ||
transactionHash: 'hash', | ||
}); | ||
render( | ||
<TransactionProvider | ||
address="0x123" | ||
contracts={[]} | ||
onSuccess={onSuccessMock} | ||
> | ||
<TestComponent /> | ||
</TransactionProvider>, | ||
); | ||
await waitFor(() => { | ||
expect(onSuccessMock).toHaveBeenCalledWith({ | ||
transactionReceipts: [{ status: 'success' }], | ||
}); | ||
}); | ||
}); | ||
|
||
it('should handle chain switching', async () => { | ||
const switchChainAsyncMock = vi.fn(); | ||
(useSwitchChain as ReturnType<typeof vi.fn>).mockReturnValue({ | ||
|
@@ -382,34 +395,6 @@ describe('TransactionProvider', () => { | |
); | ||
}); | ||
}); | ||
|
||
it('should call onSuccess when receiptArray has receipts', async () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same for this one. I am rewriting the entire logic in a more simple way so we can actually test this. |
||
const onSuccessMock = vi.fn(); | ||
const mockReceipt = { status: 'success' }; | ||
|
||
(useWaitForTransactionReceipt as ReturnType<typeof vi.fn>).mockReturnValue({ | ||
data: mockReceipt, | ||
}); | ||
|
||
render( | ||
<TransactionProvider | ||
address="0x123" | ||
contracts={[]} | ||
onSuccess={onSuccessMock} | ||
> | ||
<TestComponent /> | ||
</TransactionProvider>, | ||
); | ||
|
||
const button = screen.getByText('Submit'); | ||
fireEvent.click(button); | ||
|
||
await waitFor(() => { | ||
expect(onSuccessMock).toHaveBeenCalledWith({ | ||
transactionReceipts: [mockReceipt], | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('useTransactionContext', () => { | ||
|
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
Empty file.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apperently this test was not testing what was suppose to test 🤦🏻♂️