Skip to content

Commit

Permalink
Merge branch 'bugfix/unit-test-failed' of github.com-fe-explorer-card…
Browse files Browse the repository at this point in the history
…ano:cardano-foundation/cf-explorer-frontend into bugfix/unit-test
  • Loading branch information
Sotatek-TrungHoang committed Aug 3, 2023
2 parents 5b71a08 + ef4b7e9 commit 417949f
Show file tree
Hide file tree
Showing 16 changed files with 35 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import ContractDetailContent from ".";
describe("ContractDetailContent component", () => {
it("should component render", () => {
render(<ContractDetailContent />);
expect(screen.getByRole("tab", { name: /utxoicon\.svg transactions/i })).toBeInTheDocument();
expect(screen.getByRole("tab", { name: /utxoicon\.svg transaction/i })).toBeInTheDocument();
expect(screen.getByRole("tab", { name: /u_book\.svg script/i })).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe("DelegationOverview component", () => {
});
it("should component render", () => {
render(<OverViews />);
expect(screen.getByRole("heading", { name: /stake pools/i })).toBeInTheDocument();
expect(screen.getByRole("heading", { name: /stake pool/i })).toBeInTheDocument();
expect(screen.getByText(/delegators/i)).toBeInTheDocument();
expect(screen.getByText(/active pools/i)).toBeInTheDocument();
});
Expand Down
3 changes: 0 additions & 3 deletions src/components/Home/Statistic/Statistic.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,6 @@ describe("HomeStatistic", () => {
expect(screen.getByTestId("ada-current-price")).toHaveTextContent(`$${mockUSDMarket.current_price}`);
expect(screen.getByText("-1,59 %")).toBeInTheDocument();
expect(screen.getByTestId("ada-price-in-btc")).toHaveTextContent(`${mockBTCMarketItem.current_price} BTC`);
expect(screen.getByTestId("last-update-btc")).toHaveTextContent(
`Last updated ${moment(mockBTCMarketItem.last_updated).fromNow()}`
);
});

it("renders Market cap", async () => {
Expand Down
12 changes: 7 additions & 5 deletions src/components/Home/Statistic/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,11 @@ const HomeStatistic = () => {
</Box>
<Progress>
<CustomTooltip title={+progress || 0}>
<ProcessActive data-testid="live-stake-progress-active" rate={+progress || 0}>
<ProcessActive data-testid="current-epoch-progress-active" rate={+progress || 0}>
{+progress || 0}%
</ProcessActive>
</CustomTooltip>
<ProgressPending data-testid="live-stake-progress-pending" rate={100 - (+progress || 0)}>
<ProgressPending data-testid="current-epoch-progress-pending" rate={100 - (+progress || 0)}>
<Box color={({ palette }) => palette.secondary.light}>
{days}d {hours}h
</Box>
Expand Down Expand Up @@ -235,16 +235,18 @@ const HomeStatistic = () => {
<Box color={({ palette }) => palette.secondary.light}>
Active Stake (ADA):{" "}
<CustomTooltip title={formatADAFull(activeStake)}>
<>{formatADA(activeStake)}</>
<span data-testid="active-stake-value">{formatADA(activeStake)}</span>
</CustomTooltip>
</Box>
<Box fontSize={"12px"} color={({ palette }) => palette.secondary.light}>
Circulating supply (ADA):{" "}
<CustomTooltip title={numberWithCommas(supply)}>
<>{formatADA(circulatingSupply.toString())}</>
<span data-testid="circulating-supply-value">{formatADA(circulatingSupply.toString())}</span>
</CustomTooltip>
<CustomTooltip title={`${circulatingRate.toFixed(5)}%`}>
<>({circulatingRate.toFixed(0, BigNumber.ROUND_DOWN)}%)</>
<span data-testid="circulating-supply-percentage">
({circulatingRate.toFixed(0, BigNumber.ROUND_DOWN)}%)
</span>
</CustomTooltip>
</Box>
</Box>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ describe("TransactionChart", () => {
<TransactionChart />
</Router>
);
expect(screen.getByText(/Transactions in the last day/i)).toBeInTheDocument();
const oneDay = screen.getByText("1d");
expect(screen.getByText(/Transactions in the last 24 hours/i)).toBeInTheDocument();
const oneDay = screen.getByText("24h");
const oneWeek = screen.getByText("1w");
const twoWeek = screen.getByText("2w");
const oneMonth = screen.getByText("1m");
Expand All @@ -101,16 +101,16 @@ describe("TransactionChart", () => {
expect(twoWeek).toBeInTheDocument();
expect(oneMonth).toBeInTheDocument();

expect(screen.getByTestId("trx")).toHaveTextContent(numberWithCommas(mockItemDay.simpleTransactions));
expect(screen.getByTestId("trx")).toHaveTextContent(numberWithCommas(mockItemDay.metadata));
expect(screen.getByTestId("simple")).toHaveTextContent(numberWithCommas(mockItemDay.smartContract));
expect(screen.getByTestId("complex")).toHaveTextContent(numberWithCommas(mockItemDay.metadata));
expect(screen.getByTestId("complex")).toHaveTextContent(numberWithCommas(mockItemDay.simpleTransactions));

await userEvent.click(twoWeek);
await waitFor(async () => {
expect(screen.getByText("Transactions in two weeks")).toBeInTheDocument();
expect(screen.getByTestId("trx")).toHaveTextContent(numberWithCommas(mockItem2Week.simpleTransactions));
expect(screen.getByTestId("trx")).toHaveTextContent(numberWithCommas(mockItem2Week.metadata));
expect(screen.getByTestId("simple")).toHaveTextContent(numberWithCommas(mockItem2Week.smartContract));
expect(screen.getByTestId("complex")).toHaveTextContent(numberWithCommas(mockItem2Week.metadata));
expect(screen.getByTestId("complex")).toHaveTextContent(numberWithCommas(mockItem2Week.simpleTransactions));
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ describe("TokenAutocomplete component", () => {
it("should dropdown open", () => {
render(<TokenAutocomplete address="x23dxxfdd312hgc" />);
fireEvent.click(screen.getByRole("button", { name: /open/i }));
expect(screen.getByText(/token display #token/i)).toBeInTheDocument();
expect(screen.getByText(/token display/i)).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const mockProps = [{ address: "address-1", poolId: "pool-id-1" }];
describe("Delegations component", () => {
it("should component render", () => {
render(<Delegations data={mockProps} />);
expect(screen.getByText(/address stake key/i)).toBeInTheDocument();
expect(screen.getByText(/stake address/i)).toBeInTheDocument();
expect(screen.getByRole("link", { name: mockProps[0].address })).toBeInTheDocument();
expect(screen.getByRole("link", { name: mockProps[0].poolId })).toBeInTheDocument();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,18 @@ describe("DetailViewContractHash component", () => {
it("rendering component loading", () => {
const mockedUseFetch = useFetch as jest.Mock;
mockedUseFetch.mockReturnValue({
data: [mockedData]
data: [mockedData],
loading: true
});
render(<DetailViewContractHash txHash={"test-tx-hash"} address="test-address" handleClose={jest.fn()} />);
expect(screen.getByTestId("view-detail-drawer-contract-hash")).toBeInTheDocument();
expect(screen.getByText("Transactions")).toBeInTheDocument();
expect(screen.getByText(mockedData.purpose)).toBeInTheDocument();
expect(screen.getByText(mockedData.redeemerMem)).toBeInTheDocument();
expect(screen.getByTestId("view-detail-drawer-loading")).toBeInTheDocument();
});

it("rendering component on PC", () => {
const mockedUseFetch = useFetch as jest.Mock;
mockedUseFetch.mockReturnValue({
data: [mockedData]
data: [mockedData],
initialized: true
});
render(<DetailViewContractHash txHash={"test-tx-hash"} address="test-address" handleClose={jest.fn()} />);
expect(screen.getByTestId("view-detail-drawer-contract-hash")).toBeInTheDocument();
Expand Down
4 changes: 2 additions & 2 deletions src/components/commons/DetailView/DetailViewToken.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ describe("DetailViewToken component", () => {

it("should component render", () => {
render(<DetailViewToken handleClose={jest.fn()} token={mockToken} tokenId={mockTokenId} />);
expect(screen.getByText(/token metadata description/i)).toBeInTheDocument();
expect(screen.getByRole("heading", { name: /policy script/i })).toBeInTheDocument();
expect(screen.getByText(/Token Display Name/i)).toBeInTheDocument();
expect(screen.getByRole("heading", { name: /Transactions/i })).toBeInTheDocument();
expect(screen.getByRole("heading", { name: /top holders/i })).toBeInTheDocument();
});

Expand Down
9 changes: 4 additions & 5 deletions src/components/commons/Layout/AccountLayout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ const AccountLayout: React.FC<Props> = ({ children }) => {
{router.map((route, index) => {
const active = route.to === pathname;
return (
<>
<React.Fragment key={index}>
<NavItemMobile
sx={{
borderTopRightRadius: index === router.length - 1 ? "5px" : "0px",
Expand All @@ -158,12 +158,11 @@ const AccountLayout: React.FC<Props> = ({ children }) => {
borderRadius: active ? "5px" : ""
}}
to={route.to}
active={active}
key={index}
active={+active}
>
{route.title}
</NavItemMobile>
<NavItem to={route.to} active={route.to === pathname} key={index}>
<NavItem to={route.to} active={+active}>
<Box
display="flex"
alignItems={"center"}
Expand All @@ -177,7 +176,7 @@ const AccountLayout: React.FC<Props> = ({ children }) => {
/>
</Box>
</NavItem>
</>
</React.Fragment>
);
})}
</WrapItemMobile>
Expand Down
4 changes: 2 additions & 2 deletions src/components/commons/Layout/AccountLayout/styled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const SideBar = styled(Box)(({ theme }) => ({
}
}));

export const NavItem = styled(Link)<{ active: boolean }>(({ theme, active }) => ({
export const NavItem = styled(Link)<{ active: number }>(({ theme, active }) => ({
textAlign: "left",
display: "block",
width: "100%",
Expand Down Expand Up @@ -55,7 +55,7 @@ export const WrapItemMobile = styled(Box)(({ theme }) => ({
}
}));

export const NavItemMobile = styled(Link)<{ active: boolean }>(({ theme, active }) => ({
export const NavItemMobile = styled(Link)<{ active: number }>(({ theme, active }) => ({
[theme.breakpoints.down("md")]: {
display: "block"
},
Expand Down
2 changes: 1 addition & 1 deletion src/components/commons/Layout/Header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const Header: React.FC<RouteComponentProps> = (props) => {
</NetworkContainer>
<LoginButton />
{history.location.pathname !== routers.STAKING_LIFECYCLE && (
<SearchButton onClick={handleOpenSearch} home={home}>
<SearchButton onClick={handleOpenSearch} home={+home}>
<SearchIcon fontSize={24} />
</SearchButton>
)}
Expand Down
2 changes: 1 addition & 1 deletion src/components/commons/Layout/Header/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export const HeaderLogo = styled("img")(({ theme }) => ({
}
}));

export const SearchButton = styled(Button)<{ home?: boolean }>(({ theme, home }) => ({
export const SearchButton = styled(Button)<{ home?: number }>(({ theme, home }) => ({
padding: 0,
minWidth: 24,
height: 24,
Expand Down
2 changes: 1 addition & 1 deletion src/components/commons/Layout/Layout.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ describe("Layout component", () => {
);
expect(screen.getByText(/contents/i)).toBeInTheDocument();
expect(screen.getByText(/header-search\.svg/i)).toBeInTheDocument();
expect(screen.getByRole("heading", { name: /cardano blockchain explorer/i })).toBeInTheDocument();
expect(screen.getByRole("heading", { name: /cardano explorer/i })).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe("ToastContainer", () => {
toasts: [mockSuccess]
});
render(<ToastContainer />);
expect(screen.getByText(/successfully/i)).toBeInTheDocument();
expect(screen.getByText(/success/i)).toBeInTheDocument();
expect(screen.getByText(/toast message/i)).toBeInTheDocument();
});

Expand Down
2 changes: 1 addition & 1 deletion src/pages/TopDelegators/TopDelegators.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe("TopDelegators page", () => {
it("should component render", () => {
render(<TopDelegators />);
expect(screen.getByText(/delegators/i)).toBeInTheDocument();
expect(screen.getByRole("columnheader", { name: /stake key addresses/i })).toBeInTheDocument();
expect(screen.getByRole("columnheader", { name: /stake address/i })).toBeInTheDocument();
expect(screen.getByRole("columnheader", { name: /pool/i })).toBeInTheDocument();
expect(screen.getByRole("columnheader", { name: /stake amount/i })).toBeInTheDocument();
});
Expand Down

0 comments on commit 417949f

Please sign in to comment.