-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Add missing tests for Format API code #11562
Merged
gziolo
merged 4 commits into
WordPress:master
from
Pixelrobin:add/missing-format-api-tests
Nov 8, 2018
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@iseulde - should we add validation for
tagName
property? Values like
testand
test 2` made me think about it.