0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-11-25 05:02:57 +01:00

Add tests for w-teleport-reset-value

This commit is contained in:
Sage Abdullah 2024-01-25 14:01:28 +00:00 committed by Thibaud Colas
parent e30c25c3b1
commit 1b3e54e267

View File

@ -116,6 +116,55 @@ describe('TeleportController', () => {
);
});
it('should clear the target container if the reset value is set to true', async () => {
document.body.innerHTML += `
<div id="target-container"><p>I should not be here</p></div>
`;
const template = document.querySelector('template');
template.setAttribute(
'data-w-teleport-target-value',
'#target-container',
);
template.setAttribute('data-w-teleport-reset-value', 'true');
expect(document.getElementById('target-container').innerHTML).toEqual(
'<p>I should not be here</p>',
);
application.start();
await Promise.resolve();
expect(document.getElementById('target-container').innerHTML).toEqual(
'<div id="content">Some content</div>',
);
});
it('should not clear the target container if the reset value is unset (false)', async () => {
document.body.innerHTML += `
<div id="target-container"><p>I should still be here</p></div>
`;
const template = document.querySelector('template');
template.setAttribute(
'data-w-teleport-target-value',
'#target-container',
);
expect(document.getElementById('target-container').innerHTML).toEqual(
'<p>I should still be here</p>',
);
application.start();
await Promise.resolve();
expect(document.getElementById('target-container').innerHTML).toEqual(
'<p>I should still be here</p><div id="content">Some content</div>',
);
});
it('should throw an error if the template content is empty', async () => {
const errors = [];