Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rustam-cb committed Jan 16, 2025
1 parent 05f2610 commit 7850ac4
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 34 deletions.
46 changes: 22 additions & 24 deletions src/fund/components/FundCard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,7 @@ describe('FundCard', () => {
it('handles input changes for fiat amount', () => {
renderComponent();

const input = screen.getByTestId(
'ockFundCardAmountInput',
) as HTMLInputElement;
const input = screen.getByTestId('ockTextInput_Input') as HTMLInputElement;

act(() => {
fireEvent.change(input, { target: { value: '100' } });
Expand Down Expand Up @@ -208,7 +206,7 @@ describe('FundCard', () => {
expect(screen.getByTestId('loading-state').textContent).toBe(
'not-loading',
);
const input = screen.getByTestId('ockFundCardAmountInput');
const input = screen.getByTestId('ockTextInput_Input');
fireEvent.change(input, { target: { value: '1000' } });

const button = screen.getByTestId('ockFundButton');
Expand All @@ -227,7 +225,7 @@ describe('FundCard', () => {
expect(screen.getByTestId('loading-state').textContent).toBe(
'not-loading',
);
const input = screen.getByTestId('ockFundCardAmountInput');
const input = screen.getByTestId('ockTextInput_Input');
fireEvent.change(input, { target: { value: '1000' } });

const button = screen.getByTestId('ockFundButton');
Expand All @@ -242,7 +240,7 @@ describe('FundCard', () => {
expect(screen.getByTestId('loading-state').textContent).toBe(
'not-loading',
);
const input = screen.getByTestId('ockFundCardAmountInput');
const input = screen.getByTestId('ockTextInput_Input');

fireEvent.change(input, { target: { value: '1000' } });

Expand All @@ -257,32 +255,32 @@ describe('FundCard', () => {
});
});

it('sets submit button state to default on popup close', () => {
vi.useFakeTimers();

it('sets submit button state to default on popup close', async () => {
(openPopup as Mock).mockImplementation(() => ({ closed: true }));

renderComponent();

const button = screen.getByTestId('ockFundButton');

// Simulate entering a valid amount
const input = screen.getByTestId(
'ockFundCardAmountInput',
) as HTMLInputElement;
act(() => {
fireEvent.change(input, { target: { value: '100' } });
});
const submitButton = screen.getByTestId('ockFundButton');

// Click the submit button to trigger loading state
act(() => {
fireEvent.click(button);
});
await waitFor(() => {
expect(screen.getByTestId('loading-state').textContent).toBe(
'not-loading',
);

vi.runOnlyPendingTimers();
// Simulate entering a valid amount
const input = screen.getByTestId(
'ockTextInput_Input',
) as HTMLInputElement;

const submitButton = screen.getByTestId('ockFundButton');
fireEvent.change(input, { target: { value: '100' } });

fireEvent.click(button);

// Assert that the submit button state is set to 'default'
expect(submitButton).not.toBeDisabled();
// Assert that the submit button state is set to 'default'
expect(submitButton).not.toBeDisabled();
});
});

it('renders custom children instead of default children', () => {
Expand Down
24 changes: 14 additions & 10 deletions src/fund/hooks/useLifecycleStatus.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ describe('useLifecycleStatus', () => {
}),
);

const [, updateStatus] = result.current;
// Update to pending
act(() => {
result.current[1]({
updateStatus({
statusName: 'transactionPending',
statusData: {
abc: 'def',
Expand All @@ -38,25 +39,28 @@ describe('useLifecycleStatus', () => {
expect(result.current[0]).toEqual({
statusName: 'transactionPending',
statusData: {
test: 'any',
abc: 'def',
},
});

// Update to success

result.current[1]({
statusName: 'transactionSuccess',
statusData: {
assetImageUrl: 'a',
assetName: 'b',
assetSymbol: 'c',
chainId: 'd',
},
act(() => {
updateStatus({
statusName: 'transactionSuccess',
statusData: {
assetImageUrl: 'a',
assetName: 'b',
assetSymbol: 'c',
chainId: 'd',
},
});
});

expect(result.current[0]).toEqual({
statusName: 'transactionSuccess',
statusData: {
abc: 'def',
assetImageUrl: 'a',
assetName: 'b',
assetSymbol: 'c',
Expand Down

0 comments on commit 7850ac4

Please sign in to comment.