File size: 1,216 Bytes
7596726
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const assert = require('node:assert/strict');
const test = require('node:test');

const { withBrowserEnv } = require('./support/load-browser-modules');

// Frontend tests double as documentation for the intended UI contract.
test('analysis modal body uses DOM content and preserves text escaping', async () => {
  await withBrowserEnv({}, async ({ document, importModule }) => {
    const { buildAnalysisBody } = await importModule('static/app/schedule/analysis-modal.mjs');

    const body = buildAnalysisBody(document, {
      analysis: {
        score: '0hard/0soft',
        constraints: [
          {
            name: '<script>alert(1)</script>',
            score: '0hard/0soft',
            matchCount: 0,
          },
        ],
      },
    }, [
      { name: '<script>alert(1)</script>', type: 'hard' },
    ]);

    const table = body.querySelector('table');
    assert.ok(table, 'expected a rendered table node');
    assert.equal(table.className, 'sf-table');
    assert.equal(body.querySelector('script'), null);
    assert.match(body.textContent, /<script>alert\(1\)<\/script>/);
    assert.match(body.textContent, /ConstraintTypeScoreMatches/);
    assert.match(body.textContent, /hard/);
  });
});