From 1b3e54e267a7485e44d9caaf61eb1400ddf133ca Mon Sep 17 00:00:00 2001 From: Sage Abdullah Date: Thu, 25 Jan 2024 14:01:28 +0000 Subject: [PATCH] Add tests for w-teleport-reset-value --- .../controllers/TeleportController.test.js | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/client/src/controllers/TeleportController.test.js b/client/src/controllers/TeleportController.test.js index 407277912b..0c0700da74 100644 --- a/client/src/controllers/TeleportController.test.js +++ b/client/src/controllers/TeleportController.test.js @@ -116,6 +116,55 @@ describe('TeleportController', () => { ); }); + it('should clear the target container if the reset value is set to true', async () => { + document.body.innerHTML += ` +

I should not be here

+ `; + + 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( + '

I should not be here

', + ); + + application.start(); + + await Promise.resolve(); + + expect(document.getElementById('target-container').innerHTML).toEqual( + '
Some content
', + ); + }); + + it('should not clear the target container if the reset value is unset (false)', async () => { + document.body.innerHTML += ` +

I should still be here

+ `; + + const template = document.querySelector('template'); + template.setAttribute( + 'data-w-teleport-target-value', + '#target-container', + ); + + expect(document.getElementById('target-container').innerHTML).toEqual( + '

I should still be here

', + ); + + application.start(); + + await Promise.resolve(); + + expect(document.getElementById('target-container').innerHTML).toEqual( + '

I should still be here

Some content
', + ); + }); + it('should throw an error if the template content is empty', async () => { const errors = [];