|
| 1 | +import assert from 'node:assert/strict'; |
| 2 | +import { describe, it } from 'node:test'; |
| 3 | + |
| 4 | +import { transformHeadingNode } from '../buildContent.mjs'; |
| 5 | + |
| 6 | +const heading = { |
| 7 | + type: 'heading', |
| 8 | + depth: 3, |
| 9 | + data: { type: 'misc', slug: 's', text: 'Heading' }, |
| 10 | + children: [{ type: 'text', value: 'Heading' }], |
| 11 | +}; |
| 12 | + |
| 13 | +const makeParent = typeText => ({ |
| 14 | + children: [ |
| 15 | + heading, |
| 16 | + { |
| 17 | + type: 'paragraph', |
| 18 | + children: [{ type: 'text', value: `Type: ${typeText}` }], |
| 19 | + }, |
| 20 | + ], |
| 21 | +}); |
| 22 | + |
| 23 | +describe('transformHeadingNode (deprecation Type -> AlertBox level)', () => { |
| 24 | + it('maps documentation/compilation to info', () => { |
| 25 | + const entry = { api: 'deprecations' }; |
| 26 | + const parent = makeParent('Documentation'); |
| 27 | + const node = parent.children[0]; |
| 28 | + |
| 29 | + transformHeadingNode(entry, {}, node, 0, parent); |
| 30 | + |
| 31 | + const alert = parent.children[1]; |
| 32 | + const levelAttr = alert.attributes.find(a => a.name === 'level'); |
| 33 | + |
| 34 | + assert.equal(alert.name, 'AlertBox'); |
| 35 | + assert.equal(levelAttr.value, 'info'); |
| 36 | + }); |
| 37 | + |
| 38 | + it('maps runtime/application to warning', () => { |
| 39 | + const entry = { api: 'deprecations' }; |
| 40 | + const parent = makeParent('Runtime'); |
| 41 | + const node = parent.children[0]; |
| 42 | + |
| 43 | + transformHeadingNode(entry, {}, node, 0, parent); |
| 44 | + |
| 45 | + const alert = parent.children[1]; |
| 46 | + const levelAttr = alert.attributes.find(a => a.name === 'level'); |
| 47 | + |
| 48 | + assert.equal(alert.name, 'AlertBox'); |
| 49 | + assert.equal(levelAttr.value, 'warning'); |
| 50 | + }); |
| 51 | + |
| 52 | + it('falls back to danger for unknown types', () => { |
| 53 | + const entry = { api: 'deprecations' }; |
| 54 | + const parent = makeParent('SomeOtherThing'); |
| 55 | + const node = parent.children[0]; |
| 56 | + |
| 57 | + transformHeadingNode(entry, {}, node, 0, parent); |
| 58 | + |
| 59 | + const alert = parent.children[1]; |
| 60 | + const levelAttr = alert.attributes.find(a => a.name === 'level'); |
| 61 | + |
| 62 | + assert.equal(alert.name, 'AlertBox'); |
| 63 | + assert.equal(levelAttr.value, 'danger'); |
| 64 | + }); |
| 65 | +}); |
0 commit comments