Skip to content
Merged
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
13 changes: 10 additions & 3 deletions src/app/(dashboard)/home/ProviderQuotaWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,11 @@ export default function ProviderQuotaWidget({ autoRefreshInterval = 0 }: Provide
onClick={refreshAll}
disabled={refreshingAll || loading}
className="flex items-center gap-1.5 px-3 py-1.5 rounded-lg border border-border bg-bg-subtle text-xs font-medium text-text-main disabled:opacity-50 disabled:cursor-not-allowed hover:bg-surface transition-colors"
title={autoRefreshIntervalMs > 0 ? tr("autoRefreshing", "Auto-refreshing") : tr("refreshAll", "Refresh All")}
title={
autoRefreshIntervalMs > 0
? tr("autoRefreshing", "Auto-refreshing")
: tr("refreshAll", "Refresh All")
}
>
<span
className={`material-symbols-outlined text-[16px] ${refreshingAll ? "animate-spin" : ""}`}
Expand All @@ -187,7 +191,10 @@ export default function ProviderQuotaWidget({ autoRefreshInterval = 0 }: Provide
? tr("refreshing", "Refreshing")
: autoRefreshIntervalMs > 0
? `${tr("autoRefreshing", "Auto-refreshing")} ${formatAutoRefreshCountdown(
Math.max(0, autoRefreshIntervalMs - (autoRefreshClock - lastRefreshAllAtRef.current))
Math.max(
0,
autoRefreshIntervalMs - (autoRefreshClock - lastRefreshAllAtRef.current)
)
)}`
: tr("refreshAll", "Refresh All")}
</span>
Expand Down Expand Up @@ -224,7 +231,7 @@ export default function ProviderQuotaWidget({ autoRefreshInterval = 0 }: Provide
className="rounded-lg border border-border bg-surface/40 p-3 flex flex-col gap-2"
>
<div className="flex items-center gap-2">
<ProviderIcon provider={provider} size={18} />
<ProviderIcon providerId={provider} size={18} />
<span className="font-medium text-sm truncate">
{provider.charAt(0).toUpperCase() + provider.slice(1)}
</span>
Expand Down
22 changes: 22 additions & 0 deletions tests/unit/provider-quota-widget-icon-prop.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import test from "node:test";
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";

const ROOT = join(dirname(fileURLToPath(import.meta.url)), "..", "..");
const PROVIDER_QUOTA_WIDGET_PATH = join(ROOT, "src/app/(dashboard)/home/ProviderQuotaWidget.tsx");

const providerQuotaWidgetSrc = readFileSync(PROVIDER_QUOTA_WIDGET_PATH, "utf8");

test("ProviderQuotaWidget passes provider IDs using ProviderIcon's providerId prop", () => {
assert.ok(
providerQuotaWidgetSrc.includes("<ProviderIcon providerId={provider} size={18} />"),
"ProviderQuotaWidget must pass provider through ProviderIcon's providerId prop"
);
assert.equal(
providerQuotaWidgetSrc.includes("<ProviderIcon provider={provider}"),
false,
"ProviderQuotaWidget must not pass an unsupported provider prop to ProviderIcon"
);
});
Comment on lines +12 to +22

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Asserting on exact string matches of JSX code in a unit test is highly fragile. Any minor formatting change (such as Prettier wrapping props across multiple lines, changing spacing, or reordering props) will break this test even if the code remains perfectly correct.

Using regular expressions with wildcard whitespace matching makes the test significantly more robust and maintainable.

Suggested change
test("ProviderQuotaWidget passes provider IDs using ProviderIcon's providerId prop", () => {
assert.ok(
providerQuotaWidgetSrc.includes("<ProviderIcon providerId={provider} size={18} />"),
"ProviderQuotaWidget must pass provider through ProviderIcon's providerId prop"
);
assert.equal(
providerQuotaWidgetSrc.includes("<ProviderIcon provider={provider}"),
false,
"ProviderQuotaWidget must not pass an unsupported provider prop to ProviderIcon"
);
});
test("ProviderQuotaWidget passes provider IDs using ProviderIcon's providerId prop", () => {
const hasProviderIdProp = /<ProviderIcon\s+[^>]*providerId=\{provider\}/.test(providerQuotaWidgetSrc);
const hasUnsupportedProviderProp = /<ProviderIcon\s+[^>]*\bprovider=\{provider\}/.test(providerQuotaWidgetSrc);
assert.ok(
hasProviderIdProp,
"ProviderQuotaWidget must pass provider through ProviderIcon's providerId prop"
);
assert.equal(
hasUnsupportedProviderProp,
false,
"ProviderQuotaWidget must not pass an unsupported provider prop to ProviderIcon"
);
});