mirror of
https://github.com/router-for-me/Cli-Proxy-API-Management-Center.git
synced 2026-08-28 16:31:13 +08:00
8faaa39534
- Implemented 'weighted-round-robin' as a new routing strategy in DashboardPage. - Introduced weight input fields in ApiKeyEntriesEditor, BaseProviderForm, and SponsorProviderForm. - Added validation for credential weights, including integer checks and maximum limits. - Updated localization files to include new weight-related labels and hints. - Created utility functions for credential weight validation and parsing. - Added tests for credential weight handling and visual config routing strategy.
43 lines
1.7 KiB
TypeScript
43 lines
1.7 KiB
TypeScript
import { describe, expect, test } from 'bun:test';
|
|
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' } });
|
|
});
|
|
});
|