Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 13776: Format is already registered to handle class name #15072

Merged
merged 2 commits into from
Apr 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/rich-text/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ export function getFormatType( state, name ) {
* @return {?Object} Format type.
*/
export function getFormatTypeForBareElement( state, bareElementTagName ) {
return find( getFormatTypes( state ), ( { tagName } ) => {
return bareElementTagName === tagName;
return find( getFormatTypes( state ), ( { className, tagName } ) => {
return className === null && bareElementTagName === tagName;
} );
}

Expand Down
54 changes: 46 additions & 8 deletions packages/rich-text/src/store/test/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,71 @@ import deepFreeze from 'deep-freeze';
/**
* Internal dependencies
*/
import { getFormatTypes, getFormatType } from '../selectors';
import {
getFormatTypes,
getFormatType,
getFormatTypeForBareElement,
getFormatTypeForClassName,
} from '../selectors';

describe( 'selectors', () => {
const formatType = {
name: 'core/test-format',
className: null,
tagName: 'format',
};
const formatTypeClassName = {
name: 'core/test-format-class-name',
className: 'class-name',
tagName: 'strong',
};
const formatTypeBareTag = {
name: 'core/test-format-bare-tag',
className: null,
tagName: 'strong',
};
const defaultState = deepFreeze( {
formatTypes: {
'core/test-format': { name: 'core/test-format' },
'core/test-format-2': { name: 'core/test-format-2' },
'core/test-format': formatType,
'core/test-format-class-name': formatTypeClassName,
ellatrix marked this conversation as resolved.
Show resolved Hide resolved
// Order matters: we need to ensure that
// `core/test-format-class-name` is not considered bare.
'core/test-format-bare-tag': formatTypeBareTag,
},
} );

describe( 'getFormatTypes', () => {
it( 'should get format types', () => {
const expected = [
{ name: 'core/test-format' },
{ name: 'core/test-format-2' },
formatType,
formatTypeClassName,
formatTypeBareTag,
];

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 );
expect( result ).toEqual( formatType );
} );
} );

describe( 'getFormatTypeForBareElement', () => {
it( 'should get a format type', () => {
const result = getFormatTypeForBareElement( defaultState, 'strong' );

expect( result ).toEqual( formatTypeBareTag );
} );
} );

describe( 'getFormatTypeForClassName', () => {
it( 'should get a format type', () => {
const result = getFormatTypeForClassName( defaultState, 'class-name' );

expect( result ).toEqual( formatTypeClassName );
} );
} );
} );