Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: wallet card test #1275

Open
wants to merge 9 commits into
base: dev
Choose a base branch
from
Open

feat: wallet card test #1275

wants to merge 9 commits into from

Conversation

mhenriette
Copy link
Collaborator

@mhenriette mhenriette commented Jun 28, 2024

Submit a pull request

  • This is not a duplicate of an existing pull request.
  • No existing features have been broken without good reason.
  • Your commit messages are detailed
  • The code style guideline have been followed.
  • Documentation has been updated to reflect your changes.
  • Tests have been added or updated to reflect your changes.
  • All tests pass.

Pull Request Details

  • refactor the wallet component and create separate components to reduce the lines of code
  • optimize the code
  • write test for each component

Breaking Changes

none

Issues Fixed

#1108

Other Relevant Information

Copy link

coderabbitai bot commented Jun 28, 2024

Walkthrough

Walkthrough

This update enhances the CardsWallet component by introducing an optional testId prop for improved testability. A comprehensive test suite for both CardsWallet and CashoutAddress components ensures their proper rendering and functionality within a Redux context. Additionally, the wallet management interface is enriched with updated mock data and improved component interactions, contributing to a more robust user experience.

Changes

Files Change Summary
__tests__/components/cards/cardsWallet.test.tsx, __tests__/components/cards/wallet/indext.test.tsx Added comprehensive test suites for CardsWallet and its child components to validate rendering and functionality.
__mocks__/fixtures/wallet.ts Updated mock wallet address to a specific value for enhanced semantic meaning.
src/components/cards/wallet/index.tsx Introduced a new optional testId prop in CardsWallet for improved testability and component interaction.
src/pages/profile/wallets.tsx Updated import path casing for the Wallet component to ensure consistency.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant T as Test Suite
    participant C as CardsWallet Component
    participant CA as CashoutAddress Component

    U->>T: Run Wallet tests
    T->>C: Render CardsWallet with mock data
    C-->>T: Return rendered component
    T->>CA: Render CashoutAddress with wallet info
    CA-->>T: Validate presence of elements based on KYC status
    T->>U: Validate presence of all UI elements
Loading

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

netlify bot commented Jun 28, 2024

Deploy Preview for staging-dacade ready!

Name Link
🔨 Latest commit 3836af5
🔍 Latest deploy log https://app.netlify.com/sites/staging-dacade/deploys/66cd7db54e9c2c0008b9ed7e
😎 Deploy Preview https://deploy-preview-1275--staging-dacade.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d3c774f and 5860bc5.

Files selected for processing (1)
  • tests/components/cards/Wallet.test.tsx (1 hunks)
Additional comments not posted (1)
__tests__/components/cards/Wallet.test.tsx (1)

11-25: Review of the Wallet Component Test Suite

  1. Test Description Clarity: The test description "renders the wallet component" is clear but could be more descriptive regarding what specific aspects or states of the Wallet component it tests.

  2. Mock Data Usage: Mock data for wallet, user, and referrals are used appropriately to simulate the component's environment. This is good as it isolates the test from external dependencies.

  3. Redux State Integration: The renderWithRedux utility is correctly used, ensuring that the component is tested within a pseudo-Redux environment. However, the as any casting on lines 13-22 is risky as it bypasses TypeScript's type safety. It would be beneficial to define a proper type for the state object used in tests to catch potential mismatches or errors at compile time.

  4. Commented Code: There's commented code on lines 6-8 related to mocking a Redux slice. If this is not needed, it should be removed to keep the test file clean and maintainable.

  5. Test Coverage: Currently, only the rendering of the component is tested. Consider adding more tests to cover user interactions, state transitions, or props changes to ensure comprehensive coverage.

While the test setup looks good, consider the above points for enhancing the test suite.

@mhenriette mhenriette changed the title feat: start wallet test feat: wallet card test Jun 28, 2024
@mhenriette mhenriette self-assigned this Jun 28, 2024
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 5860bc5 and 2330c48.

Files selected for processing (2)
  • tests/components/cards/Wallet.test.tsx (1 hunks)
  • src/components/cards/Wallet.tsx (3 hunks)
Additional comments not posted (6)
__tests__/components/cards/Wallet.test.tsx (3)

1-5: Imports look good!

The necessary modules and mock data are correctly imported.


8-11: Mock setup looks good!

The jest mock for the EditAddress component is correctly implemented.


13-21: Test case looks good!

The test case correctly checks if the CardsWallet component renders with all required elements.

src/components/cards/Wallet.tsx (3)

23-23: Optional testId prop looks good!

The testId prop is correctly defined as an optional string.


