Files

55 lines
1.6 KiB
JavaScript

// @vitest-environment node
import { describe, expect, it } from 'vitest';
import {
formatShangwutongInlineContent,
shangwutongInlineMediaIndexes,
} from './inlineMedia.js';
describe('Shangwutong inline media', () => {
it('replaces declared attachment markers while preserving order', () => {
const content =
'前![商务通表情](swt-attachment://0)中![商务通表情](swt-attachment://1)后';
const attachments = [
{ dataUrl: '/uploads/emoji-a.gif' },
{ dataUrl: '/uploads/emoji-b.gif' },
];
expect(
formatShangwutongInlineContent(content, attachments, {
swt: { inline_media: [0, 1] },
})
).toBe(
'前![商务通表情](<http://localhost/uploads/emoji-a.gif>)中![商务通表情](<http://localhost/uploads/emoji-b.gif>)后'
);
});
it('appends inline images when translated content omits markers', () => {
expect(
formatShangwutongInlineContent(
'translated',
[{ dataUrl: '/emoji.gif' }],
{
swt: { inline_media: [0] },
}
)
).toBe('translated\n![商务通表情](<http://localhost/emoji.gif>)');
});
it('does not resolve undeclared markers', () => {
const content = '![商务通表情](swt-attachment://0)';
expect(
formatShangwutongInlineContent(content, [{ dataUrl: '/private.png' }], {
swt: { inline_media: [] },
})
).toBe(content);
});
it('accepts numeric strings from JSON attributes', () => {
expect(
shangwutongInlineMediaIndexes({ swt: { inline_media: ['2'] } })
).toEqual(new Set([2]));
});
});