0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-11 02:12:21 -05:00

Updated Portal tests

This commit is contained in:
Simon Backx 2023-09-07 09:59:30 +02:00 committed by Simon Backx
parent afeb9579b5
commit 8f618c7b5c

View file

@ -782,115 +782,5 @@ describe('Signup', () => {
window.location.hash = '';
});
});
describe('recommendations', () => {
describe('free member signup', () => {
test('does not redirect to the recommendations modal if recommendations are disabled', async () => {
const {
ghostApi, emailInput, nameInput, chooseBtns
} = await setup({
// Recommendations are disabled (default)
site: FixtureSite.singleTier.basic
});
// Fill signup form as free member
fireEvent.change(nameInput, {target: {value: 'Jamie Larsen'}});
fireEvent.change(emailInput, {target: {value: 'jamie@example.com'}});
fireEvent.click(chooseBtns[0]);
expect(ghostApi.member.sendMagicLink).toHaveBeenLastCalledWith({
email: 'jamie@example.com',
emailType: 'signup',
name: 'Jamie Larsen',
plan: 'free',
redirect: undefined
});
});
test('redirects the recommendations modal if recommendations are enabled', async () => {
const {
ghostApi, emailInput, nameInput, chooseBtns
} = await setup({
// Recommendations are enabled
site: FixtureSite.singleTier.withRecommendations
});
// Fill signup form as free member
fireEvent.change(nameInput, {target: {value: 'Jamie Larsen'}});
fireEvent.change(emailInput, {target: {value: 'jamie@example.com'}});
fireEvent.click(chooseBtns[0]);
const currentUrl = new URL(window.location.origin + window.location.pathname);
expect(ghostApi.member.sendMagicLink).toHaveBeenLastCalledWith({
email: 'jamie@example.com',
emailType: 'signup',
name: 'Jamie Larsen',
plan: 'free',
redirect: `${currentUrl}#/portal/welcome`
});
});
});
describe('paid member signup', () => {
test('does not redirect to the recommendations modal if recommendations are disabled', async () => {
const {
ghostApi, emailInput, nameInput, popupIframeDocument, submitButton
} = await setup({
// Recommendations are disabled (default)
site: FixtureSite.singleTier.basic
});
const yearlyPlanContainer = within(popupIframeDocument).queryByText(/Yearly$/);
const singleTierProduct = FixtureSite.singleTier.basic.products.find(p => p.type === 'paid');
// Fill signup form as free member
fireEvent.change(nameInput, {target: {value: 'Jamie Larsen'}});
fireEvent.change(emailInput, {target: {value: 'jamie@example.com'}});
fireEvent.click(yearlyPlanContainer.parentNode);
fireEvent.click(submitButton);
expect(ghostApi.member.checkoutPlan).toHaveBeenLastCalledWith({
email: 'jamie@example.com',
name: 'Jamie Larsen',
offerId: undefined,
plan: singleTierProduct.yearlyPrice.id,
tierId: singleTierProduct.id,
cadence: 'year',
successUrl: undefined
});
});
test('redirects to the recommendations modal if recommendations are enabled', async () => {
const {
ghostApi, emailInput, nameInput, popupIframeDocument, submitButton
} = await setup({
// Recommendations are disabled (default)
site: FixtureSite.singleTier.withRecommendations
});
const yearlyPlanContainer = within(popupIframeDocument).queryByText(/Yearly$/);
const singleTierProduct = FixtureSite.singleTier.basic.products.find(p => p.type === 'paid');
// Fill signup form as free member
fireEvent.change(nameInput, {target: {value: 'Jamie Larsen'}});
fireEvent.change(emailInput, {target: {value: 'jamie@example.com'}});
fireEvent.click(yearlyPlanContainer.parentNode);
fireEvent.click(submitButton);
const currentUrl = new URL(window.location.origin + window.location.pathname);
expect(ghostApi.member.checkoutPlan).toHaveBeenLastCalledWith({
email: 'jamie@example.com',
name: 'Jamie Larsen',
offerId: undefined,
plan: singleTierProduct.yearlyPrice.id,
tierId: singleTierProduct.id,
cadence: 'year',
successUrl: `${currentUrl}#/portal/welcome`
});
});
});
});
});