| 1 |
import { addIdAttributeToBlock } from '@launch/lib/blocks'; |
| 2 |
|
| 3 |
describe('addIdAttributeToBlock', () => { |
| 4 |
const blockCode = '<div class="wp-block-group something">Content</div>'; |
| 5 |
|
| 6 |
it('adds id attribute to block with wp-block-group class', () => { |
| 7 |
const result = addIdAttributeToBlock(blockCode, 'test-id'); |
| 8 |
expect(result).toContain('id="test-id"'); |
| 9 |
}); |
| 10 |
|
| 11 |
it('does not break other parts of the HTML', () => { |
| 12 |
const result = addIdAttributeToBlock(blockCode, 'unique-id'); |
| 13 |
expect(result).toContain( |
| 14 |
'<div class="wp-block-group something" id="unique-id">', |
| 15 |
); |
| 16 |
}); |
| 17 |
|
| 18 |
it('does nothing if blockCode doesn’t match the expected pattern', () => { |
| 19 |
const input = '<div class="something-else">Hello</div>'; |
| 20 |
const result = addIdAttributeToBlock(input, 'abc'); |
| 21 |
expect(result).toBe(input); |
| 22 |
}); |
| 23 |
}); |
| 24 |
|