| 1 |
import { LaunchPage } from '@auto-launch/LaunchPage'; |
| 2 |
import { render, screen } from '@testing-library/react'; |
| 3 |
|
| 4 |
jest.mock('@auto-launch/components/Launch', () => ({ |
| 5 |
Launch: () => <div data-testid="launch" />, |
| 6 |
})); |
| 7 |
jest.mock('@auto-launch/components/Logo', () => ({ Logo: () => null })); |
| 8 |
jest.mock('@auto-launch/components/MovingGradients', () => ({ |
| 9 |
MovingGradient: () => null, |
| 10 |
})); |
| 11 |
jest.mock('@auto-launch/components/NeedsTheme', () => ({ |
| 12 |
NeedsTheme: () => null, |
| 13 |
})); |
| 14 |
jest.mock('@auto-launch/components/RestartLaunchModal', () => ({ |
| 15 |
RestartLaunchModal: () => null, |
| 16 |
})); |
| 17 |
jest.mock('@auto-launch/components/ViewportPulse', () => ({ |
| 18 |
ViewportPulse: () => null, |
| 19 |
})); |
| 20 |
jest.mock('@auto-launch/functions/wp', () => ({ updateOption: jest.fn() })); |
| 21 |
jest.mock('@auto-launch/functions/setup', () => ({ |
| 22 |
preLaunchFunctions: jest.fn(), |
| 23 |
})); |
| 24 |
jest.mock('@auto-launch/state/launch-data', () => ({ |
| 25 |
useLaunchDataStore: () => ({ |
| 26 |
title: null, |
| 27 |
descriptionRaw: null, |
| 28 |
go: false, |
| 29 |
urlParams: {}, |
| 30 |
designBuild: false, |
| 31 |
pulse: false, |
| 32 |
}), |
| 33 |
})); |
| 34 |
jest.mock('@wordpress/block-library', () => ({ |
| 35 |
registerCoreBlocks: jest.fn(), |
| 36 |
})); |
| 37 |
jest.mock('@wordpress/blocks', () => ({ getBlockTypes: () => [{}] })); |
| 38 |
jest.mock('@wordpress/data', () => ({ |
| 39 |
useSelect: () => ({ textdomain: 'extendable' }), |
| 40 |
})); |
| 41 |
jest.mock('framer-motion', () => ({ |
| 42 |
AnimatePresence: ({ children }) => <>{children}</>, |
| 43 |
motion: new Proxy( |
| 44 |
{}, |
| 45 |
{ get: () => (props) => <div {...props}>{props.children}</div> }, |
| 46 |
), |
| 47 |
})); |
| 48 |
jest.mock('@auto-launch/functions/insights', () => ({ checkIn: jest.fn() })); |
| 49 |
|
| 50 |
beforeAll(() => { |
| 51 |
window.extLaunchData = { |
| 52 |
resetSiteInformation: { pagesIds: [] }, |
| 53 |
urlParams: {}, |
| 54 |
hideAutoLaunchExitLink: false, |
| 55 |
}; |
| 56 |
}); |
| 57 |
|
| 58 |
afterAll(() => { |
| 59 |
delete window.extLaunchData; |
| 60 |
}); |
| 61 |
|
| 62 |
beforeEach(() => { |
| 63 |
window.extSharedData = { |
| 64 |
adminUrl: 'https://example.test/wp-admin/', |
| 65 |
}; |
| 66 |
}); |
| 67 |
|
| 68 |
describe('AutoLaunchPage — hideAutoLaunchExitLink flag', () => { |
| 69 |
test('shows the WP Admin Dashboard exit link when the flag is false', () => { |
| 70 |
render(<LaunchPage />); |
| 71 |
expect( |
| 72 |
screen.getByRole('link', { name: /WP Admin Dashboard/i }), |
| 73 |
).toBeInTheDocument(); |
| 74 |
}); |
| 75 |
|
| 76 |
test('hides the WP Admin Dashboard exit link when the flag is true', () => { |
| 77 |
window.extLaunchData.hideAutoLaunchExitLink = true; |
| 78 |
render(<LaunchPage />); |
| 79 |
expect( |
| 80 |
screen.queryByRole('link', { name: /WP Admin Dashboard/i }), |
| 81 |
).not.toBeInTheDocument(); |
| 82 |
}); |
| 83 |
}); |
| 84 |
|
| 85 |
describe('AutoLaunchPage — AutoLaunch.WebsiteTitle A/B test', () => { |
| 86 |
test('shows the alternate heading and subtitle for variant B', () => { |
| 87 |
window.extLaunchData.activeTests = { 'AutoLaunch.WebsiteTitle': 'B' }; |
| 88 |
render(<LaunchPage />); |
| 89 |
expect(screen.getByText(/Tell Us About Your Website/i)).toBeInTheDocument(); |
| 90 |
expect( |
| 91 |
screen.getByText(/Share your vision, and we'll craft a website/i), |
| 92 |
).toBeInTheDocument(); |
| 93 |
}); |
| 94 |
|
| 95 |
test('shows the current heading and no subtitle for variant A', () => { |
| 96 |
window.extLaunchData.activeTests = { 'AutoLaunch.WebsiteTitle': 'A' }; |
| 97 |
render(<LaunchPage />); |
| 98 |
expect( |
| 99 |
screen.getByText(/Describe the website you want to build/i), |
| 100 |
).toBeInTheDocument(); |
| 101 |
expect( |
| 102 |
screen.queryByText(/Share your vision, and we'll craft a website/i), |
| 103 |
).not.toBeInTheDocument(); |
| 104 |
}); |
| 105 |
|
| 106 |
test('shows the current heading when no assignment is present', () => { |
| 107 |
window.extLaunchData.activeTests = {}; |
| 108 |
render(<LaunchPage />); |
| 109 |
expect( |
| 110 |
screen.getByText(/Describe the website you want to build/i), |
| 111 |
).toBeInTheDocument(); |
| 112 |
}); |
| 113 |
}); |
| 114 |
|