-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/WordPress/gutenberg into …
…rnmobile/fix-merge-content-not-refreshed-UI * 'master' of https://github.com/WordPress/gutenberg: Add missing tests for Format API code (#11562) chore: Improve undo/redo no-op (#11428) Fix: Contrast checker: Consider fontSize large when size >= 24px instead of >= 18px (#9268)
- Loading branch information
Showing
15 changed files
with
450 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ); | ||
} ); | ||
} ); | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ); | ||
} ); | ||
} ); | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
} ); | ||
} ); | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
}, | ||
] ); | ||
} ); | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ); | ||
} ); | ||
} ); |
Oops, something went wrong.