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
32 changes: 21 additions & 11 deletions apps/web/src/__tests__/components/VaultPanel.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ describe("VaultPanel — position load error", () => {
const amountInput = screen.getByPlaceholderText("0.00");
fireEvent.change(amountInput, { target: { value: "10" } });

const depositButton = screen
.getByText("vaultPanel.deposit")
.closest("button");
expect(depositButton?.disabled).toBe(false);
const depositButton = screen.getByTestId(
"vault-deposit-submit"
) as HTMLButtonElement;
expect(depositButton.disabled).toBe(false);
});

it("does not show the error message once positions load successfully", () => {
Expand Down Expand Up @@ -131,14 +131,27 @@ describe("VaultPanel — disconnected", () => {
});
});

describe("VaultPanel — tab switcher", () => {
it("translates the tab labels instead of rendering raw tab ids", () => {
render(<VaultPanel />);

expect(screen.getByTestId("vault-tab-deposit").textContent).toBe(
"vaultPanel.deposit"
);
expect(screen.getByTestId("vault-tab-withdraw").textContent).toBe(
"vaultPanel.withdraw"
);
});
});

describe("VaultPanel — deposit", () => {
it("calls deposit with the entered amount and clears the field on success", async () => {
render(<VaultPanel />);

fireEvent.change(screen.getByPlaceholderText("0.00"), {
target: { value: "25" },
});
fireEvent.click(screen.getByText("vaultPanel.deposit"));
fireEvent.click(screen.getByTestId("vault-deposit-submit"));

await waitFor(() => {
expect(deposit).toHaveBeenCalledWith("25", "meridian-usdc", "USDC");
Expand All @@ -154,14 +167,11 @@ describe("VaultPanel — withdraw", () => {
mockPositions({ isError: false, data: [POSITION] });
render(<VaultPanel />);

// The tab switcher renders a raw capitalized label ("Withdraw"), distinct
// from the action button below it, which renders the translated
// "vaultPanel.withdraw" key.
fireEvent.click(screen.getByText("Withdraw"));
fireEvent.click(screen.getByTestId("vault-tab-withdraw"));
fireEvent.change(screen.getByPlaceholderText("0.00"), {
target: { value: "10" },
});
fireEvent.click(screen.getByText("vaultPanel.withdraw"));
fireEvent.click(screen.getByTestId("vault-withdraw-submit"));

await waitFor(() => {
expect(withdraw).toHaveBeenCalledWith("10", "meridian-usdc", "USDC");
Expand All @@ -172,7 +182,7 @@ describe("VaultPanel — withdraw", () => {
mockPositions({ isError: false, data: [] });
render(<VaultPanel />);

fireEvent.click(screen.getByText("Withdraw"));
fireEvent.click(screen.getByTestId("vault-tab-withdraw"));
expect(screen.getByText("vaultPanel.position")).toBeDefined();
});
});
12 changes: 6 additions & 6 deletions apps/web/src/components/dashboard/VaultPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -195,18 +195,18 @@ export function VaultPanel() {
{/* Tab switcher */}
{connected && (
<div className="flex border-b border-gray-800">
{(["deposit", "withdraw"] as Tab[]).map((t) => (
{(["deposit", "withdraw"] as Tab[]).map((tabId) => (
<button
key={t}
data-testid={`vault-tab-${t}`}
onClick={() => handleTabChange(t)}
key={tabId}
data-testid={`vault-tab-${tabId}`}
onClick={() => handleTabChange(tabId)}
className={`flex-1 py-3 text-sm font-semibold transition-colors duration-150 ${
tab === t
tab === tabId
? "text-white border-b-2 border-emerald-500"
: "text-gray-600 hover:text-gray-400"
}`}
>
{t.charAt(0).toUpperCase() + t.slice(1)}
{t(`vaultPanel.${tabId}`)}
</button>
))}
</div>
Expand Down
Loading