Added tests for offer list

This commit is contained in:
Princi Vershwal 2023-11-07 17:41:32 +05:30 committed by GitHub
parent 7e01bdbf18
commit 1d8adc6e86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 84 additions and 9 deletions

View File

@ -25,7 +25,6 @@ const OfferCard: React.FC<{amount: number, cadence: string, currency: string, du
let updatedPrice = originalPrice;
let tierName = offerTier?.name + ' ' + (cadence === 'month' ? 'Monthly' : 'Yearly') + ' — ' + (duration === 'once' ? 'First payment' : duration === 'repeating' ? 'Repeating' : 'Forever');
let originalPriceWithCurrency = getSymbol(currency) + numberWithCommas(currencyToDecimal(originalPrice));
const updatedPriceWithCurrency = getSymbol(currency) + numberWithCommas(currencyToDecimal(updatedPrice));
switch (type) {
case 'percent':
@ -47,6 +46,8 @@ const OfferCard: React.FC<{amount: number, cadence: string, currency: string, du
break;
}
const updatedPriceWithCurrency = getSymbol(currency) + numberWithCommas(currencyToDecimal(updatedPrice));
return (
<div className='flex cursor-pointer flex-col gap-6 border border-transparent bg-grey-100 p-5 transition-all hover:border-grey-100 hover:bg-grey-75 hover:shadow-sm dark:bg-grey-950 dark:hover:border-grey-800' onClick={onClick}>
<div className='flex items-center justify-between'>

View File

@ -0,0 +1,54 @@
import {expect, test} from '@playwright/test';
import {globalDataRequests, mockApi, responseFixtures, settingsWithStripe, toggleLabsFlag} from '../../utils/acceptance';
test.describe('Offers Modal', () => {
test.beforeEach(async () => {
toggleLabsFlag('adminXOffers', true);
});
test('Offers Modal is available', async ({page}) => {
await mockApi({page, requests: {
...globalDataRequests,
browseSettings: {...globalDataRequests.browseSettings, response: settingsWithStripe}
}});
await page.goto('/');
const section = page.getByTestId('offers');
await section.getByRole('button', {name: 'Manage offers'}).click();
const modal = page.getByTestId('offers-modal');
await expect(modal).toBeVisible();
});
test('Can view active offers', async ({page}) => {
await mockApi({page, requests: {
...globalDataRequests,
browseSettings: {...globalDataRequests.browseSettings, response: settingsWithStripe},
browseOffers: {method: 'GET', path: '/offers/?limit=all', response: responseFixtures.offers},
browseTiers: {method: 'GET', path: '/tiers/', response: responseFixtures.tiers}
}});
await page.goto('/');
const section = page.getByTestId('offers');
await section.getByRole('button', {name: 'Manage offers'}).click();
const modal = page.getByTestId('offers-modal');
await expect(modal).toContainText('Active offers');
await expect(modal).toContainText('First offer');
await expect(modal).toContainText('Second offer');
});
test('Can view archived offers', async ({page}) => {
await mockApi({page, requests: {
...globalDataRequests,
browseSettings: {...globalDataRequests.browseSettings, response: settingsWithStripe},
browseOffers: {method: 'GET', path: '/offers/?limit=all', response: responseFixtures.offers},
browseTiers: {method: 'GET', path: '/tiers/', response: responseFixtures.tiers}
}});
await page.goto('/');
const section = page.getByTestId('offers');
await section.getByRole('button', {name: 'Manage offers'}).click();
const modal = page.getByTestId('offers-modal');
await modal.getByText('Archived').click();
await expect(modal).toContainText('Archived offers');
await expect(modal).toContainText('Third offer');
});
});

View File

@ -1,12 +1,5 @@
import {expect, test} from '@playwright/test';
import {globalDataRequests, mockApi, responseFixtures, updatedSettingsResponse} from '../../utils/acceptance';
const settingsWithStripe = updatedSettingsResponse([
{key: 'stripe_connect_publishable_key', value: 'pk_test_123'},
{key: 'stripe_connect_secret_key', value: 'sk_test_123'},
{key: 'stripe_connect_display_name', value: 'Dummy'},
{key: 'stripe_connect_account_id', value: 'acct_123'}
]);
import {globalDataRequests, mockApi, responseFixtures, settingsWithStripe} from '../../utils/acceptance';
test.describe('Tier settings', async () => {
test('Supports creating a new tier', async ({page}) => {

View File

@ -123,6 +123,13 @@ export const globalDataRequests = {
browseMe: {method: 'GET', path: '/users/me/?include=roles', response: responseFixtures.me}
};
export const settingsWithStripe = updatedSettingsResponse([
{key: 'stripe_connect_publishable_key', value: 'pk_test_123'},
{key: 'stripe_connect_secret_key', value: 'sk_test_123'},
{key: 'stripe_connect_display_name', value: 'Dummy'},
{key: 'stripe_connect_account_id', value: 'acct_123'}
]);
export const limitRequests = {
browseUsers: {method: 'GET', path: '/users/?limit=100&include=roles', response: responseFixtures.users},
browseInvites: {method: 'GET', path: '/invites/', response: responseFixtures.invites},

View File

@ -39,6 +39,26 @@
"id": "645453f4d254799990dd0e22",
"name": "Supporter"
}
},
{
"id": "6487f0c364fca78ec2fff600",
"name": "Third offer",
"code": "third-offer",
"display_title": "Third offer",
"display_description": "",
"type": "percent",
"cadence": "month",
"amount": 12,
"duration": "repeating",
"duration_in_months": 3,
"currency_restriction": false,
"currency": null,
"status": "archived",
"redemption_count": 0,
"tier": {
"id": "645453f4d254799990dd0e22",
"name": "Supporter"
}
}
]
}