-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Update entity saved states to be selected by default and partitioned by type. #21159
Merged
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
e327d5e
filter ignoredForSave out of dirtyEntityRecords
Addison-Stavlo 81010ad
rename unsavedEntityRecords, too confusing and non-representative
Addison-Stavlo 548a3d1
removed temporary commenting
Addison-Stavlo 55e1330
partitioned entities by type
Addison-Stavlo 085025a
renaming
Addison-Stavlo 8df4aae
updated h# for entity type
Addison-Stavlo e555fe0
updated title to show Untitled if not present
Addison-Stavlo b615acd
changed prop names for interior component
Addison-Stavlo 461a008
removed ignoredForSave prop
Addison-Stavlo 0bafed2
started e2e test
Addison-Stavlo e79de94
inserted new template
Addison-Stavlo e397ccb
added empty string default for slug/theme name
Addison-Stavlo 87889a5
tests for button dot state added
Addison-Stavlo 9dceb5d
refactored test names/describes
Addison-Stavlo 166ccc4
fixed failing test after openning button
Addison-Stavlo 18771c6
started published checks
Addison-Stavlo dd35a6f
refactored reusable assertions
Addison-Stavlo f60e1fd
fixed last post editor test
Addison-Stavlo 0d89553
fixed useCallback warning
Addison-Stavlo 012702d
updated save button classname
Addison-Stavlo 380c292
renamed test file
Addison-Stavlo c4c7f7d
refactored selectors etc.
Addison-Stavlo 6cfd317
fixed undefined key in site editor
Addison-Stavlo 18447e2
removed comment
Addison-Stavlo fd4da45
moved test file
Addison-Stavlo 7c52693
added title to dirty entity selector
Addison-Stavlo 20a4606
added getTitle to site entity
Addison-Stavlo 9bac85a
Skip site editor tests
youknowriad 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
178 changes: 178 additions & 0 deletions
178
packages/e2e-tests/specs/experiments/multi-entity-saving.test.js
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,178 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { | ||
createNewPost, | ||
insertBlock, | ||
disablePrePublishChecks, | ||
publishPostWithPrePublishChecksDisabled, | ||
visitAdminPage, | ||
} from '@wordpress/e2e-test-utils'; | ||
import { addQueryArgs } from '@wordpress/url'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { | ||
enableExperimentalFeatures, | ||
disableExperimentalFeatures, | ||
} from '../../experimental-features'; | ||
|
||
describe( 'Multi-entity save flow', () => { | ||
// Selectors. | ||
const checkboxSelector = '.components-checkbox-control__checked'; | ||
const templatePartSelector = '*[data-type="core/template-part"]'; | ||
const saveButtonSelector = '.editor-post-publish-button__button'; | ||
const multisaveSelector = | ||
'.editor-post-publish-button__button.has-changes-dot'; | ||
const entitiesSaveSelector = '.editor-entities-saved-states__save-button'; | ||
const saveSiteSelector = '.edit-site-save-button__button'; | ||
|
||
// Setup & Teardown. | ||
const requiredExperiments = [ | ||
'#gutenberg-full-site-editing', | ||
'#gutenberg-full-site-editing-demo', | ||
]; | ||
beforeAll( async () => { | ||
await enableExperimentalFeatures( requiredExperiments ); | ||
} ); | ||
afterAll( async () => { | ||
await disableExperimentalFeatures( requiredExperiments ); | ||
} ); | ||
|
||
describe( 'Post Editor', () => { | ||
const assertMultiSaveEnabled = async () => { | ||
const multiSaveButton = await page.waitForSelector( | ||
multisaveSelector | ||
); | ||
expect( multiSaveButton ).not.toBeNull(); | ||
}; | ||
|
||
const assertMultiSaveDisabled = async () => { | ||
const multiSaveButton = await page.$( multisaveSelector ); | ||
expect( multiSaveButton ).toBeNull(); | ||
}; | ||
|
||
describe( 'Pre-Publish state', () => { | ||
it( 'Should not trigger multi-entity save button with only post edited', async () => { | ||
await createNewPost(); | ||
await disablePrePublishChecks(); | ||
// Edit the page some. | ||
await page.click( '.editor-post-title' ); | ||
await page.keyboard.type( 'Test Post...' ); | ||
await page.keyboard.press( 'Enter' ); | ||
|
||
await assertMultiSaveDisabled(); | ||
} ); | ||
|
||
it( 'Should trigger multi-entity save button once template part edited', async () => { | ||
// Create new template part. | ||
await insertBlock( 'Template Part' ); | ||
await page.keyboard.type( 'test-template-part' ); | ||
await page.keyboard.press( 'Tab' ); | ||
await page.keyboard.type( 'test-theme' ); | ||
await page.keyboard.press( 'Tab' ); | ||
await page.keyboard.press( 'Enter' ); | ||
|
||
// Make some changes in new Template Part. | ||
await page.waitForSelector( | ||
`${ templatePartSelector } .block-editor-inner-blocks` | ||
); | ||
await page.click( templatePartSelector ); | ||
await page.keyboard.type( 'some words...' ); | ||
|
||
await assertMultiSaveEnabled(); | ||
} ); | ||
|
||
it( 'Clicking should open modal with boxes checked by default', async () => { | ||
await page.click( saveButtonSelector ); | ||
const checkedBoxes = await page.$$( checkboxSelector ); | ||
expect( checkedBoxes.length ).toBe( 2 ); | ||
} ); | ||
|
||
it( 'Saving should result in items being saved', async () => { | ||
await page.click( entitiesSaveSelector ); | ||
|
||
// Verify post is saved. | ||
const draftSaved = await page.waitForSelector( | ||
'.editor-post-saved-state.is-saved' | ||
); | ||
expect( draftSaved ).not.toBeNull(); | ||
|
||
// Verify template part is saved. | ||
await assertMultiSaveDisabled(); | ||
} ); | ||
} ); | ||
|
||
describe( 'Published state', () => { | ||
it( 'Update button disabled after publish', async () => { | ||
await publishPostWithPrePublishChecksDisabled(); | ||
const disabledSaveButton = await page.$( | ||
`${ saveButtonSelector }[aria-disabled=true]` | ||
); | ||
expect( disabledSaveButton ).not.toBeNull(); | ||
} ); | ||
|
||
it( 'Update button enabled after editing post', async () => { | ||
await page.click( '.editor-post-title' ); | ||
await page.keyboard.type( '...more title!' ); | ||
|
||
// Verify update button is enabled. | ||
const enabledSaveButton = await page.$( | ||
`${ saveButtonSelector }[aria-disabled=false]` | ||
); | ||
expect( enabledSaveButton ).not.toBeNull(); | ||
|
||
// Verify is not for multi-entity saving. | ||
await assertMultiSaveDisabled(); | ||
} ); | ||
|
||
it( 'Multi-save button triggered after editing template part.', async () => { | ||
await page.click( templatePartSelector ); | ||
await page.keyboard.type( '...some more words...' ); | ||
await page.keyboard.press( 'Enter' ); | ||
await assertMultiSaveEnabled(); | ||
} ); | ||
} ); | ||
} ); | ||
|
||
describe.skip( 'Site Editor', () => { | ||
async function assertSaveDisabled() { | ||
const disabledButton = await page.waitForSelector( | ||
`${ saveSiteSelector }[aria-disabled=true]` | ||
); | ||
expect( disabledButton ).not.toBeNull(); | ||
} | ||
const activeButtonSelector = `${ saveSiteSelector }[aria-disabled=false]`; | ||
|
||
it( 'Save button should be disabled by default', async () => { | ||
// Navigate to site editor. | ||
const query = addQueryArgs( '', { | ||
page: 'gutenberg-edit-site', | ||
} ).slice( 1 ); | ||
await visitAdminPage( 'admin.php', query ); | ||
|
||
await assertSaveDisabled(); | ||
} ); | ||
|
||
it( 'Should be enabled after edits', async () => { | ||
await page.click( templatePartSelector ); | ||
await page.keyboard.type( 'some words...' ); | ||
const enabledButton = await page.waitForSelector( | ||
activeButtonSelector | ||
); | ||
expect( enabledButton ).not.toBeNull(); | ||
} ); | ||
|
||
it( 'Clicking button should open modal with boxes checked', async () => { | ||
await page.click( activeButtonSelector ); | ||
const checkedBoxes = await page.$$( checkboxSelector ); | ||
expect( checkedBoxes ).not.toHaveLength( 0 ); | ||
} ); | ||
|
||
it( 'Saving should result in items being saved', async () => { | ||
await page.click( entitiesSaveSelector ); | ||
await assertSaveDisabled(); | ||
} ); | ||
} ); | ||
} ); |
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 |
---|---|---|
|
@@ -53,12 +53,13 @@ export default function SaveButton() { | |
const disabled = ! isDirty || isSaving; | ||
|
||
const [ isOpen, setIsOpen ] = useState( false ); | ||
const open = useCallback( setIsOpen.bind( null, true ), [] ); | ||
const close = useCallback( setIsOpen.bind( null, false ), [] ); | ||
const open = useCallback( () => setIsOpen( true ), [] ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These were also necessary to edit due to reacts warnings breaking e2e tests. Without this change, react would throw a warning when the button was used about useState update functions not supporting the second callback argument. |
||
const close = useCallback( () => setIsOpen( false ), [] ); | ||
return ( | ||
<> | ||
<Button | ||
isPrimary | ||
className="edit-site-save-button__button" | ||
aria-disabled={ disabled } | ||
disabled={ disabled } | ||
isBusy={ isSaving } | ||
|
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
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.
It was necessary to edit these to stop a react warning from breaking the e2e tests. Without initializing as an empty string, react would complain about turning an uncontrolled component into a controlled component once the input was used.