Commit 1c17e53135a for woocommerce

commit 1c17e53135a5c2859a1d405fd0102367b1249c71
Author: Pavel Dohnal <pavel.dohnal@automattic.com>
Date:   Wed Nov 25 08:17:15 2026 +0100

    Test the email editor's JavaScript store, styles and MailPoet contract (#71312)

    * Test the email editor store selectors and guard two missing fields

    hasEmptyContent() crashed on a post record without content, and
    getEmailTemplates() on a template without post types, which the API
    can return. Adds tests for the selectors that decide what the editor
    shows: empty and sent state, content, templates and recent emails.

    * Test the email editor store reducer

    Covers the actions that merge into existing state (preview, URLs,
    editor config) so a change can't drop the values they keep.

    * Keep 0, false and numbers in saved email styles

    The style cleanup checked for empty values with Object.keys(), which
    is empty for numbers and booleans, so a line height of 1.5 or a radius
    of 0 was dropped, together with its whole group. Tests the helpers.

    * Test the email content validation rules

    Covers the rules integrations add through the content validation
    filter: a failing rule blocks sending with a notice, a passing rule
    removes its old notice, and the template content is checked too.

    * Test the email editor's block settings, filter and format helpers

    These decide which blocks and formats a merchant gets in the email
    editor and must undo their changes when the editor closes.

    * Test the email editor event pipeline

    Events must not be sent while tracking is off, once-only events must
    fire once, and non-object data is wrapped.

    * Test the template picker and the reset template action

    The picker must show only the chosen category and the empty state for
    recent emails. Reset is offered only for customized plugin or theme
    templates the user may delete, and a failed reset keeps the template.

    * Test when the email editor warns about background images

    The warning shows only for blocks that support background images,
    which email clients often do not display.

    * Pin the email editor exports, store and hooks that MailPoet's JS uses

    A renamed export, store name or hook would break MailPoet's editor
    integration with every check here still green. The list comes from
    MailPoet's assets; the source is read with the TypeScript parser.

    * Treat null like an empty value in the email style cleanup

    A null left in saved styles would replace the theme default when the
    styles are merged.

    * Make the reset, block settings and contract tests check what they claim

    The reset test now checks the save and the restored content, the block
    settings test checks the update is applied, and the contract test takes
    the fewest arguments a hook gets, so one call site dropping one fails.

    * Simplify the empty check in the email style cleanup

    Children are cleaned before the check, so any key left holds a value.
    The changelog now also says empty values are dropped without an error.

    * Check the reset writes back the template loaded from the file

    The test only checked what was read, so writing an empty template
    would still pass.

    * Check the template reset saves before it deletes the custom copy

    Deleting first would lose the template if the save then failed.
    Suggested by CodeRabbit.

    * Fail the style cleanup test when a key is left as undefined

    * Pin registerEntityAction in the MailPoet contract test

