Skip to content

Commit

Permalink
Chore/move requiring confimration tests (#2779)
Browse files Browse the repository at this point in the history
* move requiring confirmation tests out of testcafe

* fix import
  • Loading branch information
m1aw authored Aug 7, 2024
1 parent 6b75a57 commit fc126cf
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 77 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

58 changes: 58 additions & 0 deletions packages/lib/src/components/Giftcard/Giftcard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,62 @@ describe('Giftcard', () => {
expect(onSubmit).toHaveBeenCalled();
});
});

describe('onRequiringConfirmation handling', () => {
test('should require confirmation and resolve payment', async () => {
const onBalanceCheck = jest.fn(resolve =>
resolve({
balance: { value: 2000, currency: 'EUR' }
})
);
const onOrderRequest = jest.fn(resolve => resolve({}));
const onSubmit = jest.fn();
const onRequiringConfirmation = jest.fn(resolve => resolve());

// mounting and clicking pay button
const giftcard = new Giftcard(global.core, {
...baseProps,
onBalanceCheck,
onOrderRequest,
onRequiringConfirmation,
onSubmit
});
render(giftcard.render());
giftcard.setState({ isValid: true });
const payButton = await screen.findByRole('button');
await user.click(payButton);

expect(onOrderRequest).not.toHaveBeenCalled();
expect(onRequiringConfirmation).toHaveBeenCalled();
expect(onSubmit).toHaveBeenCalled();
});

test('should require confirmation and cancel payment', async () => {
const onBalanceCheck = jest.fn(resolve =>
resolve({
balance: { value: 2000, currency: 'EUR' }
})
);
const onOrderRequest = jest.fn(resolve => resolve({}));
const onSubmit = jest.fn();
const onRequiringConfirmation = jest.fn(({ reject }) => reject());

// mounting and clicking pay button
const giftcard = new Giftcard(global.core, {
...baseProps,
onBalanceCheck,
onOrderRequest,
onRequiringConfirmation,
onSubmit
});
render(giftcard.render());
giftcard.setState({ isValid: true });
const payButton = await screen.findByRole('button');
await user.click(payButton);

expect(onOrderRequest).not.toHaveBeenCalled();
expect(onRequiringConfirmation).toHaveBeenCalled();
expect(onSubmit).not.toHaveBeenCalled();
});
});
});

0 comments on commit fc126cf

Please sign in to comment.