kopia lustrzana https://github.com/wagtail/wagtail
Update ActionController unit tests to use a setup function
rodzic
953c980976
commit
7b0807d17e
|
@ -5,6 +5,15 @@ describe('ActionController', () => {
|
||||||
let app;
|
let app;
|
||||||
const oldWindowLocation = window.location;
|
const oldWindowLocation = window.location;
|
||||||
|
|
||||||
|
const setup = async (html) => {
|
||||||
|
document.body.innerHTML = `<main>${html}</main>`;
|
||||||
|
|
||||||
|
app = Application.start();
|
||||||
|
app.register('w-action', ActionController);
|
||||||
|
|
||||||
|
await Promise.resolve();
|
||||||
|
};
|
||||||
|
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
delete window.location;
|
delete window.location;
|
||||||
|
|
||||||
|
@ -23,8 +32,8 @@ describe('ActionController', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('post method', () => {
|
describe('post method', () => {
|
||||||
beforeEach(() => {
|
beforeEach(async () => {
|
||||||
document.body.innerHTML = `
|
await setup(`
|
||||||
<button
|
<button
|
||||||
class="button no"
|
class="button no"
|
||||||
data-controller="w-action"
|
data-controller="w-action"
|
||||||
|
@ -32,10 +41,7 @@ describe('ActionController', () => {
|
||||||
data-w-action-url-value="https://www.github.com"
|
data-w-action-url-value="https://www.github.com"
|
||||||
>
|
>
|
||||||
Enable
|
Enable
|
||||||
</button>`;
|
</button>`);
|
||||||
|
|
||||||
app = Application.start();
|
|
||||||
app.register('w-action', ActionController);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('it should allow for a form POST with created data', () => {
|
it('it should allow for a form POST with created data', () => {
|
||||||
|
@ -54,8 +60,8 @@ describe('ActionController', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('click method', () => {
|
describe('click method', () => {
|
||||||
beforeEach(() => {
|
beforeEach(async () => {
|
||||||
document.body.innerHTML = `
|
await setup(`
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
id="button"
|
id="button"
|
||||||
|
@ -63,10 +69,7 @@ describe('ActionController', () => {
|
||||||
data-action="some-event->w-action#click"
|
data-action="some-event->w-action#click"
|
||||||
>
|
>
|
||||||
Button
|
Button
|
||||||
</button>`;
|
</button>`);
|
||||||
|
|
||||||
app = Application.start();
|
|
||||||
app.register('w-action', ActionController);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call click method when button is clicked via Stimulus action', () => {
|
it('should call click method when button is clicked via Stimulus action', () => {
|
||||||
|
@ -84,15 +87,12 @@ describe('ActionController', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('redirect method', () => {
|
describe('redirect method', () => {
|
||||||
beforeEach(() => {
|
beforeEach(async () => {
|
||||||
document.body.innerHTML = `
|
await setup(`
|
||||||
<select name="url" data-controller="w-action" data-action="change->w-action#redirect">
|
<select name="url" data-controller="w-action" data-action="change->w-action#redirect">
|
||||||
<option value="http://localhost/place?option=1">1</option>
|
<option value="http://localhost/place?option=1">1</option>
|
||||||
<option value="http://localhost/place?option=2" selected>2</option>
|
<option value="http://localhost/place?option=2" selected>2</option>
|
||||||
</select>`;
|
</select>`);
|
||||||
|
|
||||||
app = Application.start();
|
|
||||||
app.register('w-action', ActionController);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should have a redirect method that falls back to any element value', () => {
|
it('should have a redirect method that falls back to any element value', () => {
|
||||||
|
|
Ładowanie…
Reference in New Issue