diff --git a/packages/js/email-editor/changelog/email-editor-js-test-coverage b/packages/js/email-editor/changelog/email-editor-js-test-coverage
new file mode 100644
index 00000000000..215fe116dc4
--- /dev/null
+++ b/packages/js/email-editor/changelog/email-editor-js-test-coverage
@@ -0,0 +1,4 @@
+Significance: patch
+Type: dev
+Comment: Add tests for the email editor store, style helpers, block settings and events; no production change.
+
diff --git a/packages/js/email-editor/changelog/fix-email-editor-missing-fields b/packages/js/email-editor/changelog/fix-email-editor-missing-fields
new file mode 100644
index 00000000000..3584d380d49
--- /dev/null
+++ b/packages/js/email-editor/changelog/fix-email-editor-missing-fields
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Prevent the email editor from failing when an email has no content field or a template has no post types.
diff --git a/packages/js/email-editor/changelog/fix-email-editor-style-cleanup-zero b/packages/js/email-editor/changelog/fix-email-editor-style-cleanup-zero
new file mode 100644
index 00000000000..2111186e7bc
--- /dev/null
+++ b/packages/js/email-editor/changelog/fix-email-editor-style-cleanup-zero
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Keep email style values set to 0, false or a number, and drop empty ones without an error, when the email editor saves styles.
diff --git a/packages/js/email-editor/src/components/sidebar/test/block-compatibility-warnings.spec.tsx b/packages/js/email-editor/src/components/sidebar/test/block-compatibility-warnings.spec.tsx
new file mode 100644
index 00000000000..55e81519709
--- /dev/null
+++ b/packages/js/email-editor/src/components/sidebar/test/block-compatibility-warnings.spec.tsx
@@ -0,0 +1,30 @@
+/**
+ * External dependencies
+ */
+import { getBlockSupport } from '@wordpress/blocks';
+
+/**
+ * Internal dependencies
+ */
+import { hasBackgroundImageSupport } from '../block-compatibility-warnings';
+
+jest.mock( '@wordpress/blocks', () => ( { getBlockSupport: jest.fn() } ) );
+
+describe( 'hasBackgroundImageSupport', () => {
+	it.each( [
+		[ 'supports background images', { backgroundImage: true }, true ],
+		[ 'has background support without saying otherwise', {}, true ],
+		[ 'turns background images off', { backgroundImage: false }, false ],
+		[ 'has no background support', undefined, false ],
+	] )( 'warns when the block %s: %s', ( _case, support, expected ) => {
+		( getBlockSupport as jest.Mock ).mockReturnValue( support );
+
+		expect( Boolean( hasBackgroundImageSupport( 'core/group' ) ) ).toBe(
+			expected
+		);
+		expect( getBlockSupport ).toHaveBeenCalledWith(
+			'core/group',
+			'background'
+		);
+	} );
+} );
diff --git a/packages/js/email-editor/src/components/sidebar/test/reset-email-template.spec.tsx b/packages/js/email-editor/src/components/sidebar/test/reset-email-template.spec.tsx
new file mode 100644
index 00000000000..9d7364996e8
--- /dev/null
+++ b/packages/js/email-editor/src/components/sidebar/test/reset-email-template.spec.tsx
@@ -0,0 +1,183 @@
+/**
+ * External dependencies
+ */
+import { act, render, screen, waitFor } from '@testing-library/react';
+import '@testing-library/jest-dom';
+import apiFetch from '@wordpress/api-fetch';
+import { useDispatch } from '@wordpress/data';
+import { parse, serialize } from '@wordpress/blocks';
+
+/**
+ * Internal dependencies
+ */
+import getResetEmailTemplateAction from '../reset-email-template';
+
+jest.mock( '@wordpress/api-fetch', () => jest.fn() );
+jest.mock( '@wordpress/data', () => ( { useDispatch: jest.fn() } ) );
+jest.mock( '@wordpress/notices', () => ( {
+	store: { name: 'core/notices' },
+} ) );
+jest.mock( '@wordpress/core-data', () => ( { store: { name: 'core' } } ) );
+jest.mock( '@wordpress/blocks', () => ( {
+	parse: jest.fn( () => [ { name: 'core/paragraph' } ] ),
+	serialize: jest.fn( () => '<!-- default -->' ),
+} ) );
+jest.mock( '@wordpress/components', () => ( {
+	Button: ( { children, onClick, disabled } ) => (
+		<button onClick={ onClick } disabled={ disabled }>
+			{ children }
+		</button>
+	),
+} ) );
+jest.mock( '../../../events', () => ( { recordEvent: jest.fn() } ) );
+
+const apiFetchMock = apiFetch as unknown as jest.Mock;
+
+const template = {
+	id: 'woocommerce//order-email',
+	type: 'wp_template',
+	source: 'custom',
+	origin: 'plugin',
+	plugin: 'woocommerce',
+	has_theme_file: false,
+	title: 'Order &amp; shipping',
+	permissions: { delete: true },
+};
+
+describe( 'reset email template action', () => {
+	const action = getResetEmailTemplateAction();
+
+	it.each( [
+		[ 'a customized plugin template', {}, true ],
+		[
+			'a customized theme template',
+			{ plugin: '', has_theme_file: true },
+			true,
+		],
+		[ 'a template that was never customized', { source: 'plugin' }, false ],
+		[ 'a template only the user created', { plugin: '' }, false ],
+		[ 'something other than a template', { type: 'woo_email' }, false ],
+		[
+			'a template the user may not delete',
+			{ permissions: { delete: false } },
+			false,
+		],
+	] )( 'offers reset for %s: %s', ( _case, changes, expected ) => {
+		expect(
+			Boolean(
+				action.isEligible( {
+					...template,
+					...changes,
+				} as never )
+			)
+		).toBe( expected );
+	} );
+
+	describe( 'confirming the reset', () => {
+		// The click starts an async save, so wait for it inside act().
+		const clickReset = async () => {
+			const button = screen.getByRole( 'button', { name: 'Reset' } );
+			await act( async () => {
+				button.click();
+			} );
+		};
+
+		const dispatch = {
+			createSuccessNotice: jest.fn(),
+			createErrorNotice: jest.fn(),
+			invalidateResolution: jest.fn(),
+			editEntityRecord: jest.fn(),
+			saveEditedEntityRecord: jest.fn(),
+		};
+		const closeModal = jest.fn();
+		const onActionPerformed = jest.fn();
+
+		beforeEach( () => {
+			jest.clearAllMocks();
+			apiFetchMock.mockReset();
+			( useDispatch as jest.Mock ).mockReturnValue( dispatch );
+			const { RenderModal } = action;
+			render(
+				<RenderModal
+					items={ [ template ] }
+					closeModal={ closeModal }
+					onActionPerformed={ onActionPerformed }
+				/>
+			);
+		} );
+
+		it( 'saves the file template content, deletes the custom copy and confirms', async () => {
+			apiFetchMock.mockResolvedValueOnce( {
+				content: { raw: '<!-- default -->' },
+			} );
+			apiFetchMock.mockResolvedValueOnce( {} );
+			let finishSave: () => void;
+			dispatch.saveEditedEntityRecord.mockReturnValueOnce(
+				new Promise< void >( ( resolve ) => {
+					finishSave = resolve;
+				} )
+			);
+
+			await clickReset();
+
+			// The custom copy may only be deleted once the save has finished.
+			expect( dispatch.saveEditedEntityRecord ).toHaveBeenCalled();
+			expect( apiFetchMock ).toHaveBeenCalledTimes( 1 );
+			expect( dispatch.createSuccessNotice ).not.toHaveBeenCalled();
+			await act( async () => finishSave() );
+
+			await waitFor( () => expect( closeModal ).toHaveBeenCalled() );
+			expect( apiFetchMock ).toHaveBeenNthCalledWith( 1, {
+				path: '/wp/v2/templates/woocommerce//order-email?context=edit&source=plugin',
+			} );
+			expect( parse ).toHaveBeenCalledWith( '<!-- default -->' );
+			expect( dispatch.saveEditedEntityRecord ).toHaveBeenCalledWith(
+				'postType',
+				'wp_template',
+				template.id,
+				{}
+			);
+			expect( dispatch.editEntityRecord ).toHaveBeenCalledWith(
+				'postType',
+				'wp_template',
+				template.id,
+				{
+					blocks: [ { name: 'core/paragraph' } ],
+					content: '<!-- default -->',
+					source: 'plugin',
+				}
+			);
+			expect( serialize ).toHaveBeenCalledWith( [
+				{ name: 'core/paragraph' },
+			] );
+			expect( apiFetchMock ).toHaveBeenNthCalledWith( 2, {
+				path: '/wp/v2/templates/woocommerce//order-email',
+				method: 'DELETE',
+			} );
+			expect( dispatch.invalidateResolution ).toHaveBeenCalledWith(
+				'getEntityRecord',
+				[ 'postType', 'wp_template', template.id ]
+			);
+			expect( dispatch.createSuccessNotice ).toHaveBeenCalledWith(
+				'"Order & shipping" reset to default.',
+				expect.anything()
+			);
+			expect( onActionPerformed ).toHaveBeenCalledWith( [ template ] );
+		} );
+
+		it( 'shows the error and keeps the template when the reset fails', async () => {
+			apiFetchMock.mockRejectedValueOnce( new Error( 'Server error.' ) );
+
+			await clickReset();
+
+			await waitFor( () => expect( closeModal ).toHaveBeenCalled() );
+			expect( dispatch.createErrorNotice ).toHaveBeenCalledWith(
+				'Server error.',
+				expect.anything()
+			);
+			expect( dispatch.saveEditedEntityRecord ).not.toHaveBeenCalled();
+			expect( dispatch.createSuccessNotice ).not.toHaveBeenCalled();
+			expect( onActionPerformed ).not.toHaveBeenCalled();
+		} );
+	} );
+} );
diff --git a/packages/js/email-editor/src/components/template-select/test/template-list.spec.tsx b/packages/js/email-editor/src/components/template-select/test/template-list.spec.tsx
new file mode 100644
index 00000000000..5c543c3ec3a
--- /dev/null
+++ b/packages/js/email-editor/src/components/template-select/test/template-list.spec.tsx
@@ -0,0 +1,79 @@
+/**
+ * External dependencies
+ */
+import { render, screen } from '@testing-library/react';
+import '@testing-library/jest-dom';
+
+/**
+ * Internal dependencies
+ */
+import { TemplateList } from '../template-list';
+import type { TemplatePreview } from '../../../store';
+
+jest.mock( '@wordpress/editor', () => ( { store: { name: 'core/editor' } } ) );
+jest.mock( '@wordpress/data', () => ( {
+	...jest.requireActual( '@wordpress/data' ),
+	useSelect: jest.fn( () => ( { layout: undefined } ) ),
+} ) );
+jest.mock( '@wordpress/block-editor', () => ( {
+	BlockPreview: () => null,
+} ) );
+jest.mock( '../async', () => ( {
+	Async: ( { children } ) => children,
+} ) );
+jest.mock( '../../../hooks', () => ( { useEmailCss: () => [ [] ] } ) );
+jest.mock( '../../../store', () => ( {} ) );
+
+const template = ( id: number, category: string ) =>
+	( {
+		id,
+		slug: `template-${ id }`,
+		displayName: `Template ${ id }`,
+		category,
+		previewContentParsed: [],
+	} ) as unknown as TemplatePreview;
+
+describe( 'TemplateList', () => {
+	const templates = [
+		template( 1, 'basic' ),
+		template( 2, 'welcome' ),
+		template( 3, 'basic' ),
+	];
+
+	it( 'shows only the templates of the selected category', () => {
+		render(
+			<TemplateList
+				templates={ templates }
+				onTemplateSelection={ jest.fn() }
+				selectedCategory="basic"
+			/>
+		);
+
+		expect(
+			screen.getAllByRole( 'heading' ).map( ( h ) => h.textContent )
+		).toEqual( [ 'Template 1', 'Template 3' ] );
+	} );
+
+	it( 'shows the empty state and the legacy notice for a recent category without emails', () => {
+		render(
+			<TemplateList
+				templates={ templates }
+				onTemplateSelection={ jest.fn() }
+				selectedCategory="recent"
+			/>
+		);
+
+		expect(
+			screen.getByText( 'No recent templates.' )
+		).toBeInTheDocument();
+		// The notice repeats its text for screen readers.
+		expect(
+			screen.getAllByText(
+				'Templates created on the legacy editor will not appear here.'
+			).length
+		).toBeGreaterThan( 0 );
+		expect( screen.queryAllByRole( 'heading', { level: 4 } ) ).toHaveLength(
+			0
+		);
+	} );
+} );
diff --git a/packages/js/email-editor/src/config-tools/test/config-tools.spec.ts b/packages/js/email-editor/src/config-tools/test/config-tools.spec.ts
new file mode 100644
index 00000000000..77398a46b2e
--- /dev/null
+++ b/packages/js/email-editor/src/config-tools/test/config-tools.spec.ts
@@ -0,0 +1,153 @@
+/**
+ * External dependencies
+ */
+import {
+	getBlockType,
+	registerBlockType,
+	unregisterBlockType,
+} from '@wordpress/blocks';
+import { applyFilters, addFilter, removeAllFilters } from '@wordpress/hooks';
+import { registerFormatType, unregisterFormatType } from '@wordpress/rich-text';
+
+/**
+ * Internal dependencies
+ */
+import {
+	restoreAllModifiedBlockSettings,
+	updateBlockSettings,
+} from '../block-config';
+import { addFilterForEmail, clearEmailFilters } from '../filters';
+import {
+	registerFormatForEmail,
+	resetFormats,
+	unregisterFormatForEmail,
+} from '../formats';
+
+jest.mock( '@wordpress/blocks', () => ( {
+	getBlockType: jest.fn(),
+	registerBlockType: jest.fn(),
+	unregisterBlockType: jest.fn(),
+} ) );
+jest.mock( '@wordpress/rich-text', () => ( {
+	registerFormatType: jest.fn(),
+	unregisterFormatType: jest.fn(),
+} ) );
+
+describe( 'email editor config tools', () => {
+	afterEach( () => {
+		jest.clearAllMocks();
+	} );
+
+	describe( 'updateBlockSettings', () => {
+		afterEach( () => restoreAllModifiedBlockSettings() );
+
+		it( 'returns false for a block that is not registered', () => {
+			( getBlockType as jest.Mock ).mockReturnValue( undefined );
+
+			expect( updateBlockSettings( 'core/missing', () => ( {} ) ) ).toBe(
+				false
+			);
+			expect( registerBlockType ).not.toHaveBeenCalled();
+		} );
+
+		it( 'restores the settings the block had before the first update', () => {
+			( getBlockType as jest.Mock )
+				.mockReturnValueOnce( {
+					name: 'core/quote',
+					title: 'Original',
+					category: 'text',
+				} )
+				.mockReturnValueOnce( {
+					name: 'core/quote',
+					title: 'First',
+					category: 'text',
+				} );
+
+			expect(
+				updateBlockSettings( 'core/quote', () => ( {
+					title: 'First',
+				} ) )
+			).toBe( true );
+			expect( registerBlockType ).toHaveBeenCalledWith( 'core/quote', {
+				title: 'First',
+				category: 'text',
+			} );
+			updateBlockSettings( 'core/quote', () => ( { title: 'Second' } ) );
+			( registerBlockType as jest.Mock ).mockClear();
+
+			expect( restoreAllModifiedBlockSettings() ).toEqual( [
+				'core/quote',
+			] );
+			expect( unregisterBlockType ).toHaveBeenCalledWith( 'core/quote' );
+			expect( registerBlockType ).toHaveBeenCalledWith( 'core/quote', {
+				title: 'Original',
+				category: 'text',
+			} );
+			expect( restoreAllModifiedBlockSettings() ).toEqual( [] );
+		} );
+
+		it( 'returns false and logs when the block cannot be registered again', () => {
+			const error = jest.spyOn( console, 'error' ).mockImplementation();
+			( getBlockType as jest.Mock ).mockReturnValue( {
+				name: 'core/quote',
+			} );
+			( registerBlockType as jest.Mock ).mockImplementationOnce( () => {
+				throw new Error( 'invalid settings' );
+			} );
+
+			expect( updateBlockSettings( 'core/quote', () => ( {} ) ) ).toBe(
+				false
+			);
+			expect( error ).toHaveBeenCalled();
+			error.mockRestore();
+		} );
+	} );
+
+	describe( 'clearEmailFilters', () => {
+		afterEach( () => removeAllFilters( 'test_hook' ) );
+
+		it( 'removes only the filters added for the email editor', () => {
+			addFilter(
+				'test_hook',
+				'site/plugin',
+				( value: string ) => value + '-site'
+			);
+			addFilterForEmail(
+				'test_hook',
+				'email/editor',
+				( value: string ) => value + '-email'
+			);
+
+			expect( applyFilters( 'test_hook', 'x' ) ).toBe( 'x-site-email' );
+			clearEmailFilters();
+			expect( applyFilters( 'test_hook', 'x' ) ).toBe( 'x-site' );
+		} );
+	} );
+
+	describe( 'resetFormats', () => {
+		it( 'removes formats the email editor added and brings back the ones it removed', () => {
+			const bold = { name: 'core/bold', tagName: 'strong' };
+			( unregisterFormatType as jest.Mock ).mockReturnValueOnce( bold );
+			unregisterFormatForEmail( 'core/bold' );
+			registerFormatForEmail( 'email/tag', {
+				name: 'email/tag',
+				tagName: 'span',
+				interactive: false,
+				title: 'Tag',
+				edit: null,
+			} );
+			jest.clearAllMocks();
+
+			resetFormats();
+
+			expect( unregisterFormatType ).toHaveBeenCalledWith( 'email/tag' );
+			expect( registerFormatType ).toHaveBeenCalledWith( 'core/bold', {
+				object: false,
+				...bold,
+			} );
+			jest.clearAllMocks();
+			resetFormats();
+			expect( registerFormatType ).not.toHaveBeenCalled();
+		} );
+	} );
+} );
diff --git a/packages/js/email-editor/src/events/test/event-pipeline.spec.ts b/packages/js/email-editor/src/events/test/event-pipeline.spec.ts
new file mode 100644
index 00000000000..dd00afe13cc
--- /dev/null
+++ b/packages/js/email-editor/src/events/test/event-pipeline.spec.ts
@@ -0,0 +1,61 @@
+/**
+ * External dependencies
+ */
+import { addFilter, removeAllFilters } from '@wordpress/hooks';
+
+/**
+ * Internal dependencies
+ */
+import {
+	dispatcher,
+	EMAIL_STRING,
+	recordEvent,
+	recordEventOnce,
+} from '../event-pipeline';
+
+const HOOK = 'woocommerce_email_editor_events_tracking_enabled';
+
+describe( 'event pipeline', () => {
+	let received: Record< string, unknown >[];
+	const listener = ( event: Event ) =>
+		received.push( ( event as CustomEvent ).detail );
+
+	beforeEach( () => {
+		received = [];
+		dispatcher.addEventListener( EMAIL_STRING, listener );
+	} );
+
+	afterEach( () => {
+		dispatcher.removeEventListener( EMAIL_STRING, listener );
+		removeAllFilters( HOOK );
+	} );
+
+	it( 'sends nothing while tracking is off', () => {
+		recordEvent( 'opened', { id: 1 } );
+		recordEventOnce( 'opened_once' );
+
+		expect( received ).toEqual( [] );
+	} );
+
+	it( 'prefixes the event name and wraps data that is not an object', () => {
+		addFilter( HOOK, 'test', () => true );
+
+		recordEvent( 'opened', { id: 1 } );
+		recordEvent( 'clicked', 'button' as unknown as object );
+
+		expect( received ).toEqual( [
+			{ name: 'email_editor_events_opened', id: 1 },
+			{ name: 'email_editor_events_clicked', data: 'button' },
+		] );
+	} );
+
+	it( 'sends a once-only event a single time for the same name and data size', () => {
+		addFilter( HOOK, 'test', () => true );
+
+		recordEventOnce( 'loaded', { a: 1 } );
+		recordEventOnce( 'loaded', { a: 1 } );
+		recordEventOnce( 'loaded', { a: 12 } );
+
+		expect( received ).toHaveLength( 2 );
+	} );
+} );
diff --git a/packages/js/email-editor/src/hooks/test/use-content-validation.spec.ts b/packages/js/email-editor/src/hooks/test/use-content-validation.spec.ts
new file mode 100644
index 00000000000..a9046bee207
--- /dev/null
+++ b/packages/js/email-editor/src/hooks/test/use-content-validation.spec.ts
@@ -0,0 +1,97 @@
+/**
+ * External dependencies
+ */
+import { addFilter, removeAllFilters } from '@wordpress/hooks';
+
+/**
+ * Internal dependencies
+ */
+import { validateEmailContent } from '../use-content-validation';
+
+// The hook's imports pull in the block editor, which Jest cannot transform.
+// Only the pure validateEmailContent function is under test.
+jest.mock( '@wordpress/data', () => ( {
+	useSelect: jest.fn(),
+	subscribe: jest.fn(),
+	dispatch: jest.fn(),
+} ) );
+jest.mock( '@wordpress/core-data', () => ( { store: { name: 'core' } } ) );
+jest.mock( '../../store', () => ( { storeName: 'email-editor/editor' } ) );
+jest.mock( '../use-validation-notices', () => ( {
+	useValidationNotices: jest.fn(),
+} ) );
+
+const HOOK = 'woocommerce_email_editor_content_validation_rules';
+
+function notices( existing: string[] = [] ) {
+	return {
+		addValidationNotice: jest.fn(),
+		hasValidationNotice: jest.fn( ( id?: string ) =>
+			existing.includes( id ?? '' )
+		),
+		removeValidationNotice: jest.fn(),
+	};
+}
+
+function setRules( rules ) {
+	addFilter( HOOK, 'test', () => rules );
+}
+
+describe( 'validateEmailContent', () => {
+	afterEach( () => removeAllFilters( HOOK ) );
+
+	it( 'passes when no rules are registered', () => {
+		const handlers = notices();
+
+		expect( validateEmailContent( '<p>Hi</p>', '', handlers ) ).toBe(
+			true
+		);
+		expect( handlers.addValidationNotice ).not.toHaveBeenCalled();
+	} );
+
+	it( 'fails and adds a notice when a rule finds a problem in the email or its template', () => {
+		const testContent = jest.fn(
+			( content: string ) => ! content.includes( 'unsubscribe' )
+		);
+		setRules( [
+			{
+				id: 'missing-link',
+				testContent,
+				message: 'Add a link',
+				actions: [ 'fix' ],
+			},
+		] );
+		const handlers = notices();
+
+		expect(
+			validateEmailContent( '<p>Body</p>', '<footer />', handlers )
+		).toBe( false );
+		expect( testContent ).toHaveBeenCalledWith( '<p>Body</p><footer />' );
+		expect( handlers.addValidationNotice ).toHaveBeenCalledWith(
+			'missing-link',
+			'Add a link',
+			[ 'fix' ]
+		);
+	} );
+
+	it( 'removes the notice of a rule that passes again', () => {
+		setRules( [
+			{
+				id: 'missing-link',
+				testContent: () => false,
+				message: '',
+				actions: [],
+			},
+			{ id: 'other', testContent: () => false, message: '', actions: [] },
+		] );
+		const handlers = notices( [ 'missing-link' ] );
+
+		expect(
+			validateEmailContent( '<a>unsubscribe</a>', '', handlers )
+		).toBe( true );
+		expect( handlers.removeValidationNotice ).toHaveBeenCalledTimes( 1 );
+		expect( handlers.removeValidationNotice ).toHaveBeenCalledWith(
+			'missing-link'
+		);
+	} );
+} );
diff --git a/packages/js/email-editor/src/hooks/test/use-email-styles.spec.ts b/packages/js/email-editor/src/hooks/test/use-email-styles.spec.ts
new file mode 100644
index 00000000000..5392f761d97
--- /dev/null
+++ b/packages/js/email-editor/src/hooks/test/use-email-styles.spec.ts
@@ -0,0 +1,99 @@
+/**
+ * Internal dependencies
+ */
+import {
+	cleanupUserStyles,
+	setImmutably,
+	shortenWpPresetVariables,
+} from '../use-email-styles';
+
+jest.mock( '../../store', () => ( { storeName: 'email-editor/editor' } ) );
+jest.mock( '../use-user-theme', () => ( { useUserTheme: jest.fn() } ) );
+
+describe( 'email style helpers', () => {
+	describe( 'setImmutably', () => {
+		it( 'sets a nested value without changing the original object', () => {
+			const original = { color: { text: '#000' }, spacing: {} };
+
+			const next = setImmutably(
+				original,
+				[ 'color', 'background' ],
+				'#fff'
+			);
+
+			expect( next ).toEqual( {
+				color: { text: '#000', background: '#fff' },
+				spacing: {},
+			} );
+			expect( original ).toEqual( {
+				color: { text: '#000' },
+				spacing: {},
+			} );
+			expect( next.spacing ).toBe( original.spacing );
+		} );
+
+		it( 'creates missing levels and accepts a single key or an array', () => {
+			expect( setImmutably( undefined, [ 'a', 'b' ], 1 ) ).toEqual( {
+				a: { b: 1 },
+			} );
+			expect( setImmutably( { a: 1 }, 'b', 2 ) ).toEqual( {
+				a: 1,
+				b: 2,
+			} );
+			expect( setImmutably( [ 1, 2 ], 0, 9 ) ).toEqual( [ 9, 2 ] );
+		} );
+	} );
+
+	describe( 'shortenWpPresetVariables', () => {
+		it( 'shortens preset variables at any depth and leaves other values alone', () => {
+			expect(
+				shortenWpPresetVariables( {
+					color: { text: 'var(--wp--preset--color--accent-1)' },
+					spacing: {
+						padding: { top: 'var(--wp--preset--spacing--10)' },
+						margin: 'calc(10px + 2px)',
+					},
+					size: 12,
+				} )
+			).toEqual( {
+				color: { text: 'var:preset|color|accent-1' },
+				spacing: {
+					padding: { top: 'var:preset|spacing|10' },
+					margin: 'calc(10px + 2px)',
+				},
+				size: 12,
+			} );
+		} );
+	} );
+
+	describe( 'cleanupUserStyles', () => {
+		it( 'removes empty arrays, empty strings, null and undefined values and empty nested objects', () => {
+			expect(
+				cleanupUserStyles( {
+					color: {
+						text: '#000',
+						gradient: undefined,
+						background: '',
+						link: null,
+					},
+					elements: { link: { color: {} } },
+					blocks: [],
+				} )
+			).toStrictEqual( { color: { text: '#000' } } );
+		} );
+
+		it( 'keeps zero, false and other numbers set by the user', () => {
+			expect(
+				cleanupUserStyles( {
+					typography: { lineHeight: 1.5, letterSpacing: 0 },
+					border: { radius: 0 },
+					custom: { enabled: false },
+				} )
+			).toStrictEqual( {
+				typography: { lineHeight: 1.5, letterSpacing: 0 },
+				border: { radius: 0 },
+				custom: { enabled: false },
+			} );
+		} );
+	} );
+} );
diff --git a/packages/js/email-editor/src/hooks/use-email-styles.ts b/packages/js/email-editor/src/hooks/use-email-styles.ts
index 75aabd7f319..218c00e3274 100644
--- a/packages/js/email-editor/src/hooks/use-email-styles.ts
+++ b/packages/js/email-editor/src/hooks/use-email-styles.ts
@@ -30,10 +30,15 @@ interface EmailStylesData {
  * @return {boolean} True if the nested object is empty, false otherwise.
  */
 function isNestedEmpty( obj ) {
-	const isNotEmpty = Object.keys( obj ).some(
-		( key ) => Object.keys( obj[ key ] ).length > 0
-	);
-	return ! isNotEmpty;
+	// An empty string or null is unset; other plain values (0, false, numbers) are set.
+	if ( obj === null ) {
+		return true;
+	}
+	if ( typeof obj !== 'object' ) {
+		return obj === '';
+	}
+	// Children are already cleaned, so any key left holds a value.
+	return Object.keys( obj ).length === 0;
 }

 /**
@@ -78,7 +83,7 @@ export function setImmutably( setObject, setPath, value ): typeof setObject {
  * @param {Object} obj The object to shorten the variable names in.
  * @return {Object} The object with the shortened variable names.
  */
-function shortenWpPresetVariables( obj ) {
+export function shortenWpPresetVariables( obj ) {
 	// Helper function to replace the variable string
 	const replaceVariable = ( value ) => {
 		return value.replace(
@@ -114,7 +119,7 @@ function shortenWpPresetVariables( obj ) {
  * @param {Object} obj The object to clean.
  * @return {Object} The cleaned object.
  */
-function cleanupUserStyles( obj ) {
+export function cleanupUserStyles( obj ) {
 	const cleanObject = ( current ) => {
 		if (
 			( typeof current === 'object' && current !== null ) ||
diff --git a/packages/js/email-editor/src/store/selectors.ts b/packages/js/email-editor/src/store/selectors.ts
index 18a06932dcf..3cbabc9f78d 100644
--- a/packages/js/email-editor/src/store/selectors.ts
+++ b/packages/js/email-editor/src/store/selectors.ts
@@ -135,8 +135,7 @@ export const hasEmptyContent = createRegistrySelector(
 		}

 		// @ts-expect-error Missing property in type
-		const { content } = post;
-		return ! content.raw;
+		return ! post.content?.raw;
 	}
 );

@@ -402,7 +401,7 @@ export const getEmailTemplates = createRegistrySelector( ( select ) => {
 				// ignoring the post_type filter in the query
 				?.filter( ( template ) =>
 					// @ts-expect-error Missing property in type
-					template.post_types.includes( postType )
+					template.post_types?.includes( postType )
 				),
 		() => [
 			select( coreDataStore ).getEntityRecords(
diff --git a/packages/js/email-editor/src/store/test/reducer.spec.ts b/packages/js/email-editor/src/store/test/reducer.spec.ts
new file mode 100644
index 00000000000..861eb4bad23
--- /dev/null
+++ b/packages/js/email-editor/src/store/test/reducer.spec.ts
@@ -0,0 +1,68 @@
+/**
+ * Internal dependencies
+ */
+import { reducer } from '../reducer';
+import { State } from '../types';
+
+const state = {
+	preview: { toEmail: 'old@example.com', isModalOpened: false },
+	urls: { listings: '/listings', send: '/send' },
+	styles: { globalStylesPostId: 5, other: 'kept' },
+	theme: { styles: {} },
+	editorSettings: { old: true },
+	postId: 1,
+	postType: 'woo_email',
+} as unknown as State;
+
+describe( 'email editor store reducer', () => {
+	it( 'merges a preview change into the existing preview state', () => {
+		const next = reducer( state, {
+			type: 'CHANGE_PREVIEW_STATE',
+			state: { isModalOpened: true },
+		} );
+
+		expect( next.preview ).toEqual( {
+			toEmail: 'old@example.com',
+			isModalOpened: true,
+		} );
+		expect( state.preview.isModalOpened ).toBe( false );
+	} );
+
+	it( 'merges new URLs into the existing ones', () => {
+		const next = reducer( state, {
+			type: 'SET_EDITOR_URLS',
+			urls: { send: '/new-send' },
+		} );
+
+		expect( next.urls ).toEqual( {
+			listings: '/listings',
+			send: '/new-send',
+		} );
+	} );
+
+	it( 'applies the editor config without dropping other preview and style values', () => {
+		const next = reducer( state, {
+			type: 'SET_EDITOR_CONFIG',
+			config: {
+				editorSettings: { fresh: true },
+				theme: { styles: { color: {} } },
+				urls: { listings: '/l' },
+				userEmail: 'me@example.com',
+			},
+		} );
+
+		expect( next.preview ).toEqual( {
+			toEmail: 'me@example.com',
+			isModalOpened: false,
+		} );
+		expect( next.styles ).toEqual( {
+			globalStylesPostId: null,
+			other: 'kept',
+		} );
+		expect( next.editorSettings ).toEqual( { fresh: true } );
+	} );
+
+	it( 'returns the same state for an unknown action', () => {
+		expect( reducer( state, { type: 'UNKNOWN' } ) ).toBe( state );
+	} );
+} );
diff --git a/packages/js/email-editor/src/store/test/selectors.spec.ts b/packages/js/email-editor/src/store/test/selectors.spec.ts
new file mode 100644
index 00000000000..ad80bec0d42
--- /dev/null
+++ b/packages/js/email-editor/src/store/test/selectors.spec.ts
@@ -0,0 +1,305 @@
+/**
+ * External dependencies
+ */
+import { store as coreDataStore } from '@wordpress/core-data';
+import { store as editorStore } from '@wordpress/editor';
+import { applyFilters } from '@wordpress/hooks';
+import { serialize } from '@wordpress/blocks';
+
+/**
+ * Internal dependencies
+ */
+import {
+	canUserEditTemplates,
+	getCurrentTemplate,
+	getEditedEmailContent,
+	getEditedPostTemplate,
+	getEmailTemplates,
+	getSentEmailEditorPosts,
+	hasEmptyContent,
+	isEmailSent,
+} from '../selectors';
+import { storeName } from '../constants';
+
+// Importing the selectors module pulls in the whole block editor, which Jest
+// cannot transform. Only the store descriptors are needed to route `select`.
+jest.mock( '@wordpress/core-data', () => ( { store: { name: 'core' } } ) );
+jest.mock( '@wordpress/editor', () => ( { store: { name: 'core/editor' } } ) );
+jest.mock( '@wordpress/preferences', () => ( {
+	store: { name: 'core/preferences' },
+} ) );
+jest.mock( '@wordpress/blocks', () => ( {
+	serialize: jest.fn( () => '<!-- serialized -->' ),
+	parse: jest.fn(),
+} ) );
+jest.mock( '@wordpress/hooks', () => ( {
+	applyFilters: jest.fn( ( _hook, value ) => value ),
+} ) );
+
+type Selectors = Record< string, jest.Mock | ( ( ...args ) => unknown ) >;
+type Registry = { select: jest.Mock };
+
+const registrySelectors = [
+	canUserEditTemplates,
+	getCurrentTemplate,
+	getEditedEmailContent,
+	getEditedPostTemplate,
+	getEmailTemplates,
+	getSentEmailEditorPosts,
+	hasEmptyContent,
+	isEmailSent,
+] as unknown as { registry?: Registry }[];
+
+/**
+ * Gives every selector under test a fresh registry that answers from the given
+ * store selectors. A store the test didn't set up throws, so a selector that
+ * reads something unexpected fails loudly.
+ *
+ * @param stores        Selectors per store.
+ * @param stores.email  Email editor store selectors.
+ * @param stores.core   Core data store selectors.
+ * @param stores.editor Editor store selectors.
+ */
+function buildRegistry( stores: {
+	email?: Selectors;
+	core?: Selectors;
+	editor?: Selectors;
+} ) {
+	const registry: Registry = {
+		select: jest.fn( ( store ) => {
+			if ( store === storeName ) {
+				return {
+					getEmailPostId: () => 12,
+					getEmailPostType: () => 'woo_email',
+					...stores.email,
+				};
+			}
+			if ( store === coreDataStore && stores.core ) {
+				return stores.core;
+			}
+			if ( store === editorStore && stores.editor ) {
+				return stores.editor;
+			}
+			throw new Error( `Unexpected store: ${ String( store ) }` );
+		} ),
+	};
+	registrySelectors.forEach( ( selector ) => {
+		selector.registry = registry;
+	} );
+}
+
+describe( 'email editor store selectors', () => {
+	afterEach( () => {
+		registrySelectors.forEach( ( selector ) => {
+			delete selector.registry;
+		} );
+		jest.clearAllMocks();
+	} );
+
+	describe( 'hasEmptyContent', () => {
+		it.each( [
+			[ 'there is no post yet', undefined, true ],
+			[ 'the post has no content', { content: { raw: '' } }, true ],
+			[
+				'the post has content',
+				{ content: { raw: '<p>Hi</p>' } },
+				false,
+			],
+			[ 'the record has no content field', {}, true ],
+		] )( 'is %s → %s', ( _case, post, expected ) => {
+			buildRegistry( { core: { getEntityRecord: () => post } } );
+
+			expect( hasEmptyContent() ).toBe( expected );
+		} );
+	} );
+
+	describe( 'isEmailSent', () => {
+		it.each( [
+			[ undefined, false ],
+			[ { status: 'sent' }, true ],
+			[ { status: 'draft' }, false ],
+		] )( 'for post %j returns %s', ( post, expected ) => {
+			buildRegistry( { core: { getEntityRecord: () => post } } );
+
+			expect( isEmailSent() ).toBe( expected );
+		} );
+	} );
+
+	describe( 'getEditedEmailContent', () => {
+		it( 'prefers the content callback, then blocks, then the content string', () => {
+			const record = ( value: unknown ) =>
+				buildRegistry( {
+					core: { getEditedEntityRecord: () => value },
+				} );
+
+			record( { content: () => 'from callback', blocks: [ {} ] } );
+			expect( getEditedEmailContent() ).toBe( 'from callback' );
+
+			record( { blocks: [ {} ], content: 'stale string' } );
+			expect( getEditedEmailContent() ).toBe( '<!-- serialized -->' );
+			expect( serialize ).toHaveBeenCalledWith( [ {} ] );
+
+			record( { content: '<p>Plain</p>' } );
+			expect( getEditedEmailContent() ).toBe( '<p>Plain</p>' );
+
+			record( undefined );
+			expect( getEditedEmailContent() ).toBe( '' );
+		} );
+	} );
+
+	describe( 'getSentEmailEditorPosts', () => {
+		it( 'lists published and sent emails with content, using the filtered query', () => {
+			const getEntityRecords = jest.fn( () => [
+				{ id: 1, content: { raw: '<p>One</p>' } },
+				{ id: 2, content: { raw: '' } },
+			] );
+			buildRegistry( { core: { getEntityRecords } } );
+			( applyFilters as jest.Mock ).mockImplementationOnce(
+				( _hook, query ) => ( {
+					...query,
+					status: 'publish,sent,draft',
+				} )
+			);
+
+			const posts = getSentEmailEditorPosts();
+
+			expect( posts.map( ( post ) => post.id ) ).toEqual( [ 1 ] );
+			expect( applyFilters ).toHaveBeenCalledWith(
+				'woocommerce_email_editor_recent_emails_query',
+				{ per_page: 30, status: 'publish,sent' },
+				'woo_email'
+			);
+			expect( getEntityRecords ).toHaveBeenCalledWith(
+				'postType',
+				'woo_email',
+				{ per_page: 30, status: 'publish,sent,draft' }
+			);
+		} );
+
+		it.each( [ [ null ], [ 'publish' ], [ [ 'publish' ] ] ] )(
+			'falls back to the default query when a filter returns %j',
+			( filtered ) => {
+				const getEntityRecords = jest.fn( () => null );
+				buildRegistry( { core: { getEntityRecords } } );
+				( applyFilters as jest.Mock ).mockReturnValueOnce( filtered );
+
+				expect( getSentEmailEditorPosts() ).toEqual( [] );
+				expect( getEntityRecords ).toHaveBeenCalledWith(
+					'postType',
+					'woo_email',
+					{ per_page: 30, status: 'publish,sent' }
+				);
+			}
+		);
+	} );
+
+	describe( 'getEditedPostTemplate', () => {
+		const templates = [
+			{ id: 'theme//email-general', slug: 'email-general' },
+			{ id: 'theme//promo', slug: 'promo' },
+		];
+
+		function buildTemplateRegistry( canEdit: boolean ) {
+			const getEditedEntityRecord = jest.fn( ( _kind, _name, id ) => ( {
+				id,
+				edited: true,
+			} ) );
+			const getEntityRecord = jest.fn( ( _kind, _name, id ) => ( {
+				id,
+				title: { raw: 'Raw title' },
+				content: { raw: 'Raw content' },
+			} ) );
+			buildRegistry( {
+				core: {
+					getEntityRecords: () => templates,
+					getDefaultTemplateId: () => 'theme//email-general',
+					canUser: () => canEdit,
+					getEditedEntityRecord,
+					getEntityRecord,
+				},
+				editor: { getEditedPostAttribute: () => '' },
+			} );
+		}
+
+		it( 'returns the edited template for the given slug', () => {
+			buildTemplateRegistry( true );
+
+			expect( getEditedPostTemplate( undefined, 'promo' ) ).toEqual( {
+				id: 'theme//promo',
+				edited: true,
+			} );
+		} );
+
+		it( 'returns null when no template has the slug', () => {
+			buildTemplateRegistry( true );
+
+			expect( getEditedPostTemplate( undefined, 'missing' ) ).toBeNull();
+		} );
+
+		it( 'uses the default email-general template when the post has none', () => {
+			buildTemplateRegistry( true );
+
+			expect( getEditedPostTemplate( undefined ) ).toEqual( {
+				id: 'theme//email-general',
+				edited: true,
+			} );
+		} );
+
+		it( 'returns plain title and content to users who cannot edit templates', () => {
+			buildTemplateRegistry( false );
+
+			expect( getEditedPostTemplate( undefined, 'promo' ) ).toEqual(
+				expect.objectContaining( {
+					id: 'theme//promo',
+					title: 'Raw title',
+					content: 'Raw content',
+				} )
+			);
+		} );
+	} );
+
+	describe( 'getCurrentTemplate', () => {
+		it( 'returns the template being edited in template mode', () => {
+			buildRegistry( {
+				editor: {
+					getCurrentPostType: () => 'wp_template',
+					getCurrentPostId: () => 'theme//promo',
+				},
+				core: {
+					getEditedEntityRecord: ( _kind, _name, id ) => ( { id } ),
+				},
+			} );
+
+			expect( getCurrentTemplate() ).toEqual( { id: 'theme//promo' } );
+		} );
+
+		it( "returns the email's template while editing an email", () => {
+			buildRegistry( {
+				editor: { getCurrentPostType: () => 'woo_email' },
+				email: {
+					getEditedPostTemplate: () => ( { id: 'email-template' } ),
+				},
+			} );
+
+			expect( getCurrentTemplate() ).toEqual( { id: 'email-template' } );
+		} );
+	} );
+
+	describe( 'getEmailTemplates', () => {
+		it( 'keeps only templates for the email post type', () => {
+			buildRegistry( {
+				core: {
+					getEntityRecords: () => [
+						{ id: 'a', post_types: [ 'woo_email' ] },
+						{ id: 'b', post_types: [ 'page' ] },
+						{ id: 'c' },
+					],
+				},
+			} );
+
+			expect(
+				getEmailTemplates().map( ( template ) => template.id )
+			).toEqual( [ 'a' ] );
+		} );
+	} );
+} );
diff --git a/packages/js/email-editor/src/test/mailpoet-contract.spec.ts b/packages/js/email-editor/src/test/mailpoet-contract.spec.ts
new file mode 100644
index 00000000000..de74fc215fd
--- /dev/null
+++ b/packages/js/email-editor/src/test/mailpoet-contract.spec.ts
@@ -0,0 +1,179 @@
+/**
+ * External dependencies
+ */
+import { readFileSync, readdirSync, statSync } from 'fs';
+import { join } from 'path';
+import * as ts from 'typescript';
+
+/**
+ * Internal dependencies
+ */
+import { storeName } from '../store/constants';
+
+/**
+ * Pins the parts of this package that MailPoet's JavaScript uses: the exports it
+ * imports, the store it reads and writes, and the hooks it adds callbacks to. A
+ * failure here means a change would break MailPoet's email editor.
+ *
+ * The list comes from MailPoet's `assets/js/src`. Update it when MailPoet starts
+ * or stops using a part of the package. The source is read with the TypeScript
+ * parser because importing the package entry point loads the whole block editor.
+ */
+
+const SRC = join( __dirname, '..' );
+
+function parse( file: string ): ts.SourceFile {
+	return ts.createSourceFile(
+		file,
+		readFileSync( file, 'utf8' ),
+		ts.ScriptTarget.Latest,
+		true
+	);
+}
+
+/**
+ * Names a module exports directly (not through `export *`).
+ *
+ * @param file Module file.
+ */
+function exportedNames( file: string ): string[] {
+	const names: string[] = [];
+	parse( file ).forEachChild( ( node ) => {
+		if ( ts.isExportDeclaration( node ) && node.exportClause ) {
+			if ( ts.isNamedExports( node.exportClause ) ) {
+				node.exportClause.elements.forEach( ( element ) =>
+					names.push( element.name.text )
+				);
+			}
+		}
+		const modifiers = ts.canHaveModifiers( node )
+			? ts.getModifiers( node )
+			: undefined;
+		const isExported = modifiers?.some(
+			( modifier ) => modifier.kind === ts.SyntaxKind.ExportKeyword
+		);
+		if ( ! isExported ) {
+			return;
+		}
+		if ( ts.isVariableStatement( node ) ) {
+			node.declarationList.declarations.forEach( ( declaration ) => {
+				if ( ts.isIdentifier( declaration.name ) ) {
+					names.push( declaration.name.text );
+				}
+			} );
+		} else if (
+			( ts.isFunctionDeclaration( node ) ||
+				ts.isTypeAliasDeclaration( node ) ||
+				ts.isInterfaceDeclaration( node ) ) &&
+			node.name
+		) {
+			names.push( node.name.text );
+		}
+	} );
+	return names;
+}
+
+function sourceFiles( dir: string ): string[] {
+	return readdirSync( dir ).flatMap( ( name ) => {
+		const path = join( dir, name );
+		if ( statSync( path ).isDirectory() ) {
+			return name === 'test' || name === '__mocks__'
+				? []
+				: sourceFiles( path );
+		}
+		return /\.(ts|tsx|js)$/.test( name ) && ! /\.d\.ts$/.test( name )
+			? [ path ]
+			: [];
+	} );
+}
+
+/**
+ * Fewest arguments passed to each hook fired with a string literal name, so a
+ * call site that drops an argument MailPoet reads fails the check.
+ */
+function firedHooks(): Map< string, number > {
+	const hooks = new Map< string, number >();
+	sourceFiles( SRC ).forEach( ( file ) => {
+		const visit = ( node: ts.Node ) => {
+			if (
+				ts.isCallExpression( node ) &&
+				ts.isIdentifier( node.expression ) &&
+				[ 'applyFilters', 'doAction' ].includes(
+					node.expression.text
+				) &&
+				node.arguments.length > 0 &&
+				ts.isStringLiteral( node.arguments[ 0 ] )
+			) {
+				const name = node.arguments[ 0 ].text;
+				const args = node.arguments.length - 1;
+				hooks.set( name, Math.min( hooks.get( name ) ?? args, args ) );
+			}
+			ts.forEachChild( node, visit );
+		};
+		visit( parse( file ) );
+	} );
+	return hooks;
+}
+
+describe( 'MailPoet contract', () => {
+	let fired: Map< string, number >;
+
+	beforeAll( () => {
+		fired = firedHooks();
+	} );
+
+	it( 'keeps the store name MailPoet selects and dispatches to', () => {
+		expect( storeName ).toBe( 'email-editor/editor' );
+	} );
+
+	it.each( [
+		[ 'index.ts', 'initializeEditor' ],
+		[ 'index.ts', 'storeName' ],
+		[ 'index.ts', 'EmailActionsFill' ],
+		[ 'index.ts', 'TemplateSelection' ],
+		[ 'index.ts', 'RecentEmailsQuery' ],
+		// Marked internal, but MailPoet's email presets use it until they move off it.
+		[ 'index.ts', 'registerEntityAction' ],
+		[ 'store/constants.ts', 'storeName' ],
+		[ 'store/types.ts', 'EmailContentValidationRule' ],
+		[ 'store/types.ts', 'RecentEmailsQuery' ],
+		[ 'store/selectors.ts', 'getEmailPostType' ],
+		[ 'store/selectors.ts', 'isEmailSent' ],
+		[ 'store/actions.ts', 'setEmailPost' ],
+		[ 'store/actions.ts', 'togglePreviewModal' ],
+	] )( '%s exports %s', ( file, name ) => {
+		expect( exportedNames( join( SRC, file ) ) ).toContain( name );
+	} );
+
+	it( 'keeps the store re-exporting its constants and types', () => {
+		const source = readFileSync( join( SRC, 'store/index.ts' ), 'utf8' );
+
+		expect( source ).toContain( "export * from './constants';" );
+		expect( source ).toContain( "export * from './types';" );
+	} );
+
+	it.each( [
+		[ 'woocommerce_email_editor_wrap_editor_component', 1 ],
+		[ 'woocommerce_email_editor_content_validation_rules', 1 ],
+		[ 'woocommerce_email_editor_send_button_label', 1 ],
+		[ 'woocommerce_email_editor_send_action_callback', 1 ],
+		[ 'woocommerce_email_editor_send_button_disabled', 2 ],
+		[ 'woocommerce_email_editor_events', 1 ],
+		[ 'woocommerce_email_editor_events_tracking_enabled', 1 ],
+		[ 'woocommerce_email_editor_preferred_template_title', 2 ],
+		[ 'woocommerce_email_editor_recent_emails_query', 2 ],
+	] )( 'fires %s with at least %d argument(s)', ( hook, args ) => {
+		expect( fired.has( hook ) ).toBe( true );
+		expect( fired.get( hook ) ).toBeGreaterThanOrEqual( args );
+	} );
+
+	it( 'finds hooks in the source at all', () => {
+		// Guards the helpers above: an empty map would make every hook check fail
+		// for the wrong reason, so this test names that cause directly.
+		expect(
+			[ ...fired.keys() ].filter( ( name ) =>
+				name.startsWith( 'woocommerce_email_editor_' )
+			).length
+		).toBeGreaterThan( 9 );
+	} );
+} );