import { readFileSync } from 'fs';
import { resolve } from 'path';

describe( 'admin entrypoint', () => {
	it( 'mounts the shared admin application with admin app CSS', () => {
		const source = readFileSync( resolve( __dirname, 'index.ts' ), 'utf8' );

		expect( source ).toContain( "import AdminApp from './app/AdminApp';" );
		expect( source ).toContain(
			"import './app/admin/styles/product.scss';"
		);
		expect( source ).not.toContain( "import './styles/admin.scss';" );
		expect( source ).toContain(
			"document.getElementById( 'scheduled-changes-admin-root' )"
		);
		expect( source ).toContain( 'window.scheduledChangesAdmin' );
	} );

	it( 'builds the same admin entrypoint for source and wporg packaging', () => {
		const root = resolve( __dirname, '../..' );
		const source = readFileSync(
			resolve( root, 'webpack.config.js' ),
			'utf8'
		);

		expect( source ).toContain( 'assets/src/index.ts' );
		expect( source ).not.toContain( 'full-admin-index' );
		expect( source ).not.toContain( 'SCHEDULED_CHANGES_ADMIN_ENTRY' );
		expect( source ).not.toContain( 'core-admin-app' );
	} );
} );