32-32: Destructuring testId prop looks good!

The testId prop is correctly destructured with a default value of 'cardWalletId'.


78-78: Applying testId prop to JSX looks good!

The testId prop is correctly applied to the data-testid attribute of the main div.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2330c48 and baf824a.

Files selected for processing (1)
  • src/components/cards/Wallet.tsx (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/components/cards/Wallet.tsx

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between baf824a and 0d1e3ad.

Files selected for processing (10)
  • mocks/fixtures/wallet.ts (1 hunks)
  • tests/components/cards/Wallet.test.tsx (1 hunks)
  • jest.config.js (1 hunks)
  • jest.polyfills.js (2 hunks)
  • src/components/cards/wallet/CashoutAddress.tsx (1 hunks)
  • src/components/cards/wallet/Overview.tsx (1 hunks)
  • src/components/cards/wallet/WalletHint.tsx (1 hunks)
  • src/components/cards/wallet/index.tsx (1 hunks)
  • src/components/sections/profile/modals/Payout.tsx (3 hunks)
  • src/pages/profile/wallets.tsx (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • tests/components/cards/Wallet.test.tsx
Additional context used
Biome
src/components/cards/wallet/CashoutAddress.tsx

[error] 78-78: Avoid passing content using the dangerouslySetInnerHTML prop.

Setting content using code can expose users to cross-site scripting (XSS) attacks

(lint/security/noDangerouslySetInnerHtml)

Additional comments not posted (20)
__mocks__/fixtures/wallet.ts (1)

21-21: Verify the impact of the updated address.

The address field in mockWallet has been updated. Ensure that this change does not break any tests or functionality relying on this mock data.

Verification successful

The updated address in mockWallet does not break any tests or functionality.

The test case in Wallet.test.tsx does not directly assert on the address field of mockWallet, so the updated address should not impact the test results.

  • __tests__/components/cards/Wallet.test.tsx
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the updated address in mockWallet does not break any tests or functionality.

# Test: Run all tests to ensure they pass after the address update.
npm test

Length of output: 81


Script:

#!/bin/bash
# Search for occurrences of `mockWallet` in the codebase to identify where this mock data is used.
rg -A 5 'mockWallet'

Length of output: 2027


Script:

#!/bin/bash
# Search for test cases in Wallet.test.tsx to inspect how mockWallet is being utilized.
rg 'test\(' __tests__/components/cards/Wallet.test.tsx -A 10

Length of output: 62


Script:

#!/bin/bash
# Search for all function definitions in Wallet.test.tsx to inspect how mockWallet is being utilized.
ast-grep --lang typescript --pattern 'function $_($_) { $$$ }' __tests__/components/cards/Wallet.test.tsx

Length of output: 107


Script:

#!/bin/bash
# Search for occurrences of `mockWallet` in Wallet.test.tsx to inspect how it is being utilized.
rg 'mockWallet' __tests__/components/cards/Wallet.test.tsx -A 10

Length of output: 860

src/components/cards/wallet/WalletHint.tsx (1)

1-4: Verify localization keys.

Ensure that the localization key profile.wallet.payout.text is correctly defined in the translation files.

Verification successful

Localization key is correctly defined and utilized.

The localization key profile.wallet.payout.text is correctly defined in multiple translation files and is used in the WalletHint.tsx component.

  • public/locales/hr/common.json
  • public/locales/es/common.json
  • public/locales/en/common.json
  • public/locales/bg/common.json
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the localization key `profile.wallet.payout.text` is defined in the translation files.

# Test: Search for the localization key in the translation files.
rg 'profile\.wallet\.payout\.text'

Length of output: 888

jest.polyfills.js (1)

24-24: Verify the impact of adding clearImmediate.

The clearImmediate function has been added to the global scope. Ensure that this addition does not introduce any conflicts or issues.

Verification successful

No conflicts found with adding clearImmediate to the global scope.

The addition of clearImmediate to the global scope in jest.polyfills.js does not introduce any conflicts or issues. It is defined and added in a consistent manner with other polyfills.

  • jest.polyfills.js:
    • clearImmediate is added to the global scope without conflicts.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the addition of `clearImmediate` to the global scope does not introduce any conflicts or issues.

# Test: Run all tests to ensure they pass after adding `clearImmediate`.
npm test

Length of output: 81


Script:

#!/bin/bash
# Search for existing usages of `clearImmediate` in the codebase
rg 'clearImmediate' -A 5

# Check if `clearImmediate` is being added to the global scope in jest.polyfills.js
rg 'global.clearImmediate' jest.polyfills.js -A 5

Length of output: 453


Script:

#!/bin/bash
# Search for other polyfills or global definitions in jest.polyfills.js
rg 'Object.defineProperties(globalThis' jest.polyfills.js -A 10

Length of output: 174


Script:

#!/bin/bash
# Search for other polyfills or global definitions in jest.polyfills.js with corrected regex pattern
rg 'Object\.defineProperties\(globalThis' jest.polyfills.js -A 10

Length of output: 762

jest.config.js (1)

31-31: LGTM!

The addition of the alias mapping for @/ to the moduleNameMapper object is a good practice. It enhances the flexibility of module imports in tests and aligns with the project's structure.

src/components/cards/wallet/Overview.tsx (3)

1-6: LGTM!

The imports are well-organized and necessary for the Overview component. The usage of the @/ alias is consistent with the new alias mapping in jest.config.js.


7-10: LGTM!

The OverviewProps interface is well-defined, including the optional testId prop which enhances testability.


12-37: LGTM!

The Overview component is well-structured, making good use of the useTranslation hook and rendering the wallet details effectively. The inclusion of the testId prop for testing purposes is a good practice.

src/components/cards/wallet/index.tsx (3)

1-10: LGTM!

The imports are well-organized and necessary for the CardsWallet component. The usage of the @/ alias is consistent with the new alias mapping in jest.config.js.


11-18: LGTM!

The CardsWalletProps interface is well-defined, including the optional testId prop which enhances testability.


20-47: LGTM!

The CardsWallet component is well-structured, making good use of hooks and rendering the wallet card with modals effectively. The inclusion of the testId prop for testing purposes is a good practice.

src/pages/profile/wallets.tsx (1)

9-9: Verify the correctness of the import path.

The import path for the Wallet component has been changed from @/components/cards/Wallet to @/components/cards/wallet. Ensure that the new path is correct and does not break the functionality.

src/components/sections/profile/modals/Payout.tsx (2)

23-23: LGTM!

The addition of the optional testId property to the PayoutProps interface is correctly defined and enhances the component's testability.


38-38: LGTM!

The Payout component has been correctly updated to include the testId property in its parameter list and its usage within the returned JSX, enhancing the component's testability.

src/components/cards/wallet/CashoutAddress.tsx (7)

1-8: LGTM!

The import statements are correctly defined and include all necessary modules for the CashoutAddress component.


11-17: LGTM!

The CashoutAddressProps interface is correctly defined and includes all necessary properties, including the optional testId property.


28-32: LGTM!

The triggerEditAddress function is correctly defined and handles the necessary actions to set the current wallet and show the edit modal.


34-37: LGTM!

The triggerCashout function is correctly defined and handles the necessary actions to show the payout modal and toggle body scrolling.


39-49: LGTM!

The triggerKYCVerification function is correctly defined and handles the necessary actions to open the verification modal with specific parameters.


50-53: LGTM!

The cashout function is correctly defined and handles the necessary actions based on the user's KYC verification status.


56-74: LGTM!

The conditionally rendered elements for cashable wallets are correctly defined and handle the necessary functionality for address display and edit.

Comment on lines +6 to +8
interface HintProps {
wallet: Wallet;
}
Copy link

Choose a reason for hiding this comment

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

Add prop types validation.

Consider adding prop types validation to ensure that the wallet prop conforms to the expected shape.

import PropTypes from 'prop-types';

interface HintProps {
  wallet: Wallet;
}

WalletHint.propTypes = {
  wallet: PropTypes.shape({
    payouts: PropTypes.arrayOf(
      PropTypes.shape({
        amount: PropTypes.number.isRequired,
        token: PropTypes.string.isRequired,
      })
    ).isRequired,
  }).isRequired,
};

triggerCashout();
};
return (
<div className="px-7 pt-6 flex-1 pb-24 lg:pb-24" data-testId={testId}>
Copy link

Choose a reason for hiding this comment

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

Fix typo in data-testid attribute.

The data-testid attribute should be written in lowercase to ensure consistency and avoid potential issues.

-  <div className="px-7 pt-6 flex-1 pb-24 lg:pb-24" data-testId={testId}>
+  <div className="px-7 pt-6 flex-1 pb-24 lg:pb-24" data-testid={testId}>
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<div className="px-7 pt-6 flex-1 pb-24 lg:pb-24" data-testId={testId}>
<div className="px-7 pt-6 flex-1 pb-24 lg:pb-24" data-testid={testId}>

Comment on lines +76 to +85
<div className="prose">
<p
dangerouslySetInnerHTML={{
__html: t("profile.wallets.uncashable", {
token: `${wallet.title}`,
link: "https://discord.gg/5yDZvVnpQQ",
}),
}}
/>
</div>
Copy link

Choose a reason for hiding this comment

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

Avoid using dangerouslySetInnerHTML.

Using dangerouslySetInnerHTML can expose users to cross-site scripting (XSS) attacks. Consider using a safer alternative to render the message.

-  <p
-    dangerouslySetInnerHTML={{
-      __html: t("profile.wallets.uncashable", {
-        token: `${wallet.title}`,
-        link: "https://discord.gg/5yDZvVnpQQ",
-      }),
-    }}
-  />
+  <p>
+    {t("profile.wallets.uncashable", {
+      token: `${wallet.title}`,
+      link: <a href="https://discord.gg/5yDZvVnpQQ">https://discord.gg/5yDZvVnpQQ</a>,
+    })}
+  </p>

Committable suggestion was skipped due to low confidence.

Tools
Biome

[error] 78-78: Avoid passing content using the dangerouslySetInnerHTML prop.

Setting content using code can expose users to cross-site scripting (XSS) attacks

(lint/security/noDangerouslySetInnerHtml)

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Outside diff range, codebase verification and nitpick comments (5)
__tests__/components/cards/wallet/Overview.test.tsx (1)

12-20: Add descriptive messages to expect statements.

Adding descriptive messages to the expect statements will make the test output more informative and easier to debug.

-    expect(screen.getByTestId("overviewId")).toBeInTheDocument();
-    expect(screen.getByText(wallet.title)).toBeInTheDocument();
-    expect(screen.getByText("profile.wallets.balance")).toBeInTheDocument();
-    expect(screen.getByTestId("currencyId")).toBeInTheDocument();
-    expect(screen.getByTestId("coin")).toBeInTheDocument();
-    expect(screen.getByTestId("tag")).toBeInTheDocument();
+    expect(screen.getByTestId("overviewId")).toBeInTheDocument("Overview component should be in the document");
+    expect(screen.getByText(wallet.title)).toBeInTheDocument("Wallet title should be in the document");
+    expect(screen.getByText("profile.wallets.balance")).toBeInTheDocument("Balance text should be in the document");
+    expect(screen.getByTestId("currencyId")).toBeInTheDocument("Currency component should be in the document");
+    expect(screen.getByTestId("coin")).toBeInTheDocument("Coin component should be in the document");
+    expect(screen.getByTestId("tag")).toBeInTheDocument("Tag component should be in the document");
__tests__/components/cards/wallet/indext.test.tsx (1)

17-23: Add descriptive messages to expect statements.

Adding descriptive messages to the expect statements will make the test output more informative and easier to debug.

-    expect(screen.getByTestId("cardWalletId")).toBeInTheDocument();
-    expect(screen.getByTestId("overviewId")).toBeInTheDocument();
-    expect(screen.getByTestId("cashoutAddressId")).toBeInTheDocument();
-    expect(screen.queryByText("profile.wallet.payout.text")).not.toBeNull();
+    expect(screen.getByTestId("cardWalletId")).toBeInTheDocument("Card Wallet component should be in the document");
+    expect(screen.getByTestId("overviewId")).toBeInTheDocument("Overview component should be in the document");
+    expect(screen.getByTestId("cashoutAddressId")).toBeInTheDocument("Cashout Address component should be in the document");
+    expect(screen.queryByText("profile.wallet.payout.text")).not.toBeNull("Payout text should not be null");
__tests__/components/cards/wallet/WalletHint.test.tsx (3)

16-20: Add descriptive messages to expect statements.

Adding descriptive messages to the expect statements will make the test output more informative and easier to debug.

-    expect(textElements).toHaveLength(wallet.payouts.length);
+    expect(textElements).toHaveLength(wallet.payouts.length, "Number of Hint components should match the number of payouts");

22-26: Add descriptive messages to expect statements.

Adding descriptive messages to the expect statements will make the test output more informative and easier to debug.

-    expect(hints).toHaveLength(wallet.payouts.length);
+    expect(hints).toHaveLength(wallet.payouts.length, "Number of Hint components should match the number of payouts");

28-35: Add descriptive messages to expect statements.

Adding descriptive messages to the expect statements will make the test output more informative and easier to debug.

-    expect(currencyElements).toHaveLength(wallet.payouts.length);
-    wallet.payouts.forEach((payout, index) => {
-      const element = currencyElements[index];
-      expect(element).toHaveTextContent(new RegExp(`${payout.token}`));
-    });
+    expect(currencyElements).toHaveLength(wallet.payouts.length, "Number of Currency components should match the number of payouts");
+    wallet.payouts.forEach((payout, index) => {
+      const element = currencyElements[index];
+      expect(element).toHaveTextContent(new RegExp(`${payout.token}`), `Currency component at index ${index} should contain text ${payout.token}`);
+    });
Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 0d1e3ad and 05d2f1b.

Files selected for processing (3)
  • tests/components/cards/wallet/Overview.test.tsx (1 hunks)
  • tests/components/cards/wallet/WalletHint.test.tsx (1 hunks)
  • tests/components/cards/wallet/indext.test.tsx (1 hunks)

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 05d2f1b and b1128d0.

Files selected for processing (3)
  • mocks/fixtures/wallet.ts (1 hunks)
  • tests/components/cards/wallet/CashoutAddress.test.tsx (1 hunks)
  • tests/components/cards/wallet/indext.test.tsx (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • mocks/fixtures/wallet.ts
  • tests/components/cards/wallet/indext.test.tsx
Additional comments not posted (5)
__tests__/components/cards/wallet/CashoutAddress.test.tsx (5)

1-9: Imports look good.

The import statements are appropriate and necessary for the test file.


11-13: Jest mocks are correctly set up.

The jest mocks for useTypedDispatch and kyc.slice are correctly set up.

Also applies to: 24-30


15-22: Mock data is well-structured.

The mock data for walletMock, mockUserStore, and verifiedUserStore is well-structured and appropriate for the tests.

Also applies to: 32-43, 45-59


60-60: Address formatting is appropriate.

The address is formatted by splitting it into chunks of 4 characters, which is a good approach for readability.


62-110: Test cases are comprehensive and well-written.

The test cases cover various scenarios, including rendering with props, triggering modals, and handling user interactions.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between b1128d0 and ccc0b40.

Files selected for processing (1)
  • tests/components/cards/wallet/indext.test.tsx (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • tests/components/cards/wallet/indext.test.tsx

};
});

const mockUserStore = {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a fixtured instead:

Suggested change
const mockUserStore = {
const FixtureUserStore = {

describe("CashoutAddress component", () => {
let setShowEditModal: () => void;
let setShowPayoutModal: () => void;
const mockDispatch = jest.fn();
Copy link
Contributor

Choose a reason for hiding this comment

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

This is already mocked I guess

beforeEach(() => {
setShowEditModal = jest.fn();
setShowPayoutModal = jest.fn();
(useDispatch as jest.Mock).mockReturnValue(mockDispatch);
Copy link
Contributor

Choose a reason for hiding this comment

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

You already mocked useDispatch; why again redoing it before each test?

Copy link
Contributor

Choose a reason for hiding this comment

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

The code in here is not formatted

Comment on lines +19 to +25
expect(textElements).toHaveLength(wallet.payouts.length);
});

it("renders the correct number of Hint components", () => {
render(<WalletHint wallet={wallet} />);
const hints = screen.getAllByText("profile.wallet.payout.text");
expect(hints).toHaveLength(wallet.payouts.length);
Copy link
Contributor

Choose a reason for hiding this comment

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

It good already that you are checking the length; it might also be better if you can check the amount and the token is well rendered in the component

<div className="text-sm text-gray-700">
{address ? (
<p className="leading-5 text-sm flex gap-x-2 gap-y-1 flex-wrap font-mono font-normal">
{address.map((part, k) => (
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
{address.map((part, k) => (
{address.map((part, i) => (

{address ? (
<p className="leading-5 text-sm flex gap-x-2 gap-y-1 flex-wrap font-mono font-normal">
{address.map((part, k) => (
<span key={`address-${k}`} className="mr-2">
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
<span key={`address-${k}`} className="mr-2">
<span key={`address-${i}`} className="mr-2">

Copy link
Contributor

Choose a reason for hiding this comment

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

Would you refactor this component in way that we have less of if else ? : ? : ? :

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

we don't have any if else, we are using a ternary operator to avoid many if conditions

import Hint from "@/components/ui/Hint";
import { useTranslation } from "next-i18next";

interface HintProps {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we use type for components props

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We are using interface in all components, I think we can stick to same approach

export default function WalletHint({ wallet }: HintProps) {
const { t } = useTranslation();
return (
<>
Copy link
Contributor

Choose a reason for hiding this comment

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

There is no need of fragements

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

we need them to return single JSX

@mhenriette mhenriette added the BLOCKED This tasked is blocked by another task label Aug 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BLOCKED This tasked is blocked by another task ready for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create src/components/cards/Wallet component test
2 participants