generated from adobe/aem-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #85 from ifahrentholz/84-transfer-helper
#64 Transfer cleanup block helper from DVAG POC
- Loading branch information
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { cleanUpBlock } from './cleanUpBlock'; | ||
|
||
describe('cleanUpBlock', () => { | ||
let block: HTMLDivElement; | ||
|
||
beforeEach(() => { | ||
block = document.createElement('div'); | ||
block.innerHTML = '<p>Test content</p>'; | ||
block.style.display = 'block'; | ||
|
||
document.body.appendChild(block); | ||
}); | ||
|
||
afterEach(() => { | ||
document.body.removeChild(block); | ||
}); | ||
|
||
it('should remove inner HTML content', () => { | ||
cleanUpBlock(block); | ||
|
||
expect(block.innerHTML).toBe(''); | ||
}); | ||
|
||
it('should reset display property', () => { | ||
cleanUpBlock(block); | ||
|
||
expect(block.style.display).toBe(''); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* Cleans up a block by removing its inner HTML content and resetting its display property. | ||
* @param {HTMLElement} block - The HTML element representing the block to clean up. | ||
* @returns {void} | ||
* | ||
* @remarks | ||
* This function is useful for resetting a block's state or content. | ||
*/ | ||
export const cleanUpBlock = (block: HTMLElement): void => { | ||
while (block.firstChild) { | ||
block.removeChild(block.firstChild); | ||
} | ||
|
||
block.style.removeProperty('display'); | ||
}; |