mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
Added portal fixtures to tests
This commit is contained in:
parent
10c190837d
commit
fae8593d61
3 changed files with 125 additions and 5 deletions
58
apps/portal/src/components/pages/UnsubscribePage.test.js
Normal file
58
apps/portal/src/components/pages/UnsubscribePage.test.js
Normal file
|
@ -0,0 +1,58 @@
|
|||
import {render, screen} from '../../utils/test-utils';
|
||||
import UnsubscribePage from './UnsubscribePage';
|
||||
import {newsletters as Newsletters, site as FixtureSite, member as FixtureMember} from '../../utils/test-fixtures';
|
||||
|
||||
const setup = (overrides) => {
|
||||
const {mockOnActionFn, ...utils} = render(
|
||||
<UnsubscribePage />,
|
||||
{
|
||||
overrideContext: {
|
||||
...overrides
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
// let emailInput;
|
||||
// let submitButton;
|
||||
// let signupButton;
|
||||
let emailPreferencesTitle;
|
||||
|
||||
try {
|
||||
emailPreferencesTitle = utils.queryByText(/Email preferences/i);
|
||||
// emailInput = utils.getByLabelText(/email/i);
|
||||
// submitButton = utils.queryByRole('button', {name: 'Continue'});
|
||||
// signupButton = utils.queryByRole('button', {name: 'Sign up'});
|
||||
} catch (err) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
return {
|
||||
// emailInput,
|
||||
// submitButton,
|
||||
// signupButton,
|
||||
emailPreferencesTitle,
|
||||
mockOnActionFn,
|
||||
...utils
|
||||
};
|
||||
};
|
||||
|
||||
describe('Logged out UnsubscribePage', () => {
|
||||
beforeEach(() => {
|
||||
// Mock window.location
|
||||
// https://ronald.ink/?uuid=a61d0374-ba99-4dc4-9083-4c73a3e2745e&newsletter=ddb8e302-f165-46ae-8a87-01077765548c&action=unsubscribe
|
||||
Object.defineProperty(window, 'location', {
|
||||
value: new URL(`https://portal.localhost/?uuid=${FixtureMember.subbedToNewsletter.uuid}&newsletter=${Newsletters[0].id}&action=unsubscribe`),
|
||||
writable: true
|
||||
});
|
||||
});
|
||||
test('renders', () => {
|
||||
const {emailPreferencesTitle} = setup({
|
||||
site: FixtureSite.singleTier.onlyFreePlanWithoutStripe,
|
||||
member: FixtureMember.subbedToNewsletter,
|
||||
newsletters: Newsletters,
|
||||
pageData: Newsletters[0]
|
||||
});
|
||||
screen.debug(emailPreferencesTitle);
|
||||
expect(emailPreferencesTitle).toBeInTheDocument();
|
||||
});
|
||||
});
|
|
@ -121,7 +121,8 @@ export function getMemberData({
|
|||
email_suppression = {
|
||||
suppressed: false,
|
||||
info: null
|
||||
}
|
||||
},
|
||||
newsletters = []
|
||||
} = {}) {
|
||||
return {
|
||||
uuid: `member_${objectId()}`,
|
||||
|
@ -132,10 +133,53 @@ export function getMemberData({
|
|||
subscribed,
|
||||
avatar_image,
|
||||
subscriptions,
|
||||
email_suppression
|
||||
email_suppression,
|
||||
newsletters
|
||||
};
|
||||
}
|
||||
|
||||
export function getNewsletterData({
|
||||
id = `${objectId()}`,
|
||||
uuid = `${objectId()}`,
|
||||
name = 'Newsletter',
|
||||
description = 'Newsletter description',
|
||||
slug = 'newsletter',
|
||||
sender_email = null,
|
||||
subscribe_on_signup = true,
|
||||
visibility = 'members',
|
||||
sort_order = 0
|
||||
}) {
|
||||
return {
|
||||
id,
|
||||
uuid,
|
||||
name,
|
||||
description,
|
||||
slug,
|
||||
sender_email,
|
||||
subscribe_on_signup,
|
||||
visibility,
|
||||
sort_order
|
||||
};
|
||||
}
|
||||
|
||||
export function getNewslettersData({numOfNewsletters = 3} = {}) {
|
||||
const newsletters = [
|
||||
getNewsletterData({
|
||||
name: 'Newsletter 1',
|
||||
description: 'Newsletter 1 description'
|
||||
}),
|
||||
getNewsletterData({
|
||||
name: 'Newsletter 2',
|
||||
description: 'Newsletter 2 description'
|
||||
}),
|
||||
getNewsletterData({
|
||||
name: 'Newsletter 3',
|
||||
description: 'Newsletter 3 description'
|
||||
})
|
||||
];
|
||||
return newsletters.slice(0, numOfNewsletters);
|
||||
}
|
||||
|
||||
export function getProductsData({numOfProducts = 3} = {}) {
|
||||
const products = [
|
||||
getProductData({
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* eslint-disable no-unused-vars*/
|
||||
import {getFreeProduct, getMemberData, getOfferData, getPriceData, getProductData, getSiteData, getSubscriptionData, getTestSite} from './fixtures-generator';
|
||||
import {getFreeProduct, getMemberData, getOfferData, getPriceData, getProductData, getSiteData, getSubscriptionData, getNewsletterData} from './fixtures-generator';
|
||||
|
||||
export const transformTierFixture = [
|
||||
getFreeProduct({
|
||||
|
@ -24,6 +24,19 @@ export const transformTierFixture = [
|
|||
})
|
||||
];
|
||||
|
||||
export const newsletters = [
|
||||
getNewsletterData({
|
||||
name: 'Newsletter 1',
|
||||
description: 'Newsletter 1 description',
|
||||
sort_order: 1
|
||||
}),
|
||||
getNewsletterData({
|
||||
name: 'Newsletter 2',
|
||||
description: 'Newsletter 2 description',
|
||||
sort_order: 2
|
||||
})
|
||||
];
|
||||
|
||||
export const singleSiteTier = [
|
||||
getFreeProduct({
|
||||
name: 'Free',
|
||||
|
@ -163,7 +176,8 @@ export const site = {
|
|||
onlyFreePlanWithoutStripe: {
|
||||
...baseSingleTierSite,
|
||||
portal_plans: ['free'],
|
||||
is_stripe_configured: false
|
||||
is_stripe_configured: false,
|
||||
newsletters: newsletters
|
||||
},
|
||||
membersInviteOnly: {
|
||||
...baseSingleTierSite,
|
||||
|
@ -213,7 +227,8 @@ export const member = {
|
|||
subscriptions: [],
|
||||
paid: false,
|
||||
avatarImage: '',
|
||||
subscribed: true
|
||||
subscribed: true,
|
||||
newsletters: []
|
||||
}),
|
||||
altFree: getMemberData({
|
||||
name: 'Jimmie Larson',
|
||||
|
@ -301,6 +316,9 @@ export const member = {
|
|||
currentPeriodEnd: '2021-06-05T11:42:40.000Z'
|
||||
})
|
||||
]
|
||||
}),
|
||||
subbedToNewsletter: getMemberData({
|
||||
newsletters: newsletters
|
||||
})
|
||||
};
|
||||
/* eslint-enable no-unused-vars*/
|
||||
|
|
Loading…
Add table
Reference in a new issue