forked from freeCodeCamp/freeCodeCamp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththird-party-donation.spec.ts
72 lines (53 loc) · 2.3 KB
/
third-party-donation.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { test, expect } from '@playwright/test';
import translations from '../client/i18n/locales/english/translations.json';
import stripeJson from './fixtures/donation/stripe.json';
import { alertToBeVisible } from './utils/alerts';
test.describe('third-party donation tests', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/donate');
});
test('All elements are present in the widget', async ({ page }) => {
await page.getByRole('button', { name: 'Donate', exact: true }).click();
// Paypal button should be present
const paypalButtonIframe = page.frameLocator('.component-frame');
const paypalButton = paypalButtonIframe.getByRole('link');
await expect(paypalButton).toBeVisible();
await expect(paypalButton).toHaveAttribute('aria-label', 'PayPal');
// Patreon button should be present
const patreonButton = page.locator('.patreon-button');
await expect(patreonButton).toBeVisible();
// "Or dontate with card" button should be present
await expect(page.getByText('Or donate with card')).toBeVisible();
});
test('It is possible to donate with a card', async ({ page }) => {
await page.getByRole('button', { name: 'Donate', exact: true }).click();
const cardNumberIframe = page
.frameLocator('iframe[src*="elements-inner-card"]')
.nth(0);
const cardExpiryIframe = page
.frameLocator('iframe[src*="elements-inner-card"]')
.nth(1);
await cardNumberIframe
.locator('input[data-elements-stable-field-name="cardNumber"]')
.fill('4242424242424242');
await cardExpiryIframe
.locator('input[data-elements-stable-field-name="cardExpiry"]')
.fill('1025');
await page.getByRole('button', { name: 'Donate', exact: true }).click();
await page.route(
'https://api.stripe.com/v1/payment_methods',
async route => {
await route.fulfill({ json: stripeJson });
}
);
await page.route(
new URL('donate/charge-stripe-card', process.env.API_LOCATION).toString(),
async route => {
await route.fulfill({ json: { isDonating: true } });
}
);
await expect(page.getByRole('alert')).toBeVisible();
await alertToBeVisible(page, translations.donate['free-tech']);
await alertToBeVisible(page, translations.donate['visit-supporters']);
});
});