mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-25 02:31:59 -05:00
Added tests for direct portal links
closes https://github.com/TryGhost/Team/issues/1354 - extends test coverage to include direct portal links - `#/portal/*`
This commit is contained in:
parent
98f212c3df
commit
13fccc3b9f
2 changed files with 200 additions and 7 deletions
|
@ -1,7 +1,6 @@
|
|||
import App from '../App';
|
||||
import {site as FixturesSite, member as FixtureMember} from '../utils/test-fixtures';
|
||||
import {fireEvent, appRender, within} from '../utils/test-utils';
|
||||
import {site as FixtureSite} from '../utils/test-fixtures';
|
||||
import setupGhostApi from '../utils/api';
|
||||
const {formSubmitHandler, planClickHandler} = require('../data-attributes');
|
||||
|
||||
|
@ -275,7 +274,7 @@ describe('Portal Data attributes:', () => {
|
|||
let {
|
||||
popupFrame, triggerButtonFrame, ...utils
|
||||
} = await setup({
|
||||
site: FixtureSite.singleTier.basic,
|
||||
site: FixturesSite.singleTier.basic,
|
||||
showPopup: false
|
||||
});
|
||||
expect(popupFrame).not.toBeInTheDocument();
|
||||
|
@ -295,7 +294,7 @@ describe('Portal Data attributes:', () => {
|
|||
let {
|
||||
popupFrame, triggerButtonFrame, ...utils
|
||||
} = await setup({
|
||||
site: FixtureSite.singleTier.basic,
|
||||
site: FixturesSite.singleTier.basic,
|
||||
showPopup: false
|
||||
});
|
||||
expect(popupFrame).not.toBeInTheDocument();
|
||||
|
@ -317,7 +316,7 @@ describe('Portal Data attributes:', () => {
|
|||
let {
|
||||
popupFrame, triggerButtonFrame, ...utils
|
||||
} = await setup({
|
||||
site: FixtureSite.singleTier.basic,
|
||||
site: FixturesSite.singleTier.basic,
|
||||
showPopup: false
|
||||
});
|
||||
expect(popupFrame).not.toBeInTheDocument();
|
||||
|
@ -339,7 +338,7 @@ describe('Portal Data attributes:', () => {
|
|||
let {
|
||||
popupFrame, triggerButtonFrame, ...utils
|
||||
} = await setup({
|
||||
site: FixtureSite.singleTier.basic,
|
||||
site: FixturesSite.singleTier.basic,
|
||||
member: FixtureMember.free,
|
||||
showPopup: false
|
||||
});
|
||||
|
@ -362,7 +361,7 @@ describe('Portal Data attributes:', () => {
|
|||
let {
|
||||
popupFrame, triggerButtonFrame, ...utils
|
||||
} = await setup({
|
||||
site: FixtureSite.singleTier.basic,
|
||||
site: FixturesSite.singleTier.basic,
|
||||
member: FixtureMember.free,
|
||||
showPopup: false
|
||||
});
|
||||
|
@ -385,7 +384,7 @@ describe('Portal Data attributes:', () => {
|
|||
let {
|
||||
popupFrame, triggerButtonFrame, ...utils
|
||||
} = await setup({
|
||||
site: FixtureSite.singleTier.basic,
|
||||
site: FixturesSite.singleTier.basic,
|
||||
member: FixtureMember.free,
|
||||
showPopup: false
|
||||
});
|
||||
|
|
194
ghost/portal/src/tests/portal-links.test.js
Normal file
194
ghost/portal/src/tests/portal-links.test.js
Normal file
|
@ -0,0 +1,194 @@
|
|||
import App from '../App';
|
||||
import {site as FixtureSite, member as FixtureMember} from '../utils/test-fixtures';
|
||||
import {appRender, within} from '../utils/test-utils';
|
||||
import setupGhostApi from '../utils/api';
|
||||
|
||||
const setup = async ({site, member = null, showPopup = true}) => {
|
||||
const ghostApi = setupGhostApi({siteUrl: 'https://example.com'});
|
||||
ghostApi.init = jest.fn(() => {
|
||||
return Promise.resolve({
|
||||
site,
|
||||
member
|
||||
});
|
||||
});
|
||||
|
||||
ghostApi.member.sendMagicLink = jest.fn(() => {
|
||||
return Promise.resolve('success');
|
||||
});
|
||||
|
||||
ghostApi.member.checkoutPlan = jest.fn(() => {
|
||||
return Promise.resolve();
|
||||
});
|
||||
|
||||
const utils = appRender(
|
||||
<App api={ghostApi} showPopup={showPopup} />
|
||||
);
|
||||
|
||||
const triggerButtonFrame = await utils.findByTitle(/portal-trigger/i);
|
||||
const popupFrame = utils.queryByTitle(/portal-popup/i);
|
||||
return {
|
||||
ghostApi,
|
||||
popupFrame,
|
||||
triggerButtonFrame,
|
||||
...utils
|
||||
};
|
||||
};
|
||||
|
||||
describe('Portal Data links:', () => {
|
||||
beforeEach(() => {
|
||||
// Mock global fetch
|
||||
jest.spyOn(window, 'fetch').mockImplementation((url) => {
|
||||
if (url.includes('send-magic-link')) {
|
||||
return Promise.resolve({
|
||||
ok: true,
|
||||
json: async () => ({success: true})
|
||||
});
|
||||
}
|
||||
|
||||
if (url.includes('api/session')) {
|
||||
return Promise.resolve({
|
||||
ok: true,
|
||||
text: async () => {
|
||||
return 'session-identity';
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (url.includes('create-stripe-checkout-session')) {
|
||||
return Promise.resolve({
|
||||
ok: true,
|
||||
json: async () => {
|
||||
return {
|
||||
publicKey: 'key-xyz'
|
||||
};
|
||||
}
|
||||
});
|
||||
}
|
||||
return Promise.resolve({});
|
||||
});
|
||||
|
||||
// Mock global Stripe
|
||||
window.Stripe = () => {};
|
||||
jest.spyOn(window, 'Stripe').mockImplementation(() => {
|
||||
return {
|
||||
redirectToCheckout: () => {
|
||||
return Promise.resolve({});
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
// Mock window.location
|
||||
let locationMock = jest.fn();
|
||||
delete window.location;
|
||||
window.location = {assign: locationMock};
|
||||
window.location.href = (new URL('https://portal.localhost')).href;
|
||||
});
|
||||
afterEach(() => {
|
||||
jest.restoreAllMocks();
|
||||
window.location.hash = '';
|
||||
});
|
||||
describe('#/portal', () => {
|
||||
test('opens default portal page', async () => {
|
||||
window.location.hash = '#/portal';
|
||||
let {
|
||||
popupFrame, triggerButtonFrame, ...utils
|
||||
} = await setup({
|
||||
site: FixtureSite.singleTier.basic,
|
||||
showPopup: false
|
||||
});
|
||||
expect(triggerButtonFrame).toBeInTheDocument();
|
||||
popupFrame = await utils.findByTitle(/portal-popup/i);
|
||||
expect(popupFrame).toBeInTheDocument();
|
||||
const signupTitle = within(popupFrame.contentDocument).queryByText(/already a member/i);
|
||||
expect(signupTitle).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe('#/portal/signin', () => {
|
||||
test('opens portal signin page', async () => {
|
||||
window.location.hash = '#/portal/signin';
|
||||
let {
|
||||
popupFrame, triggerButtonFrame, ...utils
|
||||
} = await setup({
|
||||
site: FixtureSite.singleTier.basic,
|
||||
showPopup: false
|
||||
});
|
||||
expect(triggerButtonFrame).toBeInTheDocument();
|
||||
popupFrame = await utils.findByTitle(/portal-popup/i);
|
||||
expect(popupFrame).toBeInTheDocument();
|
||||
const loginTitle = within(popupFrame.contentDocument).queryByText(/log in/i);
|
||||
expect(loginTitle).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe('#/portal/signup', () => {
|
||||
test('opens portal signup page', async () => {
|
||||
window.location.hash = '#/portal/signup';
|
||||
let {
|
||||
popupFrame, triggerButtonFrame, ...utils
|
||||
} = await setup({
|
||||
site: FixtureSite.singleTier.basic,
|
||||
showPopup: false
|
||||
});
|
||||
expect(triggerButtonFrame).toBeInTheDocument();
|
||||
popupFrame = await utils.findByTitle(/portal-popup/i);
|
||||
expect(popupFrame).toBeInTheDocument();
|
||||
const signupTitle = within(popupFrame.contentDocument).queryByText(/already a member/i);
|
||||
expect(signupTitle).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe('#/portal/account', () => {
|
||||
test('opens portal account home page', async () => {
|
||||
window.location.hash = '#/portal/account';
|
||||
let {
|
||||
popupFrame, triggerButtonFrame, ...utils
|
||||
} = await setup({
|
||||
site: FixtureSite.singleTier.basic,
|
||||
member: FixtureMember.free,
|
||||
showPopup: false
|
||||
});
|
||||
expect(triggerButtonFrame).toBeInTheDocument();
|
||||
popupFrame = await utils.findByTitle(/portal-popup/i);
|
||||
expect(popupFrame).toBeInTheDocument();
|
||||
const accountHomeTitle = within(popupFrame.contentDocument).queryByText(/your account/i);
|
||||
expect(accountHomeTitle).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe('#/portal/account/plans', () => {
|
||||
test('opens portal account plan page', async () => {
|
||||
window.location.hash = '#/portal/account/plans';
|
||||
let {
|
||||
popupFrame, triggerButtonFrame, ...utils
|
||||
} = await setup({
|
||||
site: FixtureSite.singleTier.basic,
|
||||
member: FixtureMember.free,
|
||||
showPopup: false
|
||||
});
|
||||
expect(triggerButtonFrame).toBeInTheDocument();
|
||||
popupFrame = await utils.findByTitle(/portal-popup/i);
|
||||
expect(popupFrame).toBeInTheDocument();
|
||||
const accountPlanTitle = within(popupFrame.contentDocument).queryByText(/choose a plan/i);
|
||||
expect(accountPlanTitle).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe('#/portal/account/profile', () => {
|
||||
test('opens portal account profile page', async () => {
|
||||
window.location.hash = '#/portal/account/profile';
|
||||
let {
|
||||
popupFrame, triggerButtonFrame, ...utils
|
||||
} = await setup({
|
||||
site: FixtureSite.singleTier.basic,
|
||||
member: FixtureMember.free,
|
||||
showPopup: false
|
||||
});
|
||||
expect(triggerButtonFrame).toBeInTheDocument();
|
||||
popupFrame = await utils.findByTitle(/portal-popup/i);
|
||||
expect(popupFrame).toBeInTheDocument();
|
||||
const accountProfileTitle = within(popupFrame.contentDocument).queryByText(/account settings/i);
|
||||
expect(accountProfileTitle).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Add table
Reference in a new issue