2026-07-11 19:01:25 +08:00
|
|
|
import { describe, expect, test } from 'bun:test';
|
|
|
|
|
import { createElement, useState } from 'react';
|
|
|
|
|
import { renderToStaticMarkup } from 'react-dom/server';
|
|
|
|
|
import { parse as parseYaml } from 'yaml';
|
2026-09-28 12:55:16 +08:00
|
|
|
import { parseDisableImageGenerationMode, useVisualConfig } from '../src/hooks/useVisualConfig';
|
2026-07-11 19:01:25 +08:00
|
|
|
|
|
|
|
|
describe('visual config disable-image-generation', () => {
|
|
|
|
|
test('loads and writes the passthrough mode', () => {
|
|
|
|
|
expect(parseDisableImageGenerationMode('passthrough')).toBe('passthrough');
|
|
|
|
|
|
|
|
|
|
function Harness() {
|
|
|
|
|
const visualConfig = useVisualConfig();
|
|
|
|
|
const [phase, setPhase] = useState(0);
|
|
|
|
|
|
|
|
|
|
if (phase === 0) {
|
|
|
|
|
visualConfig.setVisualValues({ disableImageGeneration: 'passthrough' });
|
|
|
|
|
setPhase(1);
|
|
|
|
|
} else {
|
|
|
|
|
return createElement(
|
|
|
|
|
'pre',
|
|
|
|
|
null,
|
2026-09-28 12:55:16 +08:00
|
|
|
visualConfig.applyVisualChangesToYaml('multimedia:\n disable-image-generation: false\n')
|
2026-07-11 19:01:25 +08:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const markup = renderToStaticMarkup(createElement(Harness));
|
|
|
|
|
const result = markup.slice('<pre>'.length, -'</pre>'.length);
|
|
|
|
|
|
2026-09-28 12:55:16 +08:00
|
|
|
expect(parseYaml(result)).toEqual({
|
|
|
|
|
multimedia: { 'disable-image-generation': 'passthrough' },
|
|
|
|
|
});
|
2026-07-11 19:01:25 +08:00
|
|
|
});
|
|
|
|
|
});
|