Skip to content

Commit

Permalink
Merge pull request #85 from ifahrentholz/84-transfer-helper
Browse files Browse the repository at this point in the history
#64 Transfer cleanup block helper from DVAG POC
  • Loading branch information
LoomingEcho authored May 23, 2024
2 parents f27f63c + 955089c commit 023d6c9
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/utils/cleanUpBlock.spec.ts
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('');
});
});
15 changes: 15 additions & 0 deletions src/utils/cleanUpBlock.ts
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');
};

0 comments on commit 023d6c9

Please sign in to comment.