|
| 1 | +import { describe, it, expect } from 'vitest'; |
| 2 | +import { |
| 3 | + wrapRichText, |
| 4 | + wrapTestCaseSteps, |
| 5 | +} from '../../src/tools/testmanagement-utils/rich-text'; |
| 6 | + |
| 7 | +describe('wrapRichText', () => { |
| 8 | + it('escapes and wraps bare text containing >', () => { |
| 9 | + expect(wrapRichText('Navigate to Settings > Users')).toBe( |
| 10 | + '<p>Navigate to Settings > Users</p>', |
| 11 | + ); |
| 12 | + }); |
| 13 | + |
| 14 | + it('escapes and wraps bare text containing <', () => { |
| 15 | + expect(wrapRichText('if a < b then pass')).toBe( |
| 16 | + '<p>if a < b then pass</p>', |
| 17 | + ); |
| 18 | + }); |
| 19 | + |
| 20 | + it('escapes and wraps bare text containing &', () => { |
| 21 | + expect(wrapRichText('Q&A section loads')).toBe( |
| 22 | + '<p>Q&A section loads</p>', |
| 23 | + ); |
| 24 | + }); |
| 25 | + |
| 26 | + it('preserves tag-like tokens that TM would otherwise strip', () => { |
| 27 | + expect(wrapRichText('Press <Enter> to submit the form')).toBe( |
| 28 | + '<p>Press <Enter> to submit the form</p>', |
| 29 | + ); |
| 30 | + expect(wrapRichText('Use List<String> where A > B & C')).toBe( |
| 31 | + '<p>Use List<String> where A > B & C</p>', |
| 32 | + ); |
| 33 | + // Leading tag-like token that is NOT a TM-allowed tag is literal text too. |
| 34 | + expect(wrapRichText('<Enter> key submits the form')).toBe( |
| 35 | + '<p><Enter> key submits the form</p>', |
| 36 | + ); |
| 37 | + expect(wrapRichText('<h1>not an allowed TM tag</h1>')).toBe( |
| 38 | + '<p><h1>not an allowed TM tag</h1></p>', |
| 39 | + ); |
| 40 | + }); |
| 41 | + |
| 42 | + it('leaves text without <, > or & untouched', () => { |
| 43 | + expect(wrapRichText('Click "Save" then \'Confirm\'')).toBe( |
| 44 | + 'Click "Save" then \'Confirm\'', |
| 45 | + ); |
| 46 | + }); |
| 47 | + |
| 48 | + it('leaves content starting with a TM-allowed tag untouched', () => { |
| 49 | + expect(wrapRichText('<p>Settings > Users</p>')).toBe( |
| 50 | + '<p>Settings > Users</p>', |
| 51 | + ); |
| 52 | + expect(wrapRichText(' <ul><li>A & B</li></ul>')).toBe( |
| 53 | + ' <ul><li>A & B</li></ul>', |
| 54 | + ); |
| 55 | + expect(wrapRichText('<br/>')).toBe('<br/>'); |
| 56 | + }); |
| 57 | + |
| 58 | + it('treats a leading < that is not a tag as literal text', () => { |
| 59 | + expect(wrapRichText('< 5 items are shown')).toBe( |
| 60 | + '<p>< 5 items are shown</p>', |
| 61 | + ); |
| 62 | + }); |
| 63 | + |
| 64 | + it('handles any characters, not just fixed strings', () => { |
| 65 | + expect(wrapRichText('émojis 🎉 and ünïcode ≥ 5 stay bare')).toBe( |
| 66 | + 'émojis 🎉 and ünïcode ≥ 5 stay bare', |
| 67 | + ); |
| 68 | + expect(wrapRichText('unicode plus html char: 温度 > 30°C')).toBe( |
| 69 | + '<p>unicode plus html char: 温度 > 30°C</p>', |
| 70 | + ); |
| 71 | + expect(wrapRichText('line1 a > b\nline2 c < d')).toBe( |
| 72 | + '<p>line1 a > b\nline2 c < d</p>', |
| 73 | + ); |
| 74 | + expect(wrapRichText('a>=b && c<=d & "e"')).toBe( |
| 75 | + '<p>a>=b && c<=d & "e"</p>', |
| 76 | + ); |
| 77 | + }); |
| 78 | +}); |
| 79 | + |
| 80 | +describe('wrapTestCaseSteps', () => { |
| 81 | + it('wraps step and result independently and preserves other keys', () => { |
| 82 | + expect( |
| 83 | + wrapTestCaseSteps([ |
| 84 | + { step: 'Go to A > B', result: 'B page loads' }, |
| 85 | + { step: 'Click Save', result: 'Count > 0' }, |
| 86 | + ]), |
| 87 | + ).toEqual([ |
| 88 | + { step: '<p>Go to A > B</p>', result: 'B page loads' }, |
| 89 | + { step: 'Click Save', result: '<p>Count > 0</p>' }, |
| 90 | + ]); |
| 91 | + }); |
| 92 | + |
| 93 | + it('returns an empty array unchanged', () => { |
| 94 | + expect(wrapTestCaseSteps([])).toEqual([]); |
| 95 | + }); |
| 96 | +}); |
0 commit comments