|
1 |
| -import { test } from '../../../../fixtures/card.fixture'; |
| 1 | +import { expect, test } from '../../../../fixtures/card.fixture'; |
| 2 | +import { getStoryUrl } from '../../../utils/getStoryUrl'; |
| 3 | +import { URL_MAP } from '../../../../fixtures/URL_MAP'; |
| 4 | +import { PAYMENT_RESULT, REGULAR_TEST_CARD, TEST_CVC_VALUE, TEST_DATE_VALUE, UNKNOWN_BIN_CARD, VISA_CARD } from '../../../utils/constants'; |
| 5 | +import LANG from '../../../../../server/translations/en-US.json'; |
| 6 | + |
| 7 | +const PAN_ERROR_NOT_SUPPORTED = LANG['cc.num.903']; |
| 8 | + |
| 9 | +test('#1 Test that after an unsupported card has been entered we see errors, PASTING in a full supported card clears errors & makes it possible to pay', async ({ |
| 10 | + card, |
| 11 | + page |
| 12 | +}) => { |
| 13 | + // |
| 14 | + const componentConfig = { brands: ['mc'] }; |
| 15 | + |
| 16 | + await card.goto(getStoryUrl({ baseUrl: URL_MAP.card, componentConfig })); |
| 17 | + |
| 18 | + await card.isComponentVisible(); |
| 19 | + |
| 20 | + // Fill unsupported card |
| 21 | + await card.fillCardNumber(VISA_CARD); |
| 22 | + await page.waitForTimeout(100); |
| 23 | + |
| 24 | + await card.typeExpiryDate(TEST_DATE_VALUE); |
| 25 | + await card.typeCvc(TEST_CVC_VALUE); |
| 26 | + |
| 27 | + await expect(card.cardNumberErrorElement).toBeVisible(); |
| 28 | + await expect(card.cardNumberErrorElement).toHaveText(PAN_ERROR_NOT_SUPPORTED); |
| 29 | + |
| 30 | + // "Paste" number that is supported |
| 31 | + await card.fillCardNumber(REGULAR_TEST_CARD); |
| 32 | + await page.waitForTimeout(100); |
| 33 | + |
| 34 | + // If correct events have fired expect the card to not have errors |
| 35 | + await expect(card.cardNumberErrorElement).not.toBeVisible(); |
| 36 | + |
| 37 | + // And to be valid |
| 38 | + await card.pay(); |
| 39 | + await expect(card.paymentResult).toHaveText(PAYMENT_RESULT.authorised); |
| 40 | +}); |
2 | 41 |
|
3 | 42 | test(
|
4 |
| - '#1 Enter number of unsupported card, ' + 'then check UI shows an error ' + 'then PASTE supported card & check UI error is cleared', |
5 |
| - async () => { |
6 |
| - // Wait for field to appear in DOM |
7 |
| - // Fill card field with unsupported number |
8 |
| - // Test UI shows "Unsupported card" error |
9 |
| - // Past card field with supported number |
10 |
| - // Test UI shows "Unsupported card" error has gone |
| 43 | + '#2 Enter number of unsupported card, ' + 'then check UI shows an error ' + 'then PASTE card not in db & check UI error is cleared', |
| 44 | + async ({ card, page }) => { |
| 45 | + const componentConfig = { brands: ['mc'] }; |
| 46 | + |
| 47 | + await card.goto(getStoryUrl({ baseUrl: URL_MAP.card, componentConfig })); |
| 48 | + |
| 49 | + await card.isComponentVisible(); |
| 50 | + |
| 51 | + // Fill unsupported card |
| 52 | + await card.fillCardNumber(VISA_CARD); |
| 53 | + await page.waitForTimeout(100); |
| 54 | + |
| 55 | + await card.typeExpiryDate(TEST_DATE_VALUE); |
| 56 | + await card.typeCvc(TEST_CVC_VALUE); |
| 57 | + |
| 58 | + await expect(card.cardNumberErrorElement).toBeVisible(); |
| 59 | + await expect(card.cardNumberErrorElement).toHaveText(PAN_ERROR_NOT_SUPPORTED); |
| 60 | + |
| 61 | + // "Paste" number that is unknown |
| 62 | + await card.fillCardNumber(UNKNOWN_BIN_CARD); |
| 63 | + await page.waitForTimeout(100); |
| 64 | + |
| 65 | + // If correct events have fired expect the card to not have errors |
| 66 | + await expect(card.cardNumberErrorElement).not.toBeVisible(); |
11 | 67 | }
|
12 | 68 | );
|
13 | 69 |
|
14 | 70 | test(
|
15 |
| - '#2 Enter number of unsupported card, ' + |
16 |
| - 'then check UI shows an error ' + |
17 |
| - 'then press the Pay button ' + |
18 |
| - 'then check UI shows more errors ' + |
19 |
| - 'then PASTE supported card & check PAN UI errors are cleared whilst others persist', |
20 |
| - async () => { |
21 |
| - // Wait for field to appear in DOM |
22 |
| - // Fill card field with unsupported number |
23 |
| - // Test UI shows "Unsupported card" error |
24 |
| - // Click Pay (which will call showValidation on all fields) |
25 |
| - // Past card field with supported number |
26 |
| - // Test UI shows "Unsupported card" error has gone |
27 |
| - // PAN error cleared but other errors persist |
28 |
| - } |
29 |
| -); |
| 71 | + '#3 Enter number of unsupported card, ' + 'then check UI shows an error ' + 'then delete PAN & check UI error is cleared', |
| 72 | + async ({ card, page }) => { |
| 73 | + const componentConfig = { brands: ['mc'] }; |
30 | 74 |
|
31 |
| -test('#3 Enter number of unsupported card, ' + 'then check UI shows an error ' + 'then PASTE card not in db check UI error is cleared', async () => { |
32 |
| - // Wait for field to appear in DOM |
33 |
| - // Fill card field with unsupported number |
34 |
| - // Test UI shows "Unsupported card" error |
35 |
| - // Past card field with supported number |
36 |
| - // Test UI shows "Unsupported card" error has gone |
37 |
| -}); |
| 75 | + await card.goto(getStoryUrl({ baseUrl: URL_MAP.card, componentConfig })); |
38 | 76 |
|
39 |
| -test('#4 Enter number of unsupported card, ' + 'then check UI shows an error ' + 'then delete PAN & check UI error is cleared', async () => { |
40 |
| - // Wait for field to appear in DOM |
41 |
| - // Fill card field with unsupported number |
42 |
| - // Test UI shows "Unsupported card" error |
43 |
| - // delete card number |
44 |
| - // Test UI shows "Unsupported card" error has gone |
45 |
| -}); |
| 77 | + await card.isComponentVisible(); |
| 78 | + |
| 79 | + // Fill unsupported card |
| 80 | + await card.fillCardNumber(VISA_CARD); |
| 81 | + await page.waitForTimeout(100); |
| 82 | + |
| 83 | + await expect(card.cardNumberErrorElement).toBeVisible(); |
| 84 | + await expect(card.cardNumberErrorElement).toHaveText(PAN_ERROR_NOT_SUPPORTED); |
| 85 | + |
| 86 | + await page.waitForTimeout(300); // leave time for focus to shift |
| 87 | + |
| 88 | + await card.deleteCardNumber(); |
| 89 | + await expect(card.cardNumberErrorElement).not.toBeVisible(); |
| 90 | + } |
| 91 | +); |
0 commit comments