vibe-proxy/frontend/tests/visualConfigRoutingStrategy.test.ts
2026-08-24 00:10:41 +02:00

42 lines
1.7 KiB
TypeScript

import { describe, expect, test } from 'vitest';
import { createElement, useState } from 'react';
import { renderToStaticMarkup } from 'react-dom/server';
import { parse as parseYaml } from 'yaml';
import { parseRoutingStrategy, useVisualConfig } from '../src/hooks/useVisualConfig';
describe('visual config weighted routing strategy', () => {
test('recognizes the weighted-round-robin backend value', () => {
expect(parseRoutingStrategy('weighted-round-robin')).toBe('weighted-round-robin');
expect(parseRoutingStrategy('weightedroundrobin')).toBe('weighted-round-robin');
expect(parseRoutingStrategy('wrr')).toBe('weighted-round-robin');
expect(parseRoutingStrategy('fill-first')).toBe('fill-first');
expect(parseRoutingStrategy('fillfirst')).toBe('fill-first');
expect(parseRoutingStrategy('ff')).toBe('fill-first');
expect(parseRoutingStrategy(undefined)).toBe('round-robin');
});
test('writes weighted-round-robin without coercing it to round-robin', () => {
function Harness() {
const visualConfig = useVisualConfig();
const [phase, setPhase] = useState(0);
if (phase === 0) {
visualConfig.setVisualValues({ routingStrategy: 'weighted-round-robin' });
setPhase(1);
} else {
return createElement(
'pre',
null,
visualConfig.applyVisualChangesToYaml('routing:\n strategy: round-robin\n')
);
}
return null;
}
const markup = renderToStaticMarkup(createElement(Harness));
const result = markup.slice('<pre>'.length, -'</pre>'.length);
expect(parseYaml(result)).toEqual({ routing: { strategy: 'weighted-round-robin' } });
});
});