Skip to content

Commit

Permalink
Update History.test.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
0xDegenDeveloper committed Jan 31, 2025
1 parent 1cbb59f commit 5ebdac5
Showing 1 changed file with 24 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ describe("History Component", () => {
const mockHistoryItems = [
{
bid_id: "1",
amount: "1000",
amount: "1000000000", // 1 billion
price: "500000000", // 0.5 GWEI
roundState: "Auctioning",
},
{
bid_id: "2",
amount: "2000",
amount: "2000000000", // 2 billion
price: "1000000000", // 1 GWEI
roundState: "Auctioning",
},
Expand Down Expand Up @@ -98,18 +98,20 @@ describe("History Component", () => {
isTabsHidden={false}
setBidToEdit={mockSetBidToEdit}
setIsTabsHidden={mockSetIsTabsHidden}
/>
/>,
);

// Check if both history items are rendered
expect(screen.getByText(/1,000 options at 0.5 GWEI each/)).toBeInTheDocument();
expect(screen.getByText(/2,000 options at 1 GWEI each/)).toBeInTheDocument();
expect(
screen.getByText(/1.0b options at 0.5 GWEI each/),
).toBeInTheDocument();
expect(screen.getByText(/2.0b options at 1 GWEI each/)).toBeInTheDocument();

// Check if total ETH values are displayed
const ethValues = screen.getAllByText(/Total: .* ETH/);
expect(ethValues).toHaveLength(2);
expect(ethValues[0]).toHaveTextContent("Total: 5.000000000000001e-7 ETH");
expect(ethValues[1]).toHaveTextContent("Total: 0.0000020000000000000003 ETH");
expect(ethValues[0]).toHaveTextContent("Total: 0.5 ETH");
expect(ethValues[1]).toHaveTextContent("Total: 2 ETH");
});

it("shows edit button only when roundState is Auctioning", () => {
Expand All @@ -120,7 +122,7 @@ describe("History Component", () => {
isTabsHidden={false}
setBidToEdit={mockSetBidToEdit}
setIsTabsHidden={mockSetIsTabsHidden}
/>
/>,
);

// Should find two edit buttons (one for each history item)
Expand All @@ -141,7 +143,7 @@ describe("History Component", () => {
isTabsHidden={false}
setBidToEdit={mockSetBidToEdit}
setIsTabsHidden={mockSetIsTabsHidden}
/>
/>,
);

// Should not find any edit buttons
Expand All @@ -156,7 +158,7 @@ describe("History Component", () => {
isTabsHidden={false}
setBidToEdit={mockSetBidToEdit}
setIsTabsHidden={mockSetIsTabsHidden}
/>
/>,
);

const editButtons = container.getElementsByClassName("edit-button");
Expand All @@ -176,7 +178,7 @@ describe("History Component", () => {
isTabsHidden={false}
setBidToEdit={mockSetBidToEdit}
setIsTabsHidden={mockSetIsTabsHidden}
/>
/>,
);

// Should render an empty div
Expand All @@ -192,15 +194,20 @@ describe("History Component", () => {
isTabsHidden={false}
setBidToEdit={mockSetBidToEdit}
setIsTabsHidden={mockSetIsTabsHidden}
/>
/>,
);

const historyItems = screen.getAllByText(/options at/);

// First item should have border
expect(historyItems[0].parentElement?.parentElement).toHaveClass("border-b");

expect(historyItems[0].parentElement?.parentElement).toHaveClass(
"border-b",
);

// Last item should not have border
expect(historyItems[1].parentElement?.parentElement).not.toHaveClass("border-b");
expect(historyItems[1].parentElement?.parentElement).not.toHaveClass(
"border-b",
);
});
});
});

0 comments on commit 5ebdac5

Please sign in to comment.