-
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
Local autosave: Clear after successful save #18051
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -186,6 +186,49 @@ describe( 'autosave', () => { | |
toggleOfflineMode( false ); | ||
} ); | ||
|
||
it( 'should clear local autosave after successful save', async () => { | ||
await clickBlockAppender(); | ||
await page.keyboard.type( 'before save' ); | ||
await saveDraft(); | ||
|
||
await page.keyboard.type( 'after save' ); | ||
|
||
// Trigger local autosave | ||
expect( await page.evaluate( () => window.sessionStorage.length ) ).toBe( 0 ); | ||
await page.evaluate( () => window.wp.data.dispatch( 'core/editor' ).__experimentalLocalAutosave() ); | ||
expect( await page.evaluate( () => window.sessionStorage.length ) ).toBe( 1 ); | ||
|
||
// Save and wait for "Saved" to confirm save complete. | ||
await Promise.all( [ | ||
page.waitForSelector( '.editor-post-saved-state.is-saved' ), | ||
pressKeyWithModifier( 'primary', 'S' ), | ||
] ); | ||
|
||
expect( await page.evaluate( () => window.sessionStorage.length ) ).toBe( 1 ); | ||
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. Shouldn't the length be 0 in this case? The test description is:
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. Oh wow, how did that happen? 😰 I'll look. In the meantime, in actual usage the issue seemed to be fixed. |
||
} ); | ||
|
||
it( 'shouldn\'t clear local autosave if save fails', async () => { | ||
await clickBlockAppender(); | ||
await page.keyboard.type( 'before save' ); | ||
await saveDraft(); | ||
|
||
await page.keyboard.type( 'after save' ); | ||
await page.evaluate( () => window.wp.data.dispatch( 'core/editor' ).__experimentalLocalAutosave() ); | ||
expect( await page.evaluate( () => window.sessionStorage.length ) ).toBe( 1 ); | ||
|
||
toggleOfflineMode( true ); | ||
|
||
// Save and wait for "Saved" to confirm save complete. | ||
await Promise.all( [ | ||
page.waitForSelector( '.editor-post-saved-state.is-saved' ), | ||
pressKeyWithModifier( 'primary', 'S' ), | ||
] ); | ||
|
||
expect( await page.evaluate( () => window.sessionStorage.length ) ).toBe( 1 ); | ||
|
||
toggleOfflineMode( false ); | ||
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. In case the previous expectation fails, the offline mode will get propagated to other tests giving false negatives there. It's safer to clean up with 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. Yeah, great point. |
||
} ); | ||
|
||
it( 'shouldn\'t conflict with server-side autosave', async () => { | ||
await clickBlockAppender(); | ||
await page.keyboard.type( 'before publish' ); | ||
|
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've seen it in a few tests already. It might be a good idea to open a follow-up and put it into a shared utility helper.