diff --git a/projects/plugins/jetpack/changelog/add-subscription-block-tests b/projects/plugins/jetpack/changelog/add-subscription-block-tests
new file mode 100644
index 0000000000000..b64438a875440
--- /dev/null
+++ b/projects/plugins/jetpack/changelog/add-subscription-block-tests
@@ -0,0 +1,4 @@
+Significance: patch
+Type: compat
+
+Subscriptions block: adding unit tests only. Changelog entry not required.
diff --git a/projects/plugins/jetpack/extensions/blocks/subscriptions/controls.js b/projects/plugins/jetpack/extensions/blocks/subscriptions/controls.js
new file mode 100644
index 0000000000000..19a7d24f9f45f
--- /dev/null
+++ b/projects/plugins/jetpack/extensions/blocks/subscriptions/controls.js
@@ -0,0 +1,250 @@
+/**
+ * External dependencies
+ */
+import { __ } from '@wordpress/i18n';
+import { ToggleControl, PanelBody, RangeControl } from '@wordpress/components';
+import {
+ ContrastChecker,
+ PanelColorSettings,
+ FontSizePicker,
+ __experimentalPanelColorGradientSettings as PanelColorGradientSettings,
+} from '@wordpress/block-editor';
+
+/**
+ * Internal dependencies
+ */
+import { ButtonWidthControl } from '../button/button-width-panel';
+import {
+ MIN_BORDER_RADIUS_VALUE,
+ MAX_BORDER_RADIUS_VALUE,
+ DEFAULT_BORDER_RADIUS_VALUE,
+ MIN_BORDER_WEIGHT_VALUE,
+ MAX_BORDER_WEIGHT_VALUE,
+ DEFAULT_BORDER_WEIGHT_VALUE,
+ MIN_PADDING_VALUE,
+ MAX_PADDING_VALUE,
+ DEFAULT_PADDING_VALUE,
+ MIN_SPACING_VALUE,
+ MAX_SPACING_VALUE,
+ DEFAULT_SPACING_VALUE,
+ DEFAULT_FONTSIZE_VALUE,
+} from './constants';
+
+export default function SubscriptionControls( {
+ buttonBackgroundColor,
+ borderColor,
+ buttonGradient,
+ borderRadius,
+ borderWeight,
+ buttonOnNewLine,
+ emailFieldBackgroundColor,
+ fallbackButtonBackgroundColor,
+ fallbackTextColor,
+ fontSize,
+ isGradientAvailable,
+ padding,
+ setAttributes,
+ setButtonBackgroundColor,
+ setTextColor,
+ showSubscribersTotal,
+ spacing,
+ subscriberCount,
+ textColor,
+ buttonWidth,
+} ) {
+ return (
+ <>
+ { isGradientAvailable && (
+ {
+ // Note: setBorderColor from withColors hook does not
+ // work correctly with shortcode border color rendering.
+ setAttributes( {
+ borderColor: newBorderColor,
+ customBorderColor: newBorderColor,
+ } );
+ },
+ label: __( 'Border Color', 'jetpack' ),
+ },
+ ] }
+ initialOpen={ true }
+ >
+
+
+ ) }
+ { ! isGradientAvailable && (
+ {
+ // Note: setBorderColor from withColors hook does not
+ // work correctly with shortcode border color rendering.
+ setAttributes( {
+ borderColor: newBorderColor,
+ customBorderColor: newBorderColor,
+ } );
+ },
+ label: __( 'Border Color', 'jetpack' ),
+ },
+ ] }
+ initialOpen={ false }
+ >
+
+
+ ) }
+
+
+ {
+ // Note: setFontSize from withFontSizes hook does not
+ // work correctly with shortcode font size rendering.
+ const newFontSize = selectedFontSize ? selectedFontSize : DEFAULT_FONTSIZE_VALUE;
+ setAttributes( {
+ fontSize: newFontSize,
+ customFontSize: newFontSize,
+ } );
+ } }
+ />
+
+
+
+ setAttributes( { borderRadius: newBorderRadius } ) }
+ />
+
+ setAttributes( { borderWeight: newBorderWeight } ) }
+ />
+
+
+
+ setAttributes( { padding: newPaddingValue } ) }
+ />
+
+ setAttributes( { spacing: newSpacingValue } ) }
+ />
+
+ setAttributes( { buttonWidth: newButtonWidth } ) }
+ />
+
+
+
+ {
+ setAttributes( { showSubscribersTotal: ! showSubscribersTotal } );
+ } }
+ help={ () => {
+ if ( ! subscriberCount || subscriberCount < 1 ) {
+ return __(
+ 'This will remain hidden on your website until you have at least one subscriber.',
+ 'jetpack'
+ );
+ }
+ } }
+ />
+
+ {
+ setAttributes( { buttonOnNewLine: ! buttonOnNewLine } );
+ } }
+ />
+
+ >
+ );
+}
diff --git a/projects/plugins/jetpack/extensions/blocks/subscriptions/deprecated/index.js b/projects/plugins/jetpack/extensions/blocks/subscriptions/deprecated/index.js
index 7d84110812861..8314643d1a414 100644
--- a/projects/plugins/jetpack/extensions/blocks/subscriptions/deprecated/index.js
+++ b/projects/plugins/jetpack/extensions/blocks/subscriptions/deprecated/index.js
@@ -8,4 +8,7 @@ import deprecatedV3 from './v3';
import deprecatedV4 from './v4';
import deprecatedV5 from './v5';
-export default [ deprecatedV1, deprecatedV2, deprecatedV3, deprecatedV4, deprecatedV5 ];
+// Deprecations should run in reverse chronological order. Most probable
+// deprecations to run are the most recent. This ordering makes the process
+// a little more performant.
+export default [ deprecatedV5, deprecatedV4, deprecatedV3, deprecatedV2, deprecatedV1 ];
diff --git a/projects/plugins/jetpack/extensions/blocks/subscriptions/deprecated/v1/index.js b/projects/plugins/jetpack/extensions/blocks/subscriptions/deprecated/v1/index.js
index 85bf729beeb7c..599a01ce77a3e 100644
--- a/projects/plugins/jetpack/extensions/blocks/subscriptions/deprecated/v1/index.js
+++ b/projects/plugins/jetpack/extensions/blocks/subscriptions/deprecated/v1/index.js
@@ -5,24 +5,26 @@ import { __ } from '@wordpress/i18n';
import { isEmpty } from 'lodash';
import { RawHTML } from '@wordpress/element';
+/**
+ * Deprecation reason:
+ *
+ * Block moved from `subscribeButton` attribute to `submitButtonText` when it
+ * had an empty value set.
+ */
export default {
attributes: {
subscribeButton: { type: 'string', default: __( 'Subscribe', 'jetpack' ) },
showSubscribersTotal: { type: 'boolean', default: false },
},
- migrate: attr => {
+ migrate: oldAttributes => {
return {
- subscribeButton: '',
- submitButtonText: attr.subscribeButton,
- showSubscribersTotal: attr.showSubscribersTotal,
- customBackgroundButtonColor: '',
- customTextButtonColor: '',
- submitButtonClasses: '',
+ submitButtonText: oldAttributes.subscribeButton,
+ showSubscribersTotal: oldAttributes.showSubscribersTotal,
};
},
-
isEligible: attr => {
- if ( ! isEmpty( attr.subscribeButton ) ) {
+ // Newer block versions do not have `subscribeButton` attribute.
+ if ( ! attr.hasOwnProperty( 'subscribeButton' ) || ! isEmpty( attr.subscribeButton ) ) {
return false;
}
return true;
diff --git a/projects/plugins/jetpack/extensions/blocks/subscriptions/deprecated/v2/index.js b/projects/plugins/jetpack/extensions/blocks/subscriptions/deprecated/v2/index.js
index bc1e1d19a4a95..bda02a1a7f3a4 100644
--- a/projects/plugins/jetpack/extensions/blocks/subscriptions/deprecated/v2/index.js
+++ b/projects/plugins/jetpack/extensions/blocks/subscriptions/deprecated/v2/index.js
@@ -8,6 +8,12 @@ import { __ } from '@wordpress/i18n';
*/
import save from './save';
+/**
+ * Deprecation reason:
+ *
+ * Addition of option to display button on new line and renaming of color
+ * attributes to better support use of SubmitButton component.
+ */
export default {
attributes: {
subscribePlaceholder: { type: 'string', default: __( 'Email Address', 'jetpack' ) },
diff --git a/projects/plugins/jetpack/extensions/blocks/subscriptions/deprecated/v3/index.js b/projects/plugins/jetpack/extensions/blocks/subscriptions/deprecated/v3/index.js
index a297b30110462..35fa3cf98c524 100644
--- a/projects/plugins/jetpack/extensions/blocks/subscriptions/deprecated/v3/index.js
+++ b/projects/plugins/jetpack/extensions/blocks/subscriptions/deprecated/v3/index.js
@@ -4,13 +4,19 @@
import definedAttributes from './attributes';
import getSubscriptionsShortcode from './get-subscriptions-shortcode';
+/**
+ * Deprecation reason:
+ *
+ * Shortcode generation changed to omit undefined attributes.
+ */
export default {
attributes: definedAttributes,
migrate: attributes => {
+ const { fontSize, customFontSize } = attributes;
return {
...attributes,
- fontSize: `${ attributes.fontSize }px`,
- customFontSize: `${ attributes.customFontSize }px`,
+ fontSize: fontSize ? `${ fontSize }px` : undefined,
+ customFontSize: customFontSize ? `${ customFontSize }px` : undefined,
};
},
save: ( { className, attributes } ) => getSubscriptionsShortcode( className, attributes ),
diff --git a/projects/plugins/jetpack/extensions/blocks/subscriptions/deprecated/v4/index.js b/projects/plugins/jetpack/extensions/blocks/subscriptions/deprecated/v4/index.js
index 5b3fae075cab3..fbdfa733cdbee 100644
--- a/projects/plugins/jetpack/extensions/blocks/subscriptions/deprecated/v4/index.js
+++ b/projects/plugins/jetpack/extensions/blocks/subscriptions/deprecated/v4/index.js
@@ -4,13 +4,25 @@
import definedAttributes from '../v3/attributes';
import getSubscriptionsShortcode from '../v3/get-subscriptions-shortcode';
+/**
+ * Deprecation reason:
+ *
+ * Saving the default submit button text into the shortcode prevented that text
+ * from being translated for non-English locales.
+ *
+ * The `check-text-defaults` flag passed to the `getSubscriptionsShortcode`
+ * function means it will render the English defaults into the shortcode which
+ * can then in turn be detected as "default" text when parsing the shortcode and
+ * then translated appropriately.
+ */
export default {
attributes: definedAttributes,
migrate: attributes => {
+ const { fontSize, customFontSize } = attributes;
return {
...attributes,
- fontSize: `${ attributes.fontSize }px`,
- customFontSize: `${ attributes.customFontSize }px`,
+ fontSize: fontSize ? `${ fontSize }px` : undefined,
+ customFontSize: customFontSize ? `${ customFontSize }px` : undefined,
};
},
save: ( { className, attributes } ) =>
diff --git a/projects/plugins/jetpack/extensions/blocks/subscriptions/deprecated/v5/index.js b/projects/plugins/jetpack/extensions/blocks/subscriptions/deprecated/v5/index.js
index 40ffd8c7cf245..779929e42ca08 100644
--- a/projects/plugins/jetpack/extensions/blocks/subscriptions/deprecated/v5/index.js
+++ b/projects/plugins/jetpack/extensions/blocks/subscriptions/deprecated/v5/index.js
@@ -4,13 +4,20 @@
import definedAttributes from '../v3/attributes';
import save from './save';
+/**
+ * Deprecation reason
+ *
+ * Gutenberg's font size selector changed to use values including CSS units.
+ * This changed the resulting values in the generated shortcode.
+ */
export default {
attributes: definedAttributes,
migrate: attributes => {
+ const { fontSize, customFontSize } = attributes;
return {
...attributes,
- fontSize: `${ attributes.fontSize }px`,
- customFontSize: `${ attributes.customFontSize }px`,
+ fontSize: fontSize ? `${ fontSize }px` : undefined,
+ customFontSize: customFontSize ? `${ customFontSize }px` : undefined,
};
},
save,
diff --git a/projects/plugins/jetpack/extensions/blocks/subscriptions/edit.js b/projects/plugins/jetpack/extensions/blocks/subscriptions/edit.js
index 2dab410283ffe..20f5bf976b81b 100644
--- a/projects/plugins/jetpack/extensions/blocks/subscriptions/edit.js
+++ b/projects/plugins/jetpack/extensions/blocks/subscriptions/edit.js
@@ -5,25 +5,14 @@ import classnames from 'classnames';
import { isEqual } from 'lodash';
import apiFetch from '@wordpress/api-fetch';
import { __, _n, sprintf } from '@wordpress/i18n';
-import {
- TextControl,
- ToggleControl,
- PanelBody,
- RangeControl,
- withFallbackStyles,
-} from '@wordpress/components';
+import { TextControl, withFallbackStyles } from '@wordpress/components';
import {
InspectorControls,
- ContrastChecker,
- PanelColorSettings,
RichText,
withColors,
- FontSizePicker,
withFontSizes,
- __experimentalPanelColorGradientSettings as PanelColorGradientSettings,
__experimentalUseGradient as useGradient,
} from '@wordpress/block-editor';
-import { ButtonWidthControl } from '../button/button-width-panel';
import { useEffect, useState } from '@wordpress/element';
import { compose } from '@wordpress/compose';
@@ -34,20 +23,13 @@ import './view.scss';
import defaultAttributes from './attributes';
import { getValidatedAttributes } from '../../shared/get-validated-attributes';
import {
- MIN_BORDER_RADIUS_VALUE,
- MAX_BORDER_RADIUS_VALUE,
DEFAULT_BORDER_RADIUS_VALUE,
- MIN_BORDER_WEIGHT_VALUE,
- MAX_BORDER_WEIGHT_VALUE,
DEFAULT_BORDER_WEIGHT_VALUE,
- MIN_PADDING_VALUE,
- MAX_PADDING_VALUE,
DEFAULT_PADDING_VALUE,
- MIN_SPACING_VALUE,
- MAX_SPACING_VALUE,
DEFAULT_SPACING_VALUE,
DEFAULT_FONTSIZE_VALUE,
} from './constants';
+import SubscriptionControls from './controls';
const { getComputedStyle } = window;
const isGradientAvailable = !! useGradient;
@@ -69,7 +51,7 @@ const applyFallbackStyles = withFallbackStyles( ( node, ownProps ) => {
};
} );
-function SubscriptionEdit( props ) {
+export function SubscriptionEdit( props ) {
const {
className,
attributes,
@@ -221,197 +203,28 @@ function SubscriptionEdit( props ) {
return (
<>
- { isGradientAvailable && (
- {
- // Note: setBorderColor from withColors hook does not
- // work correctly with shortcode border color rendering.
- setAttributes( {
- borderColor: newBorderColor,
- customBorderColor: newBorderColor,
- } );
- },
- label: __( 'Border Color', 'jetpack' ),
- },
- ] }
- initialOpen={ true }
- >
-
-
- ) }
- { ! isGradientAvailable && (
- {
- // Note: setBorderColor from withColors hook does not
- // work correctly with shortcode border color rendering.
- setAttributes( {
- borderColor: newBorderColor,
- customBorderColor: newBorderColor,
- } );
- },
- label: __( 'Border Color', 'jetpack' ),
- },
- ] }
- initialOpen={ false }
- >
-
-
- ) }
-
-
- {
- // Note: setFontSize from withFontSizes hook does not
- // work correctly with shortcode font size rendering.
- const newFontSize = selectedFontSize ? selectedFontSize : DEFAULT_FONTSIZE_VALUE;
- setAttributes( {
- fontSize: newFontSize,
- customFontSize: newFontSize,
- } );
- } }
- />
-
-
-
- setAttributes( { borderRadius: newBorderRadius } ) }
- />
-
- setAttributes( { borderWeight: newBorderWeight } ) }
- />
-
-
-
- setAttributes( { padding: newPaddingValue } ) }
- />
-
- setAttributes( { spacing: newSpacingValue } ) }
- />
-
- setAttributes( { buttonWidth: newButtonWidth } ) }
- />
-
-
-
- {
- setAttributes( { showSubscribersTotal: ! showSubscribersTotal } );
- } }
- help={ () => {
- if ( ! subscriberCount || subscriberCount < 1 ) {
- return __(
- 'This will remain hidden on your website until you have at least one subscriber.',
- 'jetpack'
- );
- }
- } }
- />
-
- {
- setAttributes( { buttonOnNewLine: ! buttonOnNewLine } );
- } }
- />
-
+
diff --git a/projects/plugins/jetpack/extensions/blocks/subscriptions/test/controls.js b/projects/plugins/jetpack/extensions/blocks/subscriptions/test/controls.js
new file mode 100644
index 0000000000000..9e7f553127ac3
--- /dev/null
+++ b/projects/plugins/jetpack/extensions/blocks/subscriptions/test/controls.js
@@ -0,0 +1,212 @@
+/**
+ * External dependencies
+ */
+import { render, screen } from '@testing-library/react';
+import userEvent from '@testing-library/user-event';
+import '@testing-library/jest-dom/extend-expect';
+
+/**
+ * Internal dependencies
+ */
+import SubscriptionsInspectorControls from '../controls';
+import {
+ DEFAULT_FONTSIZE_VALUE,
+} from '../constants';
+
+// Temporarily mock out the ButtonWidthControl, which is causing errors due to missing
+// dependencies in the jest test runner.
+jest.mock( '../../button/button-width-panel', () => ( {
+ ...jest.requireActual( '../../button/button-width-panel' ),
+ ButtonWidthControl: () =>
Mocked Width Control
,
+} ) );
+
+const setButtonBackgroundColor = jest.fn();
+const setGradient = jest.fn();
+const setTextColor = jest.fn();
+const setAttributes = jest.fn();
+
+const defaultProps = {
+ buttonBackgroundColor: { color: '#000000' },
+ borderColor: { color: '#000000' },
+ buttonGradient: {
+ buttonGradient: 10,
+ setGradient,
+ },
+ borderRadius: 0,
+ borderWeight: 0,
+ buttonOnNewLine: false,
+ emailFieldBackgroundColor: { color: '#000000' },
+ fallbackButtonBackgroundColor: '#000000',
+ fallbackTextColor: '#000000',
+ fontSize: DEFAULT_FONTSIZE_VALUE,
+ isGradientAvailable: true,
+ padding: 0,
+ setAttributes,
+ setButtonBackgroundColor,
+ setTextColor,
+ showSubscribersTotal: true,
+ spacing: 0,
+ subscriberCount: 100,
+ textColor: '#000000',
+};
+
+beforeEach( () => {
+ setAttributes.mockClear();
+ setGradient.mockClear();
+ setTextColor.mockClear();
+ setButtonBackgroundColor.mockClear();
+} );
+
+describe( 'Inspector controls', () => {
+ describe( 'Gradient settings panel', () => {
+ test( 'displays gradient settings control panel', () => {
+ render(
);
+
+ expect( screen.getByText( 'Color Settings' ) ).toBeInTheDocument();
+ expect( screen.queryByText( 'Background Colors' ) ).not.toBeInTheDocument();
+ } );
+
+ test( 'sets solid background color', async () => {
+ render(
);
+ userEvent.click( screen.getByText( 'Solid' ) );
+ userEvent.click( screen.queryAllByLabelText( /Color\:/i, { selector: 'button' } )[0] );
+
+ expect( setButtonBackgroundColor.mock.calls[0][0] ).toMatch(/#[a-z0-9]{6,6}/);
+ } );
+
+ test( 'sets a button background color', async () => {
+ render(
);
+ userEvent.click( screen.getByText( 'Solid' ) );
+ userEvent.click( screen.queryAllByLabelText( /Color\:/i, { selector: 'button' } )[0] );
+
+ expect( setButtonBackgroundColor.mock.calls[0][0] ).toMatch(/#[a-z0-9]{6,6}/);
+ } );
+ } );
+
+ describe( 'Color settings panel', () => {
+ test( 'hides gradient settings control panel', () => {
+ render(
);
+
+ expect( screen.getByText( 'Background Colors' ) ).toBeInTheDocument();
+ expect( screen.queryByText( 'Color Settings' ) ).not.toBeInTheDocument();
+ } );
+
+ test( 'sets gradient background color', async () => {
+ render(
);
+ userEvent.click( screen.getByText( 'Gradient' ) );
+ userEvent.click( screen.queryAllByLabelText( /Gradient\:/i, { selector: 'button' } )[0] );
+
+ expect( setGradient.mock.calls[0][0] ).toMatch(/linear\-gradient\((.+)\)/);
+ } );
+ } );
+
+ describe( 'Text settings panel', () => {
+ test( 'displays correctly', () => {
+ render(
);
+
+ expect( screen.getByText( 'Text Settings' ) ).toBeInTheDocument();
+ } );
+
+ test( 'set custom text ', () => {
+ render(
);
+ userEvent.click( screen.getByText( 'Text Settings' ), { selector: 'button' } );
+ userEvent.type( screen.getAllByLabelText( 'Custom Size' )[1], '18' );
+
+ expect( setAttributes ).toHaveBeenLastCalledWith( {
+ fontSize: 18,
+ customFontSize: 18,
+ } );
+ } );
+ } );
+
+ describe( 'Border settings panel', () => {
+ test( 'displays correctly', () => {
+ render(
);
+
+ expect( screen.getByText( 'Border Settings' ) ).toBeInTheDocument();
+ } );
+
+ test( 'set border radius', () => {
+ render(
);
+ userEvent.click( screen.getByText( 'Border Settings' ), { selector: 'button' } );
+ const rangeControlElement = screen.getAllByLabelText( 'Border Radius' )[1];
+ userEvent.clear( rangeControlElement );
+ userEvent.type( rangeControlElement, '5' );
+
+ expect( setAttributes ).toHaveBeenLastCalledWith( {
+ borderRadius: 5,
+ } );
+ } );
+
+ test( 'set border weight', () => {
+ render(
);
+ userEvent.click( screen.getByText( 'Border Settings' ), { selector: 'button' } );
+ const rangeControlElement = screen.getAllByLabelText( 'Border Weight' )[1];
+ userEvent.clear( rangeControlElement );
+ userEvent.type( rangeControlElement, '5' );
+
+ expect( setAttributes ).toHaveBeenLastCalledWith( {
+ borderWeight: 5,
+ } );
+ } );
+ } );
+
+ describe( 'Spacing settings panel', () => {
+ test( 'displays correctly', () => {
+ render(
);
+
+ expect( screen.getByText( 'Spacing Settings' ) ).toBeInTheDocument();
+ } );
+
+ test( 'set space inside', () => {
+ render(
);
+ userEvent.click( screen.getByText( 'Spacing Settings' ), { selector: 'button' } );
+ const rangeControlElement = screen.getAllByLabelText( 'Space Inside' )[1];
+ userEvent.clear( rangeControlElement );
+ userEvent.type( rangeControlElement, '5' );
+
+ expect( setAttributes ).toHaveBeenLastCalledWith( {
+ padding: 5,
+ } );
+ } );
+
+ test( 'set space between', () => {
+ render(
);
+ userEvent.click( screen.getByText( 'Spacing Settings' ), { selector: 'button' } );
+ const rangeControlElement = screen.getAllByLabelText( 'Space Between' )[1];
+ userEvent.clear( rangeControlElement );
+ userEvent.type( rangeControlElement, '5' );
+
+ expect( setAttributes ).toHaveBeenLastCalledWith( {
+ spacing: 5,
+ } );
+ } );
+ } );
+
+ describe( 'Display settings panel', () => {
+ test( 'displays correctly', () => {
+ render(
);
+ expect( screen.getByText( 'Display Settings' ) ).toBeInTheDocument();
+ } );
+
+ test( 'toggles subscriber count', () => {
+ render(
);
+ userEvent.click( screen.getByText( 'Display Settings' ), { selector: 'button' } );
+ userEvent.click( screen.getByLabelText( 'Show subscriber count' ) );
+
+ expect( setAttributes ).toHaveBeenCalledWith( {
+ showSubscribersTotal: false,
+ } );
+ } );
+
+ test( 'toggles place button on new line', () => {
+ render(
);
+ userEvent.click( screen.getByText( 'Display Settings' ), { selector: 'button' } );
+ userEvent.click( screen.getByLabelText( 'Place button on new line' ) );
+
+ expect( setAttributes ).toHaveBeenCalledWith( {
+ buttonOnNewLine: true,
+ } );
+ } );
+ } );
+} );
diff --git a/projects/plugins/jetpack/extensions/blocks/subscriptions/test/edit.js b/projects/plugins/jetpack/extensions/blocks/subscriptions/test/edit.js
new file mode 100644
index 0000000000000..8c15ed9da0869
--- /dev/null
+++ b/projects/plugins/jetpack/extensions/blocks/subscriptions/test/edit.js
@@ -0,0 +1,148 @@
+/**
+ * External dependencies
+ */
+import { render, screen, act } from '@testing-library/react';
+import userEvent from '@testing-library/user-event';
+import '@testing-library/jest-dom/extend-expect';
+
+/**
+ * Internal dependencies
+ */
+import { SubscriptionEdit } from '../edit';
+
+const setAttributes = jest.fn();
+
+const defaultAttributes = {
+ borderRadius: 0,
+ borderWeight: 0,
+ padding: 0,
+ spacing: 0,
+ submitButtonText: 'Submit',
+ subscribePlaceholder: 'Do it',
+ showSubscribersTotal: false,
+ buttonOnNewLine: false,
+};
+
+const defaultProps = {
+ attributes: defaultAttributes,
+ className: 'noodles',
+ setAttributes,
+ emailFieldBackgroundColor: '',
+ buttonBackgroundColor: '',
+ setButtonBackgroundColor: '',
+ fallbackButtonBackgroundColo: '',
+ textColor: '',
+ fallbackTextColor: '',
+ setTextColor: '',
+ borderColor: '',
+ fontSize: 12,
+};
+
+const originalFetch = window.fetch;
+
+/**
+ * Mock return value for a successful fetch JSON return value.
+ *
+ * @return {Promise} Mock return value.
+ */
+const RESOLVED_FETCH_PROMISE = Promise.resolve( { count: 100 } );
+const DEFAULT_FETCH_MOCK_RETURN = Promise.resolve( {
+ status: 200,
+ json: () => RESOLVED_FETCH_PROMISE,
+} );
+
+jest.mock( '../constants', () => ( {
+ IS_GRADIENT_AVAILABLE: true
+} ) );
+
+jest.mock( '@wordpress/block-editor', () => ( {
+ ...jest.requireActual( '@wordpress/block-editor' ),
+ __experimentalUseGradient: jest.fn().mockReturnValue( {
+ gradientClass: undefined,
+ gradientValue: undefined,
+ setGradient: jest.fn()
+ } ),
+} ) );
+
+describe( 'SubscriptionEdit', () => {
+ beforeEach( () => {
+ window.fetch = jest.fn();
+ window.fetch.mockReturnValue( DEFAULT_FETCH_MOCK_RETURN );
+ } );
+
+ afterEach( async () => {
+ await act( () => RESOLVED_FETCH_PROMISE );
+ } );
+
+ afterAll( () => {
+ window.fetch = originalFetch;
+ } );
+
+ test( 'adds correct classes to container', () => {
+ const { container, rerender } = render(
);
+
+ expect( container.querySelector( `.${ defaultProps.className }` ) ).toBeInTheDocument();
+ } );
+
+ test( 'adds correct classes when button on new line', () => {
+ const { container, rerender } = render(
);
+
+ expect( container.querySelector( '.wp-block-jetpack-subscriptions__use-newline' ) ).not.toBeInTheDocument();
+
+ const updatedProps = {
+ ...defaultProps,
+ attributes: {
+ ...defaultAttributes,
+ buttonOnNewLine: true,
+ },
+ };
+ rerender(
);
+
+ expect( container.querySelector( '.wp-block-jetpack-subscriptions__use-newline' ) ).toBeInTheDocument();
+ } );
+
+ test( 'renders text field with placeholder text', () => {
+ render(
);
+
+ expect( screen.getByPlaceholderText( defaultAttributes.subscribePlaceholder ) ).toBeInTheDocument();
+ } );
+
+ test( 'renders button with default text', () => {
+ render(
);
+
+ expect( screen.getByText( defaultAttributes.submitButtonText ) ).toBeInTheDocument();
+ } );
+
+ test( 'calls setAttributes handler on button when value changes', () => {
+ render(
);
+
+ expect( screen.getByText( defaultAttributes.submitButtonText ) ).toBeInTheDocument();
+ } );
+
+ test( 'displays subscriber total', () => {
+ render(
);
+ userEvent.type( screen.getByText( defaultAttributes.submitButtonText ), ' right now!' );
+
+ expect( setAttributes ).toHaveBeenCalledWith( {
+ submitButtonText: `${ defaultAttributes.submitButtonText} right now!`,
+ } );
+ } );
+
+ test( 'displays subscriber total', () => {
+ const { container, rerender } = render(
);
+ expect( container.querySelector( 'p' ) ).not.toBeInTheDocument();
+ expect( container.querySelector( '.wp-block-jetpack-subscriptions__show-subs' ) ).not.toBeInTheDocument();
+
+ const updatedProps = {
+ ...defaultProps,
+ attributes: {
+ ...defaultAttributes,
+ showSubscribersTotal: true,
+ },
+ };
+ rerender(
);
+
+ expect( container.querySelector( '.wp-block-jetpack-subscriptions__show-subs' ) ).toBeInTheDocument();
+ expect( container.querySelector( 'p' ) ).toBeInTheDocument();
+ } );
+} );
diff --git a/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions.html b/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions.html
new file mode 100644
index 0000000000000..8335599e45d60
--- /dev/null
+++ b/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions.html
@@ -0,0 +1,3 @@
+
+
[jetpack_subscription_form show_subscribers_total="true" button_on_newline="true" custom_font_size="33" custom_border_radius="8" custom_border_weight="3" custom_padding="18" custom_spacing="10" submit_button_classes="has-33-font-size" email_field_classes="has-33-font-size" show_only_email_and_button="true"]
+
\ No newline at end of file
diff --git a/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions.json b/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions.json
new file mode 100644
index 0000000000000..d3b6afe8c2c41
--- /dev/null
+++ b/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions.json
@@ -0,0 +1,20 @@
+[
+ {
+ "clientId": "_clientId_0",
+ "name": "jetpack/subscriptions",
+ "isValid": true,
+ "attributes": {
+ "subscribePlaceholder": "Enter your email address",
+ "showSubscribersTotal": true,
+ "buttonOnNewLine": true,
+ "submitButtonText": "Sign Up",
+ "fontSize": "33px",
+ "customFontSize": "33px",
+ "borderRadius": 8,
+ "borderWeight": 3,
+ "padding": 18
+ },
+ "innerBlocks": [],
+ "originalContent": "
[jetpack_subscription_form show_subscribers_total=\"true\" button_on_newline=\"true\" custom_font_size=\"33\" custom_border_radius=\"8\" custom_border_weight=\"3\" custom_padding=\"18\" custom_spacing=\"10\" submit_button_classes=\"has-33-font-size\" email_field_classes=\"has-33-font-size\" show_only_email_and_button=\"true\"]
"
+ }
+]
diff --git a/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions.parsed.json b/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions.parsed.json
new file mode 100644
index 0000000000000..218aef8bb1110
--- /dev/null
+++ b/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions.parsed.json
@@ -0,0 +1,19 @@
+[
+ {
+ "blockName": "jetpack/subscriptions",
+ "attrs": {
+ "showSubscribersTotal": true,
+ "buttonOnNewLine": true,
+ "fontSize": 33,
+ "customFontSize": 33,
+ "borderRadius": 8,
+ "borderWeight": 3,
+ "padding": 18
+ },
+ "innerBlocks": [],
+ "innerHTML": "\n
[jetpack_subscription_form show_subscribers_total=\"true\" button_on_newline=\"true\" custom_font_size=\"33\" custom_border_radius=\"8\" custom_border_weight=\"3\" custom_padding=\"18\" custom_spacing=\"10\" submit_button_classes=\"has-33-font-size\" email_field_classes=\"has-33-font-size\" show_only_email_and_button=\"true\"]
\n",
+ "innerContent": [
+ "\n
[jetpack_subscription_form show_subscribers_total=\"true\" button_on_newline=\"true\" custom_font_size=\"33\" custom_border_radius=\"8\" custom_border_weight=\"3\" custom_padding=\"18\" custom_spacing=\"10\" submit_button_classes=\"has-33-font-size\" email_field_classes=\"has-33-font-size\" show_only_email_and_button=\"true\"]
\n"
+ ]
+ }
+]
diff --git a/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions.serialized.html b/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions.serialized.html
new file mode 100644
index 0000000000000..2e2cad855fea5
--- /dev/null
+++ b/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions.serialized.html
@@ -0,0 +1,3 @@
+
+
[jetpack_subscription_form subscribe_placeholder="Enter your email address" show_subscribers_total="true" button_on_newline="true" submit_button_text="Sign Up" custom_font_size="33px" custom_border_radius="8" custom_border_weight="3" custom_padding="18" custom_spacing="10" submit_button_classes="has-33-px-font-size" email_field_classes="has-33-px-font-size" show_only_email_and_button="true"]
+
diff --git a/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions__deprecated-1.html b/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions__deprecated-1.html
new file mode 100644
index 0000000000000..b1ebcf71bdbd6
--- /dev/null
+++ b/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions__deprecated-1.html
@@ -0,0 +1,3 @@
+
+
[jetpack_subscription_form show_subscribers_total="false" show_only_email_and_button="true"]
+
\ No newline at end of file
diff --git a/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions__deprecated-1.json b/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions__deprecated-1.json
new file mode 100644
index 0000000000000..f9ffe04412c28
--- /dev/null
+++ b/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions__deprecated-1.json
@@ -0,0 +1,13 @@
+[
+ {
+ "clientId": "_clientId_0",
+ "name": "jetpack/subscriptions",
+ "isValid": true,
+ "attributes": {
+ "submitButtonText": "Subscribe",
+ "showSubscribersTotal": false
+ },
+ "innerBlocks": [],
+ "originalContent": "
[jetpack_subscription_form show_subscribers_total=\"false\" show_only_email_and_button=\"true\"]
"
+ }
+]
diff --git a/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions__deprecated-1.parsed.json b/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions__deprecated-1.parsed.json
new file mode 100644
index 0000000000000..1ef86d3687a13
--- /dev/null
+++ b/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions__deprecated-1.parsed.json
@@ -0,0 +1,11 @@
+[
+ {
+ "blockName": "jetpack/subscriptions",
+ "attrs": {},
+ "innerBlocks": [],
+ "innerHTML": "\n
[jetpack_subscription_form show_subscribers_total=\"false\" show_only_email_and_button=\"true\"]
\n",
+ "innerContent": [
+ "\n
[jetpack_subscription_form show_subscribers_total=\"false\" show_only_email_and_button=\"true\"]
\n"
+ ]
+ }
+]
diff --git a/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions__deprecated-1.serialized.html b/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions__deprecated-1.serialized.html
new file mode 100644
index 0000000000000..1a13ffe599d5a
--- /dev/null
+++ b/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions__deprecated-1.serialized.html
@@ -0,0 +1,3 @@
+
+
[jetpack_subscription_form show_subscribers_total="false" custom_font_size="16px" custom_border_radius="0" custom_border_weight="1" custom_padding="15" custom_spacing="10" submit_button_classes="" email_field_classes="" show_only_email_and_button="true"]
+
diff --git a/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions__deprecated-2.html b/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions__deprecated-2.html
new file mode 100644
index 0000000000000..8907d28971da4
--- /dev/null
+++ b/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions__deprecated-2.html
@@ -0,0 +1,3 @@
+
+
[jetpack_subscription_form show_only_email_and_button="true" custom_background_button_color="#ffffff" custom_text_button_color="#000000" submit_button_text="Subscribe" submit_button_classes="" show_subscribers_total="false" ]
+
\ No newline at end of file
diff --git a/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions__deprecated-2.json b/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions__deprecated-2.json
new file mode 100644
index 0000000000000..4b4bfa88f3818
--- /dev/null
+++ b/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions__deprecated-2.json
@@ -0,0 +1,19 @@
+[
+ {
+ "clientId": "_clientId_0",
+ "name": "jetpack/subscriptions",
+ "isValid": true,
+ "attributes": {
+ "subscribePlaceholder": "Email Address",
+ "showSubscribersTotal": false,
+ "buttonOnNewLine": true,
+ "submitButtonText": "Subscribe",
+ "buttonBackgroundColor": "primary",
+ "customButtonBackgroundColor": "#ffffff",
+ "textColor": "background",
+ "customTextColor": "#000000"
+ },
+ "innerBlocks": [],
+ "originalContent": "
[jetpack_subscription_form show_only_email_and_button=\"true\" custom_background_button_color=\"#ffffff\" custom_text_button_color=\"#000000\" submit_button_text=\"Subscribe\" submit_button_classes=\"\" show_subscribers_total=\"false\" ]
"
+ }
+]
diff --git a/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions__deprecated-2.parsed.json b/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions__deprecated-2.parsed.json
new file mode 100644
index 0000000000000..c0e3b2e358387
--- /dev/null
+++ b/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions__deprecated-2.parsed.json
@@ -0,0 +1,16 @@
+[
+ {
+ "blockName": "jetpack/subscriptions",
+ "attrs": {
+ "customBackgroundButtonColor": "#ffffff",
+ "customTextButtonColor": "#000000",
+ "submitButtonText": "Subscribe",
+ "submitButtonClasses": ""
+ },
+ "innerBlocks": [],
+ "innerHTML": "\n
[jetpack_subscription_form show_only_email_and_button=\"true\" custom_background_button_color=\"#ffffff\" custom_text_button_color=\"#000000\" submit_button_text=\"Subscribe\" submit_button_classes=\"\" show_subscribers_total=\"false\" ]
\n",
+ "innerContent": [
+ "\n
[jetpack_subscription_form show_only_email_and_button=\"true\" custom_background_button_color=\"#ffffff\" custom_text_button_color=\"#000000\" submit_button_text=\"Subscribe\" submit_button_classes=\"\" show_subscribers_total=\"false\" ]
\n"
+ ]
+ }
+]
diff --git a/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions__deprecated-2.serialized.html b/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions__deprecated-2.serialized.html
new file mode 100644
index 0000000000000..01f8f98b9e452
--- /dev/null
+++ b/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions__deprecated-2.serialized.html
@@ -0,0 +1,3 @@
+
+
[jetpack_subscription_form show_subscribers_total="false" button_on_newline="true" custom_background_button_color="#ffffff" custom_text_button_color="#000000" custom_font_size="16px" custom_border_radius="0" custom_border_weight="1" custom_padding="15" custom_spacing="10" submit_button_classes="has-text-color has-background-color has-background has-primary-background-color" email_field_classes="" show_only_email_and_button="true"]
+
diff --git a/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions__deprecated-3.html b/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions__deprecated-3.html
new file mode 100644
index 0000000000000..b781e1f246716
--- /dev/null
+++ b/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions__deprecated-3.html
@@ -0,0 +1,22 @@
+
+
+ [jetpack_subscription_form
+ subscribe_placeholder="Email Address"
+ show_subscribers_total="false"
+ button_on_newline="false"
+ submit_button_text="Subscribe"
+ custom_background_emailfield_color="undefined"
+ custom_background_button_color="undefined"
+ custom_text_button_color="undefined"
+ custom_font_size="16"
+ custom_border_radius="0"
+ custom_border_weight="1"
+ custom_border_color="undefined"
+ custom_padding="15"
+ custom_spacing="10"
+ submit_button_classes=""
+ email_field_classes=""
+ show_only_email_and_button="true"
+ ]
+
+
\ No newline at end of file
diff --git a/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions__deprecated-3.json b/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions__deprecated-3.json
new file mode 100644
index 0000000000000..cd8d0d9f6bfe3
--- /dev/null
+++ b/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions__deprecated-3.json
@@ -0,0 +1,15 @@
+[
+ {
+ "clientId": "_clientId_0",
+ "name": "jetpack/subscriptions",
+ "isValid": true,
+ "attributes": {
+ "subscribePlaceholder": "Email Address",
+ "showSubscribersTotal": false,
+ "buttonOnNewLine": false,
+ "submitButtonText": "Subscribe"
+ },
+ "innerBlocks": [],
+ "originalContent": "
\n\t[jetpack_subscription_form\n\t\tsubscribe_placeholder=\"Email Address\"\n\t\tshow_subscribers_total=\"false\"\n\t\tbutton_on_newline=\"false\"\n\t\tsubmit_button_text=\"Subscribe\"\n\t\tcustom_background_emailfield_color=\"undefined\"\n\t\tcustom_background_button_color=\"undefined\"\n\t\tcustom_text_button_color=\"undefined\"\n\t\tcustom_font_size=\"16\"\n\t\tcustom_border_radius=\"0\"\n\t\tcustom_border_weight=\"1\"\n\t\tcustom_border_color=\"undefined\"\n\t\tcustom_padding=\"15\"\n\t\tcustom_spacing=\"10\"\n\t\tsubmit_button_classes=\"\"\n\t\temail_field_classes=\"\"\n\t\tshow_only_email_and_button=\"true\"\n\t]\n
"
+ }
+]
diff --git a/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions__deprecated-3.parsed.json b/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions__deprecated-3.parsed.json
new file mode 100644
index 0000000000000..582a9fcd1a608
--- /dev/null
+++ b/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions__deprecated-3.parsed.json
@@ -0,0 +1,14 @@
+[
+ {
+ "blockName": "jetpack/subscriptions",
+ "attrs": {
+ "subscribePlaceholder": "Email Address",
+ "submitButtonText": "Subscribe"
+ },
+ "innerBlocks": [],
+ "innerHTML": "\n
\n\t[jetpack_subscription_form\n\t\tsubscribe_placeholder=\"Email Address\"\n\t\tshow_subscribers_total=\"false\"\n\t\tbutton_on_newline=\"false\"\n\t\tsubmit_button_text=\"Subscribe\"\n\t\tcustom_background_emailfield_color=\"undefined\"\n\t\tcustom_background_button_color=\"undefined\"\n\t\tcustom_text_button_color=\"undefined\"\n\t\tcustom_font_size=\"16\"\n\t\tcustom_border_radius=\"0\"\n\t\tcustom_border_weight=\"1\"\n\t\tcustom_border_color=\"undefined\"\n\t\tcustom_padding=\"15\"\n\t\tcustom_spacing=\"10\"\n\t\tsubmit_button_classes=\"\"\n\t\temail_field_classes=\"\"\n\t\tshow_only_email_and_button=\"true\"\n\t]\n
\n",
+ "innerContent": [
+ "\n
\n\t[jetpack_subscription_form\n\t\tsubscribe_placeholder=\"Email Address\"\n\t\tshow_subscribers_total=\"false\"\n\t\tbutton_on_newline=\"false\"\n\t\tsubmit_button_text=\"Subscribe\"\n\t\tcustom_background_emailfield_color=\"undefined\"\n\t\tcustom_background_button_color=\"undefined\"\n\t\tcustom_text_button_color=\"undefined\"\n\t\tcustom_font_size=\"16\"\n\t\tcustom_border_radius=\"0\"\n\t\tcustom_border_weight=\"1\"\n\t\tcustom_border_color=\"undefined\"\n\t\tcustom_padding=\"15\"\n\t\tcustom_spacing=\"10\"\n\t\tsubmit_button_classes=\"\"\n\t\temail_field_classes=\"\"\n\t\tshow_only_email_and_button=\"true\"\n\t]\n
\n"
+ ]
+ }
+]
diff --git a/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions__deprecated-3.serialized.html b/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions__deprecated-3.serialized.html
new file mode 100644
index 0000000000000..8c87616d00ba2
--- /dev/null
+++ b/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions__deprecated-3.serialized.html
@@ -0,0 +1,3 @@
+
+
[jetpack_subscription_form show_subscribers_total="false" button_on_newline="false" custom_font_size="16px" custom_border_radius="0" custom_border_weight="1" custom_padding="15" custom_spacing="10" submit_button_classes="" email_field_classes="" show_only_email_and_button="true"]
+
diff --git a/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions__deprecated-4.html b/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions__deprecated-4.html
new file mode 100644
index 0000000000000..11b7e7046adad
--- /dev/null
+++ b/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions__deprecated-4.html
@@ -0,0 +1,22 @@
+
+
+ [jetpack_subscription_form
+ subscribe_placeholder="Enter your email address"
+ show_subscribers_total="false"
+ button_on_newline="false"
+ submit_button_text="Sign Up"
+ custom_background_emailfield_color="undefined"
+ custom_background_button_color="undefined"
+ custom_text_button_color="undefined"
+ custom_font_size="16"
+ custom_border_radius="0"
+ custom_border_weight="1"
+ custom_border_color="undefined"
+ custom_padding="15"
+ custom_spacing="10"
+ submit_button_classes=""
+ email_field_classes=""
+ show_only_email_and_button="true"
+ ]
+
+
\ No newline at end of file
diff --git a/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions__deprecated-4.json b/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions__deprecated-4.json
new file mode 100644
index 0000000000000..5b2923a3ffc2a
--- /dev/null
+++ b/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions__deprecated-4.json
@@ -0,0 +1,15 @@
+[
+ {
+ "clientId": "_clientId_0",
+ "name": "jetpack/subscriptions",
+ "isValid": true,
+ "attributes": {
+ "subscribePlaceholder": "Enter your email address",
+ "showSubscribersTotal": false,
+ "buttonOnNewLine": false,
+ "submitButtonText": "Sign Up"
+ },
+ "innerBlocks": [],
+ "originalContent": "
\n\t[jetpack_subscription_form\n\t\tsubscribe_placeholder=\"Enter your email address\"\n\t\tshow_subscribers_total=\"false\"\n\t\tbutton_on_newline=\"false\"\n\t\tsubmit_button_text=\"Sign Up\"\n\t\tcustom_background_emailfield_color=\"undefined\"\n\t\tcustom_background_button_color=\"undefined\"\n\t\tcustom_text_button_color=\"undefined\"\n\t\tcustom_font_size=\"16\"\n\t\tcustom_border_radius=\"0\"\n\t\tcustom_border_weight=\"1\"\n\t\tcustom_border_color=\"undefined\"\n\t\tcustom_padding=\"15\"\n\t\tcustom_spacing=\"10\"\n\t\tsubmit_button_classes=\"\"\n\t\temail_field_classes=\"\"\n\t\tshow_only_email_and_button=\"true\"\n\t]\n
"
+ }
+]
diff --git a/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions__deprecated-4.parsed.json b/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions__deprecated-4.parsed.json
new file mode 100644
index 0000000000000..6a04678da91a8
--- /dev/null
+++ b/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions__deprecated-4.parsed.json
@@ -0,0 +1,14 @@
+[
+ {
+ "blockName": "jetpack/subscriptions",
+ "attrs": {
+ "subscribePlaceholder": "Enter your email address",
+ "submitButtonText": "Sign Up"
+ },
+ "innerBlocks": [],
+ "innerHTML": "\n
\n\t[jetpack_subscription_form\n\t\tsubscribe_placeholder=\"Enter your email address\"\n\t\tshow_subscribers_total=\"false\"\n\t\tbutton_on_newline=\"false\"\n\t\tsubmit_button_text=\"Sign Up\"\n\t\tcustom_background_emailfield_color=\"undefined\"\n\t\tcustom_background_button_color=\"undefined\"\n\t\tcustom_text_button_color=\"undefined\"\n\t\tcustom_font_size=\"16\"\n\t\tcustom_border_radius=\"0\"\n\t\tcustom_border_weight=\"1\"\n\t\tcustom_border_color=\"undefined\"\n\t\tcustom_padding=\"15\"\n\t\tcustom_spacing=\"10\"\n\t\tsubmit_button_classes=\"\"\n\t\temail_field_classes=\"\"\n\t\tshow_only_email_and_button=\"true\"\n\t]\n
\n",
+ "innerContent": [
+ "\n
\n\t[jetpack_subscription_form\n\t\tsubscribe_placeholder=\"Enter your email address\"\n\t\tshow_subscribers_total=\"false\"\n\t\tbutton_on_newline=\"false\"\n\t\tsubmit_button_text=\"Sign Up\"\n\t\tcustom_background_emailfield_color=\"undefined\"\n\t\tcustom_background_button_color=\"undefined\"\n\t\tcustom_text_button_color=\"undefined\"\n\t\tcustom_font_size=\"16\"\n\t\tcustom_border_radius=\"0\"\n\t\tcustom_border_weight=\"1\"\n\t\tcustom_border_color=\"undefined\"\n\t\tcustom_padding=\"15\"\n\t\tcustom_spacing=\"10\"\n\t\tsubmit_button_classes=\"\"\n\t\temail_field_classes=\"\"\n\t\tshow_only_email_and_button=\"true\"\n\t]\n
\n"
+ ]
+ }
+]
diff --git a/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions__deprecated-4.serialized.html b/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions__deprecated-4.serialized.html
new file mode 100644
index 0000000000000..9e2f8e2c1d337
--- /dev/null
+++ b/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions__deprecated-4.serialized.html
@@ -0,0 +1,3 @@
+
+
[jetpack_subscription_form subscribe_placeholder="Enter your email address" show_subscribers_total="false" button_on_newline="false" submit_button_text="Sign Up" custom_font_size="16px" custom_border_radius="0" custom_border_weight="1" custom_padding="15" custom_spacing="10" submit_button_classes="" email_field_classes="" show_only_email_and_button="true"]
+
diff --git a/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions__deprecated-5.html b/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions__deprecated-5.html
new file mode 100644
index 0000000000000..7530b79d54d5f
--- /dev/null
+++ b/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions__deprecated-5.html
@@ -0,0 +1,3 @@
+
+
[jetpack_subscription_form subscribe_placeholder="Email Address" show_subscribers_total="false" button_on_newline="false" submit_button_text="Subscribe" custom_font_size="33" custom_border_radius="0" custom_border_weight="1" custom_padding="15" custom_spacing="10" submit_button_classes="" email_field_classes="" show_only_email_and_button="true"]
+
diff --git a/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions__deprecated-5.json b/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions__deprecated-5.json
new file mode 100644
index 0000000000000..be701e137dbec
--- /dev/null
+++ b/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions__deprecated-5.json
@@ -0,0 +1,16 @@
+[
+ {
+ "clientId": "_clientId_0",
+ "name": "jetpack/subscriptions",
+ "isValid": true,
+ "attributes": {
+ "subscribePlaceholder": "Email Address",
+ "showSubscribersTotal": false,
+ "buttonOnNewLine": false,
+ "submitButtonText": "Subscribe",
+ "customFontSize": "33px"
+ },
+ "innerBlocks": [],
+ "originalContent": "
[jetpack_subscription_form subscribe_placeholder=\"Email Address\" show_subscribers_total=\"false\" button_on_newline=\"false\" submit_button_text=\"Subscribe\" custom_font_size=\"33\" custom_border_radius=\"0\" custom_border_weight=\"1\" custom_padding=\"15\" custom_spacing=\"10\" submit_button_classes=\"\" email_field_classes=\"\" show_only_email_and_button=\"true\"]
"
+ }
+]
diff --git a/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions__deprecated-5.parsed.json b/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions__deprecated-5.parsed.json
new file mode 100644
index 0000000000000..079e4197d2a5f
--- /dev/null
+++ b/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions__deprecated-5.parsed.json
@@ -0,0 +1,24 @@
+[
+ {
+ "blockName": "jetpack/subscriptions",
+ "attrs": {
+ "subscribePlaceholder": "Email Address",
+ "submitButtonText": "Subscribe",
+ "customFontSize": 33
+ },
+ "innerBlocks": [],
+ "innerHTML": "\n
[jetpack_subscription_form subscribe_placeholder=\"Email Address\" show_subscribers_total=\"false\" button_on_newline=\"false\" submit_button_text=\"Subscribe\" custom_font_size=\"33\" custom_border_radius=\"0\" custom_border_weight=\"1\" custom_padding=\"15\" custom_spacing=\"10\" submit_button_classes=\"\" email_field_classes=\"\" show_only_email_and_button=\"true\"]
\n",
+ "innerContent": [
+ "\n
[jetpack_subscription_form subscribe_placeholder=\"Email Address\" show_subscribers_total=\"false\" button_on_newline=\"false\" submit_button_text=\"Subscribe\" custom_font_size=\"33\" custom_border_radius=\"0\" custom_border_weight=\"1\" custom_padding=\"15\" custom_spacing=\"10\" submit_button_classes=\"\" email_field_classes=\"\" show_only_email_and_button=\"true\"]
\n"
+ ]
+ },
+ {
+ "blockName": null,
+ "attrs": {},
+ "innerBlocks": [],
+ "innerHTML": "\n",
+ "innerContent": [
+ "\n"
+ ]
+ }
+]
diff --git a/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions__deprecated-5.serialized.html b/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions__deprecated-5.serialized.html
new file mode 100644
index 0000000000000..bab16107e1ae7
--- /dev/null
+++ b/projects/plugins/jetpack/extensions/blocks/subscriptions/test/fixtures/jetpack__subscriptions__deprecated-5.serialized.html
@@ -0,0 +1,3 @@
+
+
[jetpack_subscription_form show_subscribers_total="false" button_on_newline="false" custom_font_size="33px" custom_border_radius="0" custom_border_weight="1" custom_padding="15" custom_spacing="10" submit_button_classes="" email_field_classes="" show_only_email_and_button="true"]
+
diff --git a/projects/plugins/jetpack/extensions/blocks/subscriptions/test/validate.js b/projects/plugins/jetpack/extensions/blocks/subscriptions/test/validate.js
new file mode 100644
index 0000000000000..0eee11719eeab
--- /dev/null
+++ b/projects/plugins/jetpack/extensions/blocks/subscriptions/test/validate.js
@@ -0,0 +1,11 @@
+/**
+ * Internal dependencies
+ */
+import { name, settings } from '../';
+import runBlockFixtureTests from '../../../shared/test/block-fixtures';
+
+// Need to include all the blocks involved in rendering this block.
+// The main block should be the first in the array.
+const blocks = [ { name: `jetpack/${ name }`, settings } ];
+
+runBlockFixtureTests( `jetpack/${ name }`, blocks, __dirname );