mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
🐛 Fixed portal free trial message incorrectly showing (#17095)
no issue Fixed portal free trial message incorrectly showing when signing up for free. Message was showing due to `pageQuery` erroneously not being passed down the call stack to `getSiteProducts`
This commit is contained in:
parent
64518d2ad4
commit
a79035c2f6
4 changed files with 40 additions and 7 deletions
|
@ -606,8 +606,8 @@ class SignupPage extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
renderFreeTrialMessage() {
|
renderFreeTrialMessage() {
|
||||||
const {site, t} = this.context;
|
const {site, t, pageQuery} = this.context;
|
||||||
if (hasFreeTrialTier({site}) && !isInviteOnlySite({site})) {
|
if (hasFreeTrialTier({site, pageQuery}) && !isInviteOnlySite({site})) {
|
||||||
return (
|
return (
|
||||||
<p className='gh-portal-free-trial-notification' data-testid="free-trial-notification-text">
|
<p className='gh-portal-free-trial-notification' data-testid="free-trial-notification-text">
|
||||||
{t('After a free trial ends, you will be charged the regular price for the tier you\'ve chosen. You can always cancel before then.')}
|
{t('After a free trial ends, you will be charged the regular price for the tier you\'ve chosen. You can always cancel before then.')}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import SignupPage from './SignupPage';
|
import SignupPage from './SignupPage';
|
||||||
|
import {getFreeProduct, getProductData, getSiteData} from '../../utils/fixtures-generator';
|
||||||
import {render, fireEvent} from '../../utils/test-utils';
|
import {render, fireEvent} from '../../utils/test-utils';
|
||||||
|
|
||||||
const setup = (overrides) => {
|
const setup = (overrides) => {
|
||||||
|
@ -7,7 +8,8 @@ const setup = (overrides) => {
|
||||||
<SignupPage />,
|
<SignupPage />,
|
||||||
{
|
{
|
||||||
overrideContext: {
|
overrideContext: {
|
||||||
member: null
|
member: null,
|
||||||
|
...overrides
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -16,12 +18,14 @@ const setup = (overrides) => {
|
||||||
const submitButton = utils.queryByRole('button', {name: 'Continue'});
|
const submitButton = utils.queryByRole('button', {name: 'Continue'});
|
||||||
const chooseButton = utils.queryAllByRole('button', {name: 'Choose'});
|
const chooseButton = utils.queryAllByRole('button', {name: 'Choose'});
|
||||||
const signinButton = utils.queryByRole('button', {name: 'Sign in'});
|
const signinButton = utils.queryByRole('button', {name: 'Sign in'});
|
||||||
|
const freeTrialMessage = utils.queryByText(/After a free trial ends/i);
|
||||||
return {
|
return {
|
||||||
nameInput,
|
nameInput,
|
||||||
emailInput,
|
emailInput,
|
||||||
submitButton,
|
submitButton,
|
||||||
chooseButton,
|
chooseButton,
|
||||||
signinButton,
|
signinButton,
|
||||||
|
freeTrialMessage,
|
||||||
mockOnActionFn,
|
mockOnActionFn,
|
||||||
...utils
|
...utils
|
||||||
};
|
};
|
||||||
|
@ -59,4 +63,31 @@ describe('SignupPage', () => {
|
||||||
fireEvent.click(signinButton);
|
fireEvent.click(signinButton);
|
||||||
expect(mockOnActionFn).toHaveBeenCalledWith('switchPage', {page: 'signin'});
|
expect(mockOnActionFn).toHaveBeenCalledWith('switchPage', {page: 'signin'});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('renders free trial message', () => {
|
||||||
|
const {freeTrialMessage} = setup({
|
||||||
|
site: getSiteData({
|
||||||
|
products: [
|
||||||
|
getProductData({trialDays: 7}),
|
||||||
|
getFreeProduct({})
|
||||||
|
]
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(freeTrialMessage).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('does not render free trial message on free signup', () => {
|
||||||
|
const {freeTrialMessage} = setup({
|
||||||
|
site: getSiteData({
|
||||||
|
products: [
|
||||||
|
getProductData({trialDays: 7}),
|
||||||
|
getFreeProduct({})
|
||||||
|
]
|
||||||
|
}),
|
||||||
|
pageQuery: 'free'
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(freeTrialMessage).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -189,7 +189,8 @@ export function getProductData({
|
||||||
id = `product_${objectId()}`,
|
id = `product_${objectId()}`,
|
||||||
monthlyPrice = getPriceData(),
|
monthlyPrice = getPriceData(),
|
||||||
yearlyPrice = getPriceData({interval: 'year'}),
|
yearlyPrice = getPriceData({interval: 'year'}),
|
||||||
numOfBenefits = 2
|
numOfBenefits = 2,
|
||||||
|
trialDays = null
|
||||||
}) {
|
}) {
|
||||||
return {
|
return {
|
||||||
id: id,
|
id: id,
|
||||||
|
@ -198,7 +199,8 @@ export function getProductData({
|
||||||
monthlyPrice: type === 'free' ? null : monthlyPrice,
|
monthlyPrice: type === 'free' ? null : monthlyPrice,
|
||||||
yearlyPrice: type === 'free' ? null : yearlyPrice,
|
yearlyPrice: type === 'free' ? null : yearlyPrice,
|
||||||
type: type,
|
type: type,
|
||||||
benefits: getBenefits({numOfBenefits})
|
benefits: getBenefits({numOfBenefits}),
|
||||||
|
trial_days: trialDays
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -410,8 +410,8 @@ export function getSiteProducts({site, pageQuery}) {
|
||||||
return products;
|
return products;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function hasFreeTrialTier({site}) {
|
export function hasFreeTrialTier({site, pageQuery}) {
|
||||||
const tiers = getSiteProducts({site});
|
const tiers = getSiteProducts({site, pageQuery});
|
||||||
return tiers.some((tier) => {
|
return tiers.some((tier) => {
|
||||||
return !!tier?.trial_days;
|
return !!tier?.trial_days;
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue