Skip to content

Commit

Permalink
Merge pull request #1104 from trilitech/fix-internal-prefix-bugs
Browse files Browse the repository at this point in the history
Fix internal prefix bugs
  • Loading branch information
serjonya-trili authored Apr 12, 2024
2 parents edff55a + 7c4d5a2 commit 2109d4c
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/components/OperationTile/InternalPrefix.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const InternalPrefix: React.FC<{
}

return (
<Heading marginRight="4px" color={colors.gray[450]} size="md">
<Heading marginRight="4px" color={colors.gray[450]} data-testid="internal-prefix" size="md">
Internal:
</Heading>
);
Expand Down
28 changes: 28 additions & 0 deletions src/components/OperationTile/TokenTransferTile.test.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { OperationTileContext } from "./OperationTileContext";
import { tokenTransferFixture, transactionFixture } from "./testUtils";
import { TokenTransferTile } from "./TokenTransferTile";
import * as operationDestinationModule from "./useGetOperationDestination";
import { mockImplicitAddress, mockLedgerAccount } from "../../mocks/factories";
import { addAccount } from "../../mocks/helpers";
import { ghostnetThezard } from "../../mocks/nftTokens";
import { render, screen } from "../../mocks/testUtils";
import { DefaultNetworks } from "../../types/Network";
import { Token, fromRaw } from "../../types/Token";
Expand Down Expand Up @@ -236,6 +238,32 @@ describe("<TokenTransferTile />", () => {
expect(screen.getByTestId("to")).toHaveTextContent("Account");
});
});

describe.each([
{ type: "NFT", transfer: tokenTransferFixture({ token: ghostnetThezard.token }) },
{ type: "token", transfer: tokenTransferFixture({}) },
])("for $type", ({ transfer }) => {
afterEach(() => jest.restoreAllMocks());

it("renders internal prefix for internal operations", () => {
jest
.spyOn(operationDestinationModule, "useGetOperationDestination")
.mockReturnValue("unrelated");

render(fixture(contextValue, transfer));

expect(screen.getByTestId("internal-prefix")).toBeVisible();
});

it("does not render internal prefix for normal operations", () => {
jest
.spyOn(operationDestinationModule, "useGetOperationDestination")
.mockReturnValue("incoming");
render(fixture(contextValue, transfer));

expect(screen.queryByTestId("internal-prefix")).not.toBeInTheDocument();
});
});
});

describe("page mode", () => {
Expand Down
33 changes: 18 additions & 15 deletions src/components/OperationTile/TokenTransferTile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const TokenTransferTile: React.FC<{
}
openDelay={300}
>
<Flex>
<Center>
<InternalPrefix operation={operation || tokenTransfer} />
<TzktLink
marginRight="8px"
Expand All @@ -76,22 +76,25 @@ export const TokenTransferTile: React.FC<{
{tokenNameSafe(token)}
</Text>
</TzktLink>
</Flex>
</Center>
</Tooltip>
) : (
<TzktLink
marginRight="8px"
color={underlineColor}
data-testid="title"
migrationId={tokenTransfer.migrationId}
originationId={tokenTransfer.originationId}
transactionId={tokenTransfer.transactionId}
>
<Text display="inline" color={titleColor} fontWeight="600">
{sign}
{tokenAmount}
</Text>
</TzktLink>
<Center>
<InternalPrefix operation={operation || tokenTransfer} />
<TzktLink
marginRight="8px"
color={underlineColor}
data-testid="title"
migrationId={tokenTransfer.migrationId}
originationId={tokenTransfer.originationId}
transactionId={tokenTransfer.transactionId}
>
<Text display="inline" color={titleColor} fontWeight="600">
{sign}
{tokenAmount}
</Text>
</TzktLink>
</Center>
);

return (
Expand Down

1 comment on commit 2109d4c

@github-actions
Copy link

Choose a reason for hiding this comment

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

Coverage report

St.
Category Percentage Covered / Total
🟢 Statements 85.99% 3130/3640
🟡 Branches 78.97% 1078/1365
🟢 Functions 84.36% 982/1164
🟢 Lines 85.73% 2962/3455

Test suite run success

1368 tests passing in 170 suites.

Report generated by 🧪jest coverage report action from 2109d4c

Please sign in to comment.