From 78dd21f2e8e21c4beb6ee8d81258eb3fd34f15ef Mon Sep 17 00:00:00 2001 From: Jorge Date: Thu, 8 Nov 2018 03:14:10 +0000 Subject: [PATCH 1/3] Fix: Contrast checker: Consider fontSize large when size >= 24px instead of >= 18px (#9268) --- packages/block-library/src/button/edit.js | 4 +++- packages/editor/src/components/contrast-checker/index.js | 4 ++-- .../contrast-checker/test/__snapshots__/index.js.snap | 4 ++-- .../editor/src/components/contrast-checker/test/index.js | 8 ++++---- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/packages/block-library/src/button/edit.js b/packages/block-library/src/button/edit.js index b101c13c560d68..860d6a1fb64b6b 100644 --- a/packages/block-library/src/button/edit.js +++ b/packages/block-library/src/button/edit.js @@ -114,7 +114,9 @@ class ButtonEdit extends Component { > = 18 ) ? 'large' : 'small' ) } + { level: 'AA', size: ( isLargeText || ( isLargeText !== false && fontSize >= 24 ) ? 'large' : 'small' ) } ) ) { return null; } diff --git a/packages/editor/src/components/contrast-checker/test/__snapshots__/index.js.snap b/packages/editor/src/components/contrast-checker/test/__snapshots__/index.js.snap index 6bb1dc8d4f5bfb..1c56207c62bea2 100644 --- a/packages/editor/src/components/contrast-checker/test/__snapshots__/index.js.snap +++ b/packages/editor/src/components/contrast-checker/test/__snapshots__/index.js.snap @@ -87,7 +87,7 @@ exports[`ContrastChecker should render messages when the textColor is valid, but exports[`ContrastChecker should take into consideration the font size passed 1`] = `
diff --git a/packages/editor/src/components/contrast-checker/test/index.js b/packages/editor/src/components/contrast-checker/test/index.js index ee7cdc81613433..eca63c0e7b97d8 100644 --- a/packages/editor/src/components/contrast-checker/test/index.js +++ b/packages/editor/src/components/contrast-checker/test/index.js @@ -115,7 +115,7 @@ describe( 'ContrastChecker', () => { ); @@ -125,7 +125,7 @@ describe( 'ContrastChecker', () => { ); @@ -137,7 +137,7 @@ describe( 'ContrastChecker', () => { ); @@ -148,7 +148,7 @@ describe( 'ContrastChecker', () => { ); From 4e9d9b3d36841c264bce35d4bf1ba3d9ff75f659 Mon Sep 17 00:00:00 2001 From: Matthew Riley MacPherson Date: Thu, 8 Nov 2018 03:46:46 +0000 Subject: [PATCH 2/3] chore: Improve undo/redo no-op (#11428) * chore: Improve undo/redo no-op See: https://github.com/WordPress/gutenberg/pull/11379\#discussion_r230406108 * Do not wrap dispatch undo/redo --- .../editor/src/components/editor-history/redo.js | 16 ++++++---------- .../editor/src/components/editor-history/undo.js | 16 ++++++---------- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/packages/editor/src/components/editor-history/redo.js b/packages/editor/src/components/editor-history/redo.js index 33cd412d2adf42..de6c3e46a26daf 100644 --- a/packages/editor/src/components/editor-history/redo.js +++ b/packages/editor/src/components/editor-history/redo.js @@ -13,8 +13,11 @@ function EditorHistoryRedo( { hasRedo, redo } ) { icon="redo" label={ __( 'Redo' ) } shortcut={ displayShortcut.primaryShift( 'z' ) } + // If there are no redo levels we don't want to actually disable this + // button, because it will remove focus for keyboard users. + // See: https://github.com/WordPress/gutenberg/issues/3486 aria-disabled={ ! hasRedo } - onClick={ redo } + onClick={ hasRedo ? redo : undefined } className="editor-history__redo" /> ); @@ -24,14 +27,7 @@ export default compose( [ withSelect( ( select ) => ( { hasRedo: select( 'core/editor' ).hasEditorRedo(), } ) ), - withDispatch( ( dispatch, ownProps ) => ( { - redo: () => { - // If there are no redo levels this is a no-op, because we don't actually - // disable the button. - // See: https://github.com/WordPress/gutenberg/issues/3486 - if ( ownProps.hasRedo ) { - dispatch( 'core/editor' ).redo(); - } - }, + withDispatch( ( dispatch ) => ( { + redo: dispatch( 'core/editor' ).redo, } ) ), ] )( EditorHistoryRedo ); diff --git a/packages/editor/src/components/editor-history/undo.js b/packages/editor/src/components/editor-history/undo.js index 008654dd434009..6c3826cc7f1f4d 100644 --- a/packages/editor/src/components/editor-history/undo.js +++ b/packages/editor/src/components/editor-history/undo.js @@ -13,8 +13,11 @@ function EditorHistoryUndo( { hasUndo, undo } ) { icon="undo" label={ __( 'Undo' ) } shortcut={ displayShortcut.primary( 'z' ) } + // If there are no undo levels we don't want to actually disable this + // button, because it will remove focus for keyboard users. + // See: https://github.com/WordPress/gutenberg/issues/3486 aria-disabled={ ! hasUndo } - onClick={ undo } + onClick={ hasUndo ? undo : undefined } className="editor-history__undo" /> ); @@ -24,14 +27,7 @@ export default compose( [ withSelect( ( select ) => ( { hasUndo: select( 'core/editor' ).hasEditorUndo(), } ) ), - withDispatch( ( dispatch, ownProps ) => ( { - undo: () => { - // If there are no undo levels this is a no-op, because we don't actually - // disable the button. - // See: https://github.com/WordPress/gutenberg/issues/3486 - if ( ownProps.hasUndo ) { - dispatch( 'core/editor' ).undo(); - } - }, + withDispatch( ( dispatch ) => ( { + undo: dispatch( 'core/editor' ).undo, } ) ), ] )( EditorHistoryUndo ); From a9b0742ea2cd5b2bd39ac7242ceacc10aa538565 Mon Sep 17 00:00:00 2001 From: Michael Savchuk Date: Thu, 8 Nov 2018 00:26:58 -0800 Subject: [PATCH 3/3] Add missing tests for Format API code (#11562) * Add missing tests for Format API code * Add missing tests for Format API code * Rebase, fix, and apply feedback --- packages/rich-text/src/insert-object.js | 2 +- packages/rich-text/src/store/test/actions.js | 30 +++++ .../rich-text/src/store/test/selectors.js | 38 ++++++ .../rich-text/src/test/get-format-type.js | 43 ++++++ .../rich-text/src/test/get-format-types.js | 57 ++++++++ packages/rich-text/src/test/insert-object.js | 36 +++++ .../src/test/register-format-type.js | 125 ++++++++++++++++-- packages/rich-text/src/test/toggle-format.js | 56 ++++++++ .../src/test/unregister-format-type.js | 53 ++++++++ 9 files changed, 427 insertions(+), 13 deletions(-) create mode 100644 packages/rich-text/src/store/test/actions.js create mode 100644 packages/rich-text/src/store/test/selectors.js create mode 100644 packages/rich-text/src/test/get-format-type.js create mode 100644 packages/rich-text/src/test/get-format-types.js create mode 100644 packages/rich-text/src/test/insert-object.js create mode 100644 packages/rich-text/src/test/toggle-format.js create mode 100644 packages/rich-text/src/test/unregister-format-type.js diff --git a/packages/rich-text/src/insert-object.js b/packages/rich-text/src/insert-object.js index b3486bcec4ebbe..bf67ac3913b739 100644 --- a/packages/rich-text/src/insert-object.js +++ b/packages/rich-text/src/insert-object.js @@ -12,7 +12,7 @@ const OBJECT_REPLACEMENT_CHARACTER = '\ufffc'; * removed. Indices are retrieved from the selection if none are provided. * * @param {Object} value Value to modify. - * @param {string} formatToInsert Format to insert as object. + * @param {Object} formatToInsert Format to insert as object. * @param {number} startIndex Start index. * @param {number} endIndex End index. * diff --git a/packages/rich-text/src/store/test/actions.js b/packages/rich-text/src/store/test/actions.js new file mode 100644 index 00000000000000..a01c64e18b5419 --- /dev/null +++ b/packages/rich-text/src/store/test/actions.js @@ -0,0 +1,30 @@ +/** + * Internal dependencies + */ +import { addFormatTypes, removeFormatTypes } from '../actions'; + +describe( 'actions', () => { + describe( 'addFormatTypes', () => { + it( 'should cast format types as an array', () => { + const formatTypes = { name: 'core/test-format' }; + const expected = { + type: 'ADD_FORMAT_TYPES', + formatTypes: [ formatTypes ], + }; + + expect( addFormatTypes( formatTypes ) ).toEqual( expected ); + } ); + } ); + + describe( 'removeFormatTypes', () => { + it( 'should cast format types as an array', () => { + const names = 'core/test-format'; + const expected = { + type: 'REMOVE_FORMAT_TYPES', + names: [ names ], + }; + + expect( removeFormatTypes( names ) ).toEqual( expected ); + } ); + } ); +} ); diff --git a/packages/rich-text/src/store/test/selectors.js b/packages/rich-text/src/store/test/selectors.js new file mode 100644 index 00000000000000..ca49185a6e6b1a --- /dev/null +++ b/packages/rich-text/src/store/test/selectors.js @@ -0,0 +1,38 @@ +/** + * External dependencies + */ +import deepFreeze from 'deep-freeze'; + +/** + * Internal dependencies + */ +import { getFormatTypes, getFormatType } from '../selectors'; + +describe( 'selectors', () => { + const defaultState = deepFreeze( { + formatTypes: { + 'core/test-format': { name: 'core/test-format' }, + 'core/test-format-2': { name: 'core/test-format-2' }, + }, + } ); + + describe( 'getFormatTypes', () => { + it( 'should get format types', () => { + const expected = [ + { name: 'core/test-format' }, + { name: 'core/test-format-2' }, + ]; + + expect( getFormatTypes( defaultState ) ).toEqual( expected ); + } ); + } ); + + describe( 'getFormatType', () => { + it( 'should get a format type', () => { + const expected = { name: 'core/test-format' }; + const result = getFormatType( defaultState, 'core/test-format' ); + + expect( result ).toEqual( expected ); + } ); + } ); +} ); diff --git a/packages/rich-text/src/test/get-format-type.js b/packages/rich-text/src/test/get-format-type.js new file mode 100644 index 00000000000000..edbb3d719d4f7b --- /dev/null +++ b/packages/rich-text/src/test/get-format-type.js @@ -0,0 +1,43 @@ +/** + * External dependencies + */ +import { noop } from 'lodash'; + +/** + * Internal dependencies + */ +import { getFormatType } from '../get-format-type'; +import { unregisterFormatType } from '../unregister-format-type'; +import { registerFormatType } from '../register-format-type'; +import { getFormatTypes } from '../get-format-types'; + +describe( 'getFormatType', () => { + beforeAll( () => { + // Initialize the rich-text store. + require( '../store' ); + } ); + + afterEach( () => { + getFormatTypes().forEach( ( format ) => { + unregisterFormatType( format.name ); + } ); + } ); + + it( 'should return all format type elements', () => { + const formatType = { + edit: noop, + title: 'format title', + keywords: [ 'one', 'two', 'three' ], + formatTestSetting: 'settingTestValue', + tagName: 'test', + className: null, + }; + + registerFormatType( 'core/test-format-with-settings', formatType ); + + expect( getFormatType( 'core/test-format-with-settings' ) ).toEqual( { + name: 'core/test-format-with-settings', + ...formatType, + } ); + } ); +} ); diff --git a/packages/rich-text/src/test/get-format-types.js b/packages/rich-text/src/test/get-format-types.js new file mode 100644 index 00000000000000..1f7939198c8251 --- /dev/null +++ b/packages/rich-text/src/test/get-format-types.js @@ -0,0 +1,57 @@ +/** + * External dependencies + */ +import { noop } from 'lodash'; + +/** + * Internal dependencies + */ +import { getFormatTypes } from '../get-format-types'; +import { unregisterFormatType } from '../unregister-format-type'; +import { registerFormatType } from '../register-format-type'; + +describe( 'getFormatTypes', () => { + beforeAll( () => { + // Initialize the rich-text store. + require( '../store' ); + } ); + + afterEach( () => { + getFormatTypes().forEach( ( format ) => { + unregisterFormatType( format.name ); + } ); + } ); + + it( 'should return an empty array at first', () => { + expect( getFormatTypes() ).toEqual( [] ); + } ); + + it( 'should return all registered formats', () => { + const testFormat = { + edit: noop, + title: 'format title', + tagName: 'test', + className: null, + }; + const testFormatWithSettings = { + edit: noop, + title: 'format title 2', + keywords: [ 'one', 'two', 'three' ], + tagName: 'test 2', + className: null, + formatTestSetting: 'settingTestValue', + }; + registerFormatType( 'core/test-format', testFormat ); + registerFormatType( 'core/test-format-with-settings', testFormatWithSettings ); + expect( getFormatTypes() ).toEqual( [ + { + name: 'core/test-format', + ...testFormat, + }, + { + name: 'core/test-format-with-settings', + ...testFormatWithSettings, + }, + ] ); + } ); +} ); diff --git a/packages/rich-text/src/test/insert-object.js b/packages/rich-text/src/test/insert-object.js new file mode 100644 index 00000000000000..15680372986a9d --- /dev/null +++ b/packages/rich-text/src/test/insert-object.js @@ -0,0 +1,36 @@ +/** + * External dependencies + */ +import deepFreeze from 'deep-freeze'; + +/** + * Internal dependencies + */ +import { insertObject } from '../insert-object'; +import { getSparseArrayLength } from './helpers'; +import { OBJECT_REPLACEMENT_CHARACTER } from '../special-characters'; + +describe( 'insert', () => { + const obj = { type: 'obj' }; + const em = { type: 'em' }; + + it( 'should delete and insert', () => { + const record = { + formats: [ , , , , [ em ], [ em ], [ em ], , , , , , , ], + text: 'one two three', + start: 6, + end: 6, + }; + const expected = { + formats: [ , , [ { ...obj, object: true } ], [ em ], , , , , , , ], + text: `on${ OBJECT_REPLACEMENT_CHARACTER }o three`, + start: 3, + end: 3, + }; + const result = insertObject( deepFreeze( record ), obj, 2, 6 ); + + expect( result ).toEqual( expected ); + expect( result ).not.toBe( record ); + expect( getSparseArrayLength( result.formats ) ).toBe( 2 ); + } ); +} ); diff --git a/packages/rich-text/src/test/register-format-type.js b/packages/rich-text/src/test/register-format-type.js index 5dadffb050abf6..cde3c900e8b41c 100644 --- a/packages/rich-text/src/test/register-format-type.js +++ b/packages/rich-text/src/test/register-format-type.js @@ -6,9 +6,9 @@ import { select } from '@wordpress/data'; /** * Internal dependencies */ - import { registerFormatType } from '../register-format-type'; import { unregisterFormatType } from '../unregister-format-type'; +import { getFormatType } from '../get-format-type'; describe( 'registerFormatType', () => { beforeAll( () => { @@ -37,57 +37,129 @@ describe( 'registerFormatType', () => { } ); it( 'should error without arguments', () => { - registerFormatType(); + const format = registerFormatType(); expect( console ).toHaveErroredWith( 'Format names must be strings.' ); + expect( format ).toBeUndefined(); + } ); + + it( 'should reject format types without a namespace', () => { + const format = registerFormatType( 'doing-it-wrong' ); + expect( console ).toHaveErroredWith( 'Format names must contain a namespace prefix, include only lowercase alphanumeric characters or dashes, and start with a letter. Example: my-plugin/my-custom-format' ); + expect( format ).toBeUndefined(); + } ); + + it( 'should reject format types with too many namespaces', () => { + const format = registerFormatType( 'doing/it/wrong' ); + expect( console ).toHaveErroredWith( 'Format names must contain a namespace prefix, include only lowercase alphanumeric characters or dashes, and start with a letter. Example: my-plugin/my-custom-format' ); + expect( format ).toBeUndefined(); + } ); + + it( 'should reject format types with invalid characters', () => { + const format = registerFormatType( 'still/_doing_it_wrong' ); + expect( console ).toHaveErroredWith( 'Format names must contain a namespace prefix, include only lowercase alphanumeric characters or dashes, and start with a letter. Example: my-plugin/my-custom-format' ); + expect( format ).toBeUndefined(); + } ); + + it( 'should reject format types with uppercase characters', () => { + const format = registerFormatType( 'Core/Bold' ); + expect( console ).toHaveErroredWith( 'Format names must contain a namespace prefix, include only lowercase alphanumeric characters or dashes, and start with a letter. Example: my-plugin/my-custom-format' ); + expect( format ).toBeUndefined(); } ); - it( 'should error on invalid name', () => { - registerFormatType( 'test', validSettings ); + it( 'should reject format types not starting with a letter', () => { + const format = registerFormatType( 'my-plugin/4-fancy-format' ); expect( console ).toHaveErroredWith( 'Format names must contain a namespace prefix, include only lowercase alphanumeric characters or dashes, and start with a letter. Example: my-plugin/my-custom-format' ); + expect( format ).toBeUndefined(); + } ); + + it( 'should reject numbers', () => { + const format = registerFormatType( 42 ); + expect( console ).toHaveErroredWith( 'Format names must be strings.' ); + expect( format ).toBeUndefined(); + } ); + + it( 'should accept valid format names', () => { + const format = registerFormatType( 'my-plugin/fancy-format-4', validSettings ); + expect( console ).not.toHaveErrored(); + expect( format ).toEqual( { + name: 'my-plugin/fancy-format-4', + ...validSettings, + } ); } ); it( 'should error on already registered name', () => { registerFormatType( validName, validSettings ); - registerFormatType( validName, validSettings ); + const duplicateFormat = registerFormatType( validName, validSettings ); expect( console ).toHaveErroredWith( 'Format "plugin/test" is already registered.' ); + expect( duplicateFormat ).toBeUndefined(); } ); it( 'should error on undefined edit property', () => { - registerFormatType( 'plugin/test', { + const format = registerFormatType( 'plugin/test', { ...validSettings, edit: undefined, } ); expect( console ).toHaveErroredWith( 'The "edit" property must be specified and must be a valid function.' ); + expect( format ).toBeUndefined(); + } ); + + it( 'should reject formats with an invalid edit function', () => { + const format = registerFormatType( validName, { + ...validSettings, + edit: 'not-a-function', + } ); + expect( console ).toHaveErroredWith( 'The "edit" property must be specified and must be a valid function.' ); + expect( format ).toBeUndefined(); + } ); + + it( 'should reject formats without tag name', () => { + const settings = { ...validSettings }; + delete settings.tagName; + const format = registerFormatType( validName, settings ); + expect( console ).toHaveErroredWith( 'Format tag names must be a string.' ); + expect( format ).toBeUndefined(); } ); it( 'should error on empty tagName property', () => { - registerFormatType( validName, { + const format = registerFormatType( validName, { ...validSettings, tagName: '', } ); expect( console ).toHaveErroredWith( 'Format tag names must be a string.' ); + expect( format ).toBeUndefined(); + } ); + + it( 'should reject formats without class name', () => { + const settings = { ...validSettings }; + delete settings.className; + const format = registerFormatType( validName, settings ); + expect( console ).toHaveErroredWith( 'Format class names must be a string, or null to handle bare elements.' ); + expect( format ).toBeUndefined(); } ); it( 'should error on invalid empty className property', () => { - registerFormatType( validName, { + const format = registerFormatType( validName, { ...validSettings, className: '', } ); expect( console ).toHaveErroredWith( 'Format class names must be a string, or null to handle bare elements.' ); + expect( format ).toBeUndefined(); } ); it( 'should error on invalid className property', () => { - registerFormatType( validName, { + const format = registerFormatType( validName, { ...validSettings, className: 'invalid class name', } ); expect( console ).toHaveErroredWith( 'A class name must begin with a letter, followed by any number of hyphens, letters, or numbers.' ); + expect( format ).toBeUndefined(); } ); it( 'should error on already registered tagName', () => { registerFormatType( validName, validSettings ); - registerFormatType( 'plugin/second', validSettings ); + const duplicateTagNameFormat = registerFormatType( 'plugin/second', validSettings ); expect( console ).toHaveErroredWith( 'Format "plugin/test" is already registered to handle bare tag name "test".' ); + expect( duplicateTagNameFormat ).toBeUndefined(); } ); it( 'should error on already registered className', () => { @@ -95,18 +167,47 @@ describe( 'registerFormatType', () => { ...validSettings, className: 'test', } ); - registerFormatType( 'plugin/second', { + const duplicateClassNameFormat = registerFormatType( 'plugin/second', { ...validSettings, className: 'test', } ); expect( console ).toHaveErroredWith( 'Format "plugin/test" is already registered to handle class name "test".' ); + expect( duplicateClassNameFormat ).toBeUndefined(); + } ); + + it( 'should reject formats without title', () => { + const settings = { ...validSettings }; + delete settings.title; + const format = registerFormatType( validName, settings ); + expect( console ).toHaveErroredWith( `The format "${ validName }" must have a title.` ); + expect( format ).toBeUndefined(); } ); it( 'should error on empty title property', () => { - registerFormatType( validName, { + const format = registerFormatType( validName, { ...validSettings, title: '', } ); expect( console ).toHaveErroredWith( 'The format "plugin/test" must have a title.' ); + expect( format ).toBeUndefined(); + } ); + + it( 'should reject titles which are not strings', () => { + const format = registerFormatType( validName, { + ...validSettings, + title: 1337, + } ); + expect( console ).toHaveErroredWith( 'Format titles must be strings.' ); + expect( format ).toBeUndefined(); + } ); + + it( 'should store a copy of the format type', () => { + const formatType = { ...validSettings }; + registerFormatType( validName, formatType ); + formatType.mutated = true; + expect( getFormatType( validName ) ).toEqual( { + name: validName, + ...validSettings, + } ); } ); } ); diff --git a/packages/rich-text/src/test/toggle-format.js b/packages/rich-text/src/test/toggle-format.js new file mode 100644 index 00000000000000..4a890a43bfae58 --- /dev/null +++ b/packages/rich-text/src/test/toggle-format.js @@ -0,0 +1,56 @@ +/** + * External dependencies + */ +import deepFreeze from 'deep-freeze'; + +/** + * Internal dependencies + */ + +import { toggleFormat } from '../toggle-format'; +import { getSparseArrayLength } from './helpers'; + +describe( 'toggleFormat', () => { + const strong = { type: 'strong' }; + const em = { type: 'em' }; + + it( 'should remove format if it exists at start of selection', () => { + const record = { + formats: [ , , , [ strong ], [ em, strong ], [ em ], [ em ], , , , , , , ], + text: 'one two three', + start: 3, + end: 6, + }; + const expected = { + formats: [ , , , , [ em ], [ em ], [ em ], , , , , , , ], + text: 'one two three', + start: 3, + end: 6, + }; + const result = toggleFormat( deepFreeze( record ), strong ); + + expect( result ).toEqual( expected ); + expect( result ).not.toBe( record ); + expect( getSparseArrayLength( result.formats ) ).toBe( 3 ); + } ); + + it( 'should apply format if it doesn\'t exist at start of selection', () => { + const record = { + formats: [ , , , , [ em, strong ], [ em ], [ em ], , , , , , , ], + text: 'one two three', + start: 3, + end: 6, + }; + const expected = { + formats: [ , , , [ strong ], [ em, strong ], [ em, strong ], [ em ], , , , , , , ], + text: 'one two three', + start: 3, + end: 6, + }; + const result = toggleFormat( deepFreeze( record ), strong ); + + expect( result ).toEqual( expected ); + expect( result ).not.toBe( record ); + expect( getSparseArrayLength( result.formats ) ).toBe( 4 ); + } ); +} ); diff --git a/packages/rich-text/src/test/unregister-format-type.js b/packages/rich-text/src/test/unregister-format-type.js new file mode 100644 index 00000000000000..82774f5395d9d7 --- /dev/null +++ b/packages/rich-text/src/test/unregister-format-type.js @@ -0,0 +1,53 @@ +/** + * External dependencies + */ +import { noop } from 'lodash'; + +/** + * Internal dependencies + */ +import { unregisterFormatType } from '../unregister-format-type'; +import { registerFormatType } from '../register-format-type'; +import { getFormatTypes } from '../get-format-types'; +import { getFormatType } from '../get-format-type'; + +describe( 'unregisterFormatType', () => { + const defaultFormatSettings = { + edit: noop, + title: 'format title', + tagName: 'test', + className: null, + }; + + beforeAll( () => { + // Initialize the rich-text store. + require( '../store' ); + } ); + + afterEach( () => { + getFormatTypes().forEach( ( format ) => { + unregisterFormatType( format.name ); + } ); + } ); + + it( 'should fail if the format is not registered', () => { + const oldFormat = unregisterFormatType( 'core/test-format' ); + expect( console ).toHaveErroredWith( 'Format core/test-format is not registered.' ); + expect( oldFormat ).toBeUndefined(); + } ); + + it( 'should unregister existing formats', () => { + registerFormatType( 'core/test-format', defaultFormatSettings ); + expect( getFormatType( 'core/test-format' ) ).toEqual( { + name: 'core/test-format', + ...defaultFormatSettings, + } ); + const oldFormat = unregisterFormatType( 'core/test-format' ); + expect( console ).not.toHaveErrored(); + expect( oldFormat ).toEqual( { + name: 'core/test-format', + ...defaultFormatSettings, + } ); + expect( getFormatTypes() ).toEqual( [] ); + } ); +} );