Files
TREK/client/src/utils/flowText.test.ts
T
Maurice 796f39fe1f fix(rtl): write the isolate marks of flowText as escapes, not as raw characters
A raw FSI or PDI in the source reads as nothing and is what Sonar's
bidirectional character rule (S6389) flags. The strings are the same.
2026-11-08 01:40:30 +00:00

35 lines
1.2 KiB
TypeScript

/**
* FE-UTIL-FLOW-001 to FE-UTIL-FLOW-003
*
* "A → B" as one string that reads in the direction of the UI.
*/
import { afterEach, describe, expect, it } from 'vitest';
import { flowText, isRtlDocument } from './flowText';
const FSI = '\u2068';
const PDI = '\u2069';
describe('flowText', () => {
afterEach(() => {
document.documentElement.dir = '';
});
it('FE-UTIL-FLOW-001: a left-to-right UI gets the plain arrow between the names', () => {
expect(flowText(['Sam Carter', 'Ada'], false)).toBe('Sam Carter → Ada');
expect(flowText(['Kyoto', 'Osaka', 'Nara'], false)).toBe('Kyoto → Osaka → Nara');
});
it('FE-UTIL-FLOW-002: in Arabic each name is isolated and the arrow points left, from the first to the second', () => {
expect(flowText(['Sam Carter', 'أنت'], true)).toBe(`${FSI}Sam Carter${PDI} ← ${FSI}أنت${PDI}`);
});
it('FE-UTIL-FLOW-003: without an explicit direction it follows the document', () => {
expect(isRtlDocument()).toBe(false);
expect(flowText(['A', 'B'])).toBe('A → B');
document.documentElement.dir = 'rtl';
expect(isRtlDocument()).toBe(true);
expect(flowText(['A', 'B'])).toBe(`${FSI}A${PDI} ← ${FSI}B${PDI}`);
});
});