|
| 1 | +import assert from 'node:assert/strict'; |
| 2 | +import { describe, it } from 'node:test'; |
| 3 | + |
| 4 | +import buildStabilityOverview from '../buildStabilityOverview.mjs'; |
| 5 | + |
| 6 | +const getAttribute = (node, name) => |
| 7 | + node.attributes.find(attribute => attribute.name === name)?.value; |
| 8 | + |
| 9 | +describe('buildStabilityOverview', () => { |
| 10 | + it('builds a table with expected headings and rows', () => { |
| 11 | + const entries = [ |
| 12 | + { |
| 13 | + api: 'fs', |
| 14 | + name: 'File system', |
| 15 | + stabilityIndex: 2, |
| 16 | + stabilityDescription: 'Stable', |
| 17 | + }, |
| 18 | + { |
| 19 | + api: 'async_context', |
| 20 | + name: 'Async context', |
| 21 | + stabilityIndex: 1, |
| 22 | + stabilityDescription: 'Experimental', |
| 23 | + }, |
| 24 | + ]; |
| 25 | + |
| 26 | + const result = buildStabilityOverview(entries); |
| 27 | + |
| 28 | + assert.equal(result.tagName, 'table'); |
| 29 | + |
| 30 | + const thead = result.children[0]; |
| 31 | + const tbody = result.children[1]; |
| 32 | + |
| 33 | + assert.equal(thead.tagName, 'thead'); |
| 34 | + assert.equal(tbody.tagName, 'tbody'); |
| 35 | + assert.equal(tbody.children.length, 2); |
| 36 | + |
| 37 | + const headerCells = thead.children[0].children; |
| 38 | + assert.equal(headerCells[0].children[0].value, 'API'); |
| 39 | + assert.equal(headerCells[1].children[0].value, 'Stability'); |
| 40 | + }); |
| 41 | + |
| 42 | + it('creates links and BadgeGroup cells with mapped props', () => { |
| 43 | + const [row] = buildStabilityOverview([ |
| 44 | + { |
| 45 | + api: 'fs', |
| 46 | + name: 'File system', |
| 47 | + stabilityIndex: 0, |
| 48 | + stabilityDescription: 'Deprecated: use fs/promises', |
| 49 | + }, |
| 50 | + ]).children[1].children; |
| 51 | + |
| 52 | + const link = row.children[0].children[0]; |
| 53 | + const badgeGroup = row.children[1].children[0]; |
| 54 | + |
| 55 | + assert.equal(link.tagName, 'a'); |
| 56 | + assert.equal(link.properties.href, 'fs.html'); |
| 57 | + assert.equal(link.children[0].value, 'File system'); |
| 58 | + |
| 59 | + assert.equal(badgeGroup.name, 'BadgeGroup'); |
| 60 | + assert.equal(getAttribute(badgeGroup, 'as'), 'span'); |
| 61 | + assert.equal(getAttribute(badgeGroup, 'size'), 'small'); |
| 62 | + assert.equal(getAttribute(badgeGroup, 'kind'), 'error'); |
| 63 | + assert.equal(getAttribute(badgeGroup, 'badgeText'), '0'); |
| 64 | + assert.equal(badgeGroup.children[0].value, 'Deprecated: use fs/promises'); |
| 65 | + }); |
| 66 | + |
| 67 | + it('falls back to success kind for unknown stability index', () => { |
| 68 | + const [row] = buildStabilityOverview([ |
| 69 | + { |
| 70 | + api: 'custom', |
| 71 | + name: 'Custom API', |
| 72 | + stabilityIndex: 9, |
| 73 | + stabilityDescription: 'Unknown status', |
| 74 | + }, |
| 75 | + ]).children[1].children; |
| 76 | + |
| 77 | + const badgeGroup = row.children[1].children[0]; |
| 78 | + |
| 79 | + assert.equal(getAttribute(badgeGroup, 'kind'), 'success'); |
| 80 | + assert.equal(getAttribute(badgeGroup, 'badgeText'), '9'); |
| 81 | + }); |
| 82 | +}); |
0 commit comments