Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 3 additions & 17 deletions gui/src/components/combo-workspace-controls.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useState } from "react";
import type { ComboEffort, ComboStrategy, ComboTarget, ProviderQuotaStates } from "../combo-workspace-data";
import { comboImagesSupported } from "../combo-capabilities";
import { COMBO_EFFORTS, COMBO_STRATEGY_LABEL_KEYS, newComboTarget } from "../combo-workspace-data";
import { COMBO_EFFORTS, COMBO_STRATEGIES, COMBO_STRATEGY_LABEL_KEYS, newComboTarget } from "../combo-workspace-data";
import { IconArrowDown, IconArrowUp, IconGrip, IconPlus, IconTrash } from "../icons";
import { useT } from "../i18n/shared";
import { Switch } from "../ui";
Expand All @@ -21,10 +21,7 @@ export function StrategySeg({
const t = useT();
return (
<div className="cwi-strategy-seg" role="radiogroup" aria-label={t("cws.strategy")}>
{([
["failover", "cws.strategy.failover"],
["round-robin", "cws.strategy.roundRobin"],
] as const).map(([id, key]) => (
{COMBO_STRATEGIES.map((id) => (
<button
key={id}
type="button"
Expand All @@ -34,20 +31,9 @@ export function StrategySeg({
disabled={disabled}
onClick={() => onChange(id)}
>
{t(key)}
{t(COMBO_STRATEGY_LABEL_KEYS[id])}
</button>
))}
{value !== "failover" && value !== "round-robin" ? (
<button
type="button"
role="radio"
aria-checked={true}
className="btn btn-sm btn-primary"
disabled
>
{t(COMBO_STRATEGY_LABEL_KEYS[value])}
</button>
) : null}
</div>
);
}
Expand Down
31 changes: 31 additions & 0 deletions gui/tests/combo-strategy-selector.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { afterEach, beforeEach, expect, test } from "bun:test";
import { renderToStaticMarkup } from "react-dom/server";
import { StrategySeg } from "../src/components/combo-workspace-controls";
import { LanguageProvider } from "../src/i18n/provider";

let previousLanguage: unknown;

beforeEach(() => {
previousLanguage = (globalThis.navigator as { language?: unknown } | undefined)?.language;
Object.defineProperty(globalThis.navigator, "language", { configurable: true, value: "en-US" });
});

afterEach(() => {
Object.defineProperty(globalThis.navigator, "language", { configurable: true, value: previousLanguage });
});

test("combo strategy selector exposes all runtime strategies", () => {
const html = renderToStaticMarkup(
<LanguageProvider>
<StrategySeg value="random" onChange={() => {}} />
</LanguageProvider>,
);
const radios = html.match(/<button[^>]*role="radio"[^>]*>/g) ?? [];
expect(radios).toHaveLength(5);
expect(html).toContain("Failover");
expect(html).toContain("Round-robin");
expect(html).toContain("Random");
expect(html).toContain("Least-used");
expect(html).toContain("Reset-window");
expect(radios.every((button) => !button.includes("disabled="))).toBe(true);
});
Loading