mirror of
https://github.com/Shik3i/KoalaSync.git
synced 2026-08-30 12:29:27 +00:00
fix(extension): harden chat and target tab lifecycle
This commit is contained in:
@@ -19,4 +19,25 @@ describe('chat formatting', () => {
|
||||
{ type: 'em', text: 'italic' }
|
||||
]);
|
||||
});
|
||||
|
||||
it('splits up to 5000 Unicode code points into at most ten ordered chat-v1 messages', () => {
|
||||
const split = globalThis.KoalaSyncChatFormat.splitChatText;
|
||||
expect(split('hello world', 500, 10)).toEqual(['hello world']);
|
||||
|
||||
const emojiChunks = split('😀'.repeat(1001), 500, 10);
|
||||
expect(emojiChunks.map(chunk => [...chunk].length)).toEqual([500, 500, 1]);
|
||||
|
||||
const maximumChunks = split('x'.repeat(5000), 500, 10);
|
||||
expect(maximumChunks).toHaveLength(10);
|
||||
expect(maximumChunks.every(chunk => [...chunk].length === 500)).toBe(true);
|
||||
expect(maximumChunks.join('')).toBe('x'.repeat(5000));
|
||||
|
||||
expect(() => split('x'.repeat(5001), 500, 10)).toThrow(RangeError);
|
||||
});
|
||||
|
||||
it('prefers whitespace boundaries without creating more chunks than the limit allows', () => {
|
||||
const split = globalThis.KoalaSyncChatFormat.splitChatText;
|
||||
const chunks = split(`${'a'.repeat(420)} ${'b'.repeat(179)}`, 500, 10);
|
||||
expect(chunks).toEqual(['a'.repeat(420), 'b'.repeat(179)]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user