kopia lustrzana https://github.com/wagtail/wagtail
Use has-edits-value to test w-action#forceReload with w-unsaved
rodzic
2a47ad1da2
commit
28006a13c3
client/src/controllers
|
@ -168,7 +168,6 @@ describe('ActionController', () => {
|
|||
<form
|
||||
data-controller="w-unsaved"
|
||||
data-action="beforeunload@window->w-unsaved#confirm"
|
||||
data-w-unsaved-force-value="true"
|
||||
data-w-unsaved-confirmation-value="You have unsaved changes!"
|
||||
>
|
||||
</form>
|
||||
|
@ -181,6 +180,13 @@ describe('ActionController', () => {
|
|||
</button>
|
||||
`;
|
||||
await Promise.resolve();
|
||||
|
||||
// Simulate having unsaved changes by setting has-edits-value to true.
|
||||
// We can't set this on init because the value is set to false on connect.
|
||||
document
|
||||
.querySelector('form')
|
||||
.setAttribute('data-w-unsaved-has-edits-value', 'true');
|
||||
await Promise.resolve();
|
||||
const beforeUnloadHandler = jest.fn();
|
||||
window.addEventListener('beforeunload', beforeUnloadHandler);
|
||||
|
||||
|
@ -202,7 +208,6 @@ describe('ActionController', () => {
|
|||
<form
|
||||
data-controller="w-unsaved"
|
||||
data-action="beforeunload@window->w-unsaved#confirm"
|
||||
data-w-unsaved-force-value="true"
|
||||
data-w-unsaved-confirmation-value="You have unsaved changes!"
|
||||
>
|
||||
</form>
|
||||
|
@ -213,9 +218,16 @@ describe('ActionController', () => {
|
|||
>
|
||||
Force reload
|
||||
</button>`);
|
||||
|
||||
// Simulate having unsaved changes by setting has-edits-value to true.
|
||||
// We can't set this on init because the value is set to false on connect.
|
||||
document
|
||||
.querySelector('form')
|
||||
.setAttribute('data-w-unsaved-has-edits-value', 'true');
|
||||
await Promise.resolve();
|
||||
});
|
||||
|
||||
it('should reload the page without preventing the beforeunload event', () => {
|
||||
it('should reload the page without showing the browser confirmation dialog', () => {
|
||||
const confirmHandler = jest.fn();
|
||||
const beforeUnloadHandler = jest.fn();
|
||||
document.addEventListener('w-unsaved:confirm', confirmHandler);
|
||||
|
|
Ładowanie…
Reference in New Issue