kopia lustrzana https://github.com/wagtail/wagtail
Add reload() method to ActionController
rodzic
0cf68697c0
commit
1c2616623d
client/src/controllers
|
@ -22,6 +22,7 @@ describe('ActionController', () => {
|
|||
{
|
||||
...Object.getOwnPropertyDescriptors(oldWindowLocation),
|
||||
assign: { configurable: true, value: jest.fn() },
|
||||
reload: { configurable: true, value: jest.fn() },
|
||||
},
|
||||
);
|
||||
});
|
||||
|
@ -112,10 +113,7 @@ describe('ActionController', () => {
|
|||
|
||||
it('should call click method when button is clicked via Stimulus action', () => {
|
||||
const btn = document.getElementById('button');
|
||||
const clickMock = jest.fn();
|
||||
HTMLButtonElement.prototype.click = clickMock;
|
||||
|
||||
btn.addEventListener('some-event', btn.click());
|
||||
const clickMock = jest.spyOn(HTMLButtonElement.prototype, 'click');
|
||||
|
||||
const event = new CustomEvent('some-event');
|
||||
btn.dispatchEvent(event);
|
||||
|
@ -124,6 +122,24 @@ describe('ActionController', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('reload method', () => {
|
||||
beforeEach(async () => {
|
||||
await setup(`
|
||||
<button
|
||||
id="button"
|
||||
data-controller="w-action"
|
||||
data-action="click->w-action#reload"
|
||||
>
|
||||
Reload
|
||||
</button>`);
|
||||
});
|
||||
|
||||
it('should reload the page', () => {
|
||||
document.getElementById('button').click();
|
||||
expect(window.location.reload).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('redirect method', () => {
|
||||
beforeEach(async () => {
|
||||
await setup(`
|
||||
|
|
|
@ -119,6 +119,13 @@ export class ActionController extends Controller<
|
|||
navigator.sendBeacon(this.urlValue, new FormData(this.createFormElement()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reload the browser.
|
||||
*/
|
||||
reload() {
|
||||
window.location.reload();
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger a redirect based on the custom event's detail, the Stimulus param
|
||||
* or finally check the controlled element for a value to use.
|
||||
|
|
Ładowanie…
Reference in New Issue