mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-06 22:40:14 -05:00
Added tests for edit offer
Ref: https://www.notion.so/ghost/Implement-edit-modal-7c4f1930d40243e887b37f2cb4701a1f
This commit is contained in:
parent
532dc2165f
commit
c26b5256cf
2 changed files with 50 additions and 1 deletions
|
@ -144,7 +144,10 @@ const EditOfferModal: React.FC<RoutingModalProps> = ({params}) => {
|
|||
dirty={saveState === 'unsaved'}
|
||||
okColor={okProps.color}
|
||||
okLabel={okProps.label || 'Save'}
|
||||
sidebar={sidebar} size='full' title='Offer'
|
||||
sidebar={sidebar}
|
||||
size='full'
|
||||
testId='offer-update-modal'
|
||||
title='Offer'
|
||||
onCancel={() => {
|
||||
modal.remove();
|
||||
updateRoute('offers/edit');
|
||||
|
|
|
@ -51,4 +51,50 @@ test.describe('Offers Modal', () => {
|
|||
await expect(modal).toContainText('Archived offers');
|
||||
await expect(modal).toContainText('Third offer');
|
||||
});
|
||||
|
||||
test('Supports updating an offer', async ({page}) => {
|
||||
const {lastApiRequests} = await mockApi({page, requests: {
|
||||
...globalDataRequests,
|
||||
browseSettings: {...globalDataRequests.browseSettings, response: settingsWithStripe},
|
||||
browseOffers: {method: 'GET', path: '/offers/?limit=all', response: responseFixtures.offers},
|
||||
browseOffersById: {method: 'GET', path: `/offers/${responseFixtures.offers.offers[0].id}/`, response: responseFixtures.offers},
|
||||
browseTiers: {method: 'GET', path: '/tiers/', response: responseFixtures.tiers},
|
||||
editOffer: {method: 'PUT', path: `/offers/${responseFixtures.offers.offers[0].id}/`, response: {
|
||||
offers: [{
|
||||
id: responseFixtures.offers.offers[0].id,
|
||||
name: 'Updated offer',
|
||||
body_font_category: 'sans_serif'
|
||||
}]
|
||||
}}
|
||||
}});
|
||||
|
||||
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 modal.getByText('First offer').click();
|
||||
|
||||
const offerUpdateModal = page.getByTestId('offer-update-modal');
|
||||
await expect(offerUpdateModal).toBeVisible();
|
||||
|
||||
await offerUpdateModal.getByPlaceholder('black-friday').fill('');
|
||||
await offerUpdateModal.getByRole('button', {name: 'Save'}).click();
|
||||
|
||||
await expect(page.getByTestId('toast-error')).toContainText(/Can't save offer, please double check that you've filled all mandatory fields./);
|
||||
await expect(offerUpdateModal).toContainText(/Please enter a code/);
|
||||
|
||||
await offerUpdateModal.getByPlaceholder('black-friday').fill('black-friday-offer');
|
||||
|
||||
await offerUpdateModal.getByRole('button', {name: 'Save'}).click();
|
||||
|
||||
expect(lastApiRequests.editOffer?.body).toMatchObject({
|
||||
offers: [{
|
||||
id: responseFixtures.offers.offers[0].id,
|
||||
name: 'First offer',
|
||||
code: 'black-friday-offer'
|
||||
}]
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue