-
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
Add missing tests for Format API code #11562
Conversation
Thanks for the tests @Pixelrobin! |
|
||
describe( 'getFormatType', () => { | ||
// Initialize format store. | ||
require( '../store' ); |
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.
Shouldn't this be wrapped in a beforeAll
?
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.
Oh, my bad. I think I did it like this all the way though. I'll fix it.
const obj = { type: 'obj' }; | ||
const em = { type: 'em' }; | ||
|
||
const OBJECT_REPLACEMENT_CHARACTER = '\ufffc'; |
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.
There's a special characters file with these constants that you can import.
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.
Oh yeah, I noticed that. I was working off an older version that didn't have that implemented yet. I assume updating the branch would require me to take care of the merge conflict myself?
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.
After a rebase you could use the constants. :)
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.
I usually do the following on my branch:
git fetch
git rebase origin/master
you fix conflicts and:
git add .
git rebase --continue
}; | ||
const expected = { | ||
formats: [ , , [ { ...obj, object: true } ], [ em ], , , , , , , ], | ||
text: 'on' + OBJECT_REPLACEMENT_CHARACTER + 'o three', |
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.
Minor: you could use template literals here:
`on${ OBJECT_REPLACEMENT_CHARACTER }o three`
It reads a bit easier to me.
Looks good! Needs a rebase. There were some tests added for |
|
||
describe( 'getFormatTypes', () => { | ||
// Initialize format store. | ||
require( '../store' ); |
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.
The same thing with beforeAll
.
} ); | ||
|
||
it( 'should return all registered formats', () => { | ||
const formatType1 = { edit: noop, title: 'format title' }; |
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.
I personally like more descriptive names for variables.
How about:
testFormat
testFormatWithSettings
to align with the names used as first param inregisterFormatType
?
const obj = { type: 'obj' }; | ||
const em = { type: 'em' }; | ||
|
||
const OBJECT_REPLACEMENT_CHARACTER = '\ufffc'; |
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.
I usually do the following on my branch:
git fetch
git rebase origin/master
you fix conflicts and:
git add .
git rebase --continue
import { getFormatTypes, getFormatType } from '../selectors'; | ||
|
||
describe( 'selectors', () => { | ||
const defaultState = { |
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.
It's a good practice to wrap state with deepFreeze
to ensure that selectors never mutate state.
const defaultFormatSettings = { edit: noop, title: 'format title' }; | ||
|
||
// Initialize format store. | ||
require( '../store' ); |
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.
beforeAll
again :)
I also noticed that comment isn't 100% accurate. It is rich text store.
In general, we need to come up with a nicer way of using stores with tests.
const defaultFormatSettings = { edit: noop, title: 'format title' }; | ||
|
||
// Initialize format store. | ||
require( '../store' ); |
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.
beforeAll
:)
|
||
it( 'should unregister existing formats', () => { | ||
registerFormatType( 'core/test-format', defaultFormatSettings ); | ||
expect( getFormatTypes() ).toEqual( [ |
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.
It might read better when getFormatType
is used here as core/test-format'
is the only thing we care about here..
You learn really fast, awesome work! :)
Yes, this is the only tricky part. I left some hint how I usually do it. Just make sure we don't have duplicated tests in that file. A few of tests you added are missing in the test suite added by @iseulde yesterday. |
Moved to 4.4 as it's not a blocker for 4.3. Let's merge it if it's ready though. |
2973ece
to
fd7a191
Compare
Ok, I think I applied all the feedback, thanks!
Rebasing added the |
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.
Awesome work, thanks for addressing all feedback 💯
@Pixelrobin congrats on your first code contribution! 🎉 |
title: 'format title', | ||
keywords: [ 'one', 'two', 'three' ], | ||
formatTestSetting: 'settingTestValue', | ||
tagName: 'test', |
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.
…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)
Description
Closes #11110.
Addressed #11110 by adding various tests. I used tests from other parts of the code as a reference. I am new to Jest and Gutenberg development though.
Types of changes
Adds tests to several functions in the Format API, which should hopefully not break anything?
Checklist: