Add projects
This commit is contained in:
parent
2d3a9ad623
commit
8b607dd700
1802 changed files with 503346 additions and 2 deletions
42
frontend/tests/visualConfigRoutingStrategy.test.ts
Normal file
42
frontend/tests/visualConfigRoutingStrategy.test.ts
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
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' } });
|
||||
});
|
||||
});
|
||||
Loading…
Reference in a new issue