techtools
Головна / proto / flow-old / test / block-help.test.ts

block-help.test.ts

TypeScript · 40 рядків

1import test from 'node:test'
2import assert from 'node:assert/strict'
3import { blockHelp } from '../src/blockHelp.js'
4import { renderMarkdown } from '../src/markdown.js'
5
6test('Mapping help documents every supported mapping scope and operation', () => {
7  const help = blockHelp('MAPPING')
8
9  assert.equal(help.title, 'Mapping block')
10  for (const term of ['$copy', '$data', 'data.*', 'task.*', 'event.*', '$map', 'item.*']) {
11    assert.ok(help.markdown.includes(term), `missing ${term}`)
12  }
13  assert.match(help.markdown, /Common mistakes/)
14  assert.match(help.markdown, /constants are not currently supported/)
15  assert.equal(blockHelp('API_REQUEST'), null)
16})
17
18test('Markdown renderer formats tutorials and escapes raw HTML', () => {
19  const html = renderMarkdown('# Title\n\n- **Safe** `code`\n\n```json\n{"x":"<script>"}\n```')
20
21  assert.match(html, /<h1>Title<\/h1>/)
22  assert.match(html, /<ul>/)
23  assert.match(html, /<strong>Safe<\/strong>/)
24  assert.match(html, /<code>code<\/code>/)
25  assert.match(html, /language-json/)
26  assert.match(html, /&lt;script&gt;/)
27  assert.doesNotMatch(html, /<script>/)
28})
29
30test('Action and Condition help document the expression language (G2, G3)', () => {
31  for (const type of ['ACTION', 'CONDITION']) {
32    const help = blockHelp(type)
33    for (const term of ['len(x)', 'coalesce', 'now()', 'ts(date)', '`=`', 'data.task']) {
34      assert.ok(help.markdown.includes(term), `${type}: missing ${term}`)
35    }
36  }
37  assert.match(blockHelp('ACTION').markdown, /"=data.expected - data.accepted"/)
38  assert.match(blockHelp('CONDITION').markdown, /Conditions on connectors/)
39})
40