<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css"
        integrity="sha512-SzlrxWUlpfuzQ+pcUCosxcglQRNAq/DZjVsC0lE40xsADsfeQoEypE+enwcOiGjk/bSuGGKHEyjSoQ1zVisanQ=="
        crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
</html>
import { LaunchPage } from '@auto-launch/LaunchPage';
import { render, screen } from '@testing-library/react';

jest.mock('@auto-launch/components/Launch', () => ({
	Launch: () => <div data-testid="launch" />,
}));
jest.mock('@auto-launch/components/Logo', () => ({ Logo: () => null }));
jest.mock('@auto-launch/components/MovingGradients', () => ({
	MovingGradient: () => null,
}));
jest.mock('@auto-launch/components/NeedsTheme', () => ({
	NeedsTheme: () => null,
}));
jest.mock('@auto-launch/components/RestartLaunchModal', () => ({
	RestartLaunchModal: () => null,
}));
jest.mock('@auto-launch/components/ViewportPulse', () => ({
	ViewportPulse: () => null,
}));
jest.mock('@auto-launch/functions/wp', () => ({ updateOption: jest.fn() }));
jest.mock('@auto-launch/state/launch-data', () => ({
	useLaunchDataStore: () => ({
		title: null,
		descriptionRaw: null,
		go: false,
		urlParams: {},
		designBuild: false,
		pulse: false,
	}),
}));
jest.mock('@wordpress/block-library', () => ({
	registerCoreBlocks: jest.fn(),
}));
jest.mock('@wordpress/blocks', () => ({ getBlockTypes: () => [{}] }));
jest.mock('@wordpress/data', () => ({
	useSelect: () => ({ textdomain: 'extendable' }),
}));
jest.mock('framer-motion', () => ({
	AnimatePresence: ({ children }) => <>{children}</>,
	motion: new Proxy(
		{},
		{ get: () => (props) => <div {...props}>{props.children}</div> },
	),
}));
jest.mock('@auto-launch/functions/insights', () => ({ checkIn: jest.fn() }));

beforeAll(() => {
	window.extLaunchData = {
		resetSiteInformation: { pagesIds: [] },
		urlParams: {},
		hideAutoLaunchExitLink: false,
	};
});

afterAll(() => {
	delete window.extLaunchData;
});

beforeEach(() => {
	window.extSharedData = {
		adminUrl: 'https://example.test/wp-admin/',
	};
});

describe('AutoLaunchPage — hideAutoLaunchExitLink flag', () => {
	test('shows the WP Admin Dashboard exit link when the flag is false', () => {
		render(<LaunchPage />);
		expect(
			screen.getByRole('link', { name: /WP Admin Dashboard/i }),
		).toBeInTheDocument();
	});

	test('hides the WP Admin Dashboard exit link when the flag is true', () => {
		window.extLaunchData.hideAutoLaunchExitLink = true;
		render(<LaunchPage />);
		expect(
			screen.queryByRole('link', { name: /WP Admin Dashboard/i }),
		).not.toBeInTheDocument();
	});
});
