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

Add ipPolicy and ipWidget tests #18

Merged
merged 2 commits into from
Jun 12, 2024
Merged

Add ipPolicy and ipWidget tests #18

merged 2 commits into from
Jun 12, 2024

Conversation

tyitang
Copy link
Contributor

@tyitang tyitang commented Jun 11, 2024

  • Add IpPolicyAccordion component test
  • Update IpWidget component test

Summary by CodeRabbit

  • New Features

    • Introduced new IP policy stories to the IpPolicyAccordion component, showcasing different policy scenarios.
    • Enhanced IpWidget stories with additional configurations and interactions, including top and bottom navigation options.
  • Improvements

    • Added constants for different policy types to improve story clarity and consistency.
    • Updated user interaction handling in IpWidget stories for a more accurate simulation.

Copy link

vercel bot commented Jun 11, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
storykit ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 12, 2024 2:10am

Copy link

coderabbitai bot commented Jun 11, 2024

Walkthrough

The recent updates introduce new constants and stories to the IpPolicyAccordion and IpWidget components, enhancing their functionality and interaction handling. These changes aim to provide better simulation and testing of various IP policy scenarios and navigation options within the components.

Changes

File Path Change Summary
packages/storykit/src/components/IpPolicyAccordion/__docs__/IpPolicyAccordion.stories.tsx Added POLICY_TYPE constants and new stories for various IP policies, simulating interactions within the accordion component. Included imports for expect, userEvent, waitFor, and within from "@storybook/test".
packages/storykit/src/components/IpWidget/__docs__/IpWidget.stories.tsx Added argTypes for ipId and isBottomNav in multiple stories. Modified userEvent.click to await userEvent.click and added additional user interactions. Updated story configurations for better simulation of navigation scenarios.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant IpPolicyAccordion
    participant IpWidget
    User->>IpPolicyAccordion: Selects IP policy
    IpPolicyAccordion->>IpWidget: Sends policy type
    IpWidget->>User: Updates UI based on policy type

    User->>IpWidget: Interacts with navigation
    IpWidget->>IpPolicyAccordion: Sends navigation state
    IpPolicyAccordion->>User: Updates UI based on navigation
Loading

Poem

In the land of code, where stories unfold,
Policies dance, new types to behold.
Accordions sing with a click and a cheer,
Widgets navigate, bringing joy near.
With constants and args, our tale's complete,
A harmonious update, oh so sweet! 🌟


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.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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

@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: 5

Outside diff range and nitpick comments (1)
packages/storykit/src/components/IpPolicyAccordion/__docs__/IpPolicyAccordion.stories.tsx (1)

7-11: Add comprehensive documentation for TERMS_TYPE.

The TERMS_TYPE constant is crucial for understanding the different policy types. Consider adding detailed comments explaining each type to enhance code readability and maintainability.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 356a3ba and d6b43ec.

Files selected for processing (2)
  • packages/storykit/src/components/IpPolicyAccordion/docs/IpPolicyAccordion.stories.tsx (2 hunks)
  • packages/storykit/src/components/IpWidget/docs/IpWidget.stories.tsx (7 hunks)
Additional comments not posted (5)
packages/storykit/src/components/IpWidget/__docs__/IpWidget.stories.tsx (3)

100-103: Consistency in asynchronous patterns is maintained.

The changes in BottomNavigation story maintain consistency with the TopNavigation story, ensuring uniform behavior across different navigation types.

Also applies to: 122-122


156-161: Validate the isBottomNav argument's impact.

#!/bin/bash
# Description: Verify the impact of `isBottomNav: true` on the `IpFoundOverview` story.

# Test: Search for the usage of `isBottomNav` in the story. Expect: Proper handling of the argument.
rg --type typescript $'isBottomNav: true' packages/storykit/src/components/IpWidget/__docs__/IpWidget.stories.tsx

181-186: Check for potential data inconsistencies.

#!/bin/bash
# Description: Verify the `ipId` consistency across stories.

# Test: Search for the usage of `ipId` in the story. Expect: Consistent `ipId` values across stories.
rg --type typescript $'ipId' packages/storykit/src/components/IpWidget/__docs__/IpWidget.stories.tsx
packages/storykit/src/components/IpPolicyAccordion/__docs__/IpPolicyAccordion.stories.tsx (2)

105-142: Validate the size parameter's impact in the IpOfCommercialUse story.

#!/bin/bash
# Description: Verify the impact of different `size` values on the `IpOfCommercialUse` story.

# Test: Search for the usage of `size` in the story. Expect: Proper handling and visible effects of different sizes.
rg --type typescript $'size' packages/storykit/src/components/IpPolicyAccordion/__docs__/IpPolicyAccordion.stories.tsx

145-182: Check for potential data inconsistencies in IpOfNonCommercialSocialRemixing.

#!/bin/bash
# Description: Verify the `ipId` consistency across stories in `IpPolicyAccordion`.

# Test: Search for the usage of `ipId` in the story. Expect: Consistent `ipId` values across stories.
rg --type typescript $'ipId' packages/storykit/src/components/IpPolicyAccordion/__docs__/IpPolicyAccordion.stories.tsx

Comment on lines +44 to +47
argTypes: {
ipId: { options: ["0x22Fe8C376919586F344fED952A9448df442b10f2"] },
isBottomNav: { control: false },
},
Copy link

Choose a reason for hiding this comment

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

Ensure asynchronous event handling is robust.

The use of await userEvent.click followed by await waitFor is correct, but consider adding error handling for potential exceptions during these asynchronous operations.

Also applies to: 66-66

Comment on lines +205 to +235
argTypes: {
ipId: { options: ["0x22Fe8C376919586F344fED952A9448df442b10f2"] },
},
args: {
ipId: "0x22Fe8C376919586F344fED952A9448df442b10f2",
isBottomNav: true,
},
play: async ({ canvasElement }) => {
const canvas = within(canvasElement)
await waitFor(
() => {
expect(canvas.getByText("11155111: Example NFT #4367")).toBeInTheDocument()
},
{ timeout: 10000 }
)

await userEvent.click(canvas.getByRole("button", { expanded: false }))
await waitFor(
() => {
expect(canvas.getByRole("menu").getAttribute("data-headlessui-state")).toBe("open")
},
{ timeout: 10000 }
)

await userEvent.click(canvas.getByRole("button", { expanded: true }))
await waitFor(
() => {
expect(canvas.queryByRole("menu")).toBeNull()
},
{ timeout: 10000 }
)
Copy link

Choose a reason for hiding this comment

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

Enhance user interaction handling in the MenuOpenAndClose story.

Consider adding more detailed comments or logs within the play function to better trace the sequence of user interactions and their effects, improving maintainability and debuggability.

Comment on lines +48 to +63
export const IpNoPolicy: Story = {
argTypes: {
ipId: {
options: ["0x0aEcA721aDceb65fbE81F450a1C59978fF903124"],
},
},
args: {
ipId: "0x0aEcA721aDceb65fbE81F450a1C59978fF903124",
size: "medium",
},
play: async ({ canvasElement }) => {
const canvas = within(canvasElement)
await waitFor(() => {
expect(canvas.getByText("No Policy")).toBeInTheDocument()
})
},
Copy link

Choose a reason for hiding this comment

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

Ensure robust error handling in the IpNoPolicy story.

The asynchronous operations in the play function lack error handling. Consider wrapping these operations in try-catch blocks to handle potential exceptions gracefully.

Comment on lines 65 to 102
export const IpOfCommercialRemix: Story = {
argTypes: {
ipId: {
options: ["0x9344852e16A4aCC2592FDeD4301eDcC58E8E0128"],
},
},
args: {
ipId: "0x9344852e16A4aCC2592FDeD4301eDcC58E8E0128",
size: "large",
},
play: async ({ canvasElement }) => {
const canvas = within(canvasElement)
await waitFor(
() => {
expect(canvas.getByText(TERMS_TYPE.COMMERCIAL_REMIX)).toBeInTheDocument()
},
{ timeout: 10000 }
)

await userEvent.click(canvas.getByText(TERMS_TYPE.COMMERCIAL_REMIX))
await waitFor(
() => {
expect(canvas.getByText(TERMS_TYPE.COMMERCIAL_REMIX).nextElementSibling?.classList).not.toContain(
"skIpPolicyAccordion__item-list--expanded"
)
},
{ timeout: 10000 }
)

await userEvent.click(canvas.getByText(TERMS_TYPE.COMMERCIAL_REMIX))
await waitFor(
() => {
expect(canvas.getByText(TERMS_TYPE.COMMERCIAL_REMIX).nextElementSibling?.classList).toContain(
"skIpPolicyAccordion__item-list--expanded"
)
},
{ timeout: 10000 }
)
Copy link

Choose a reason for hiding this comment

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

Optimize repeated code in the IpOfCommercialRemix story.

The repeated calls to userEvent.click and waitFor can be abstracted into a helper function to reduce code duplication and improve maintainability.

Comment on lines 185 to 247
export const IpOfMultiplePolicies: Story = {
argTypes: {
ipId: {
options: ["0x2CFc4F2F086cf9a859d87119dA0d54bB88173516"],
},
},
args: {
ipId: "0x2CFc4F2F086cf9a859d87119dA0d54bB88173516",
size: "medium",
},
play: async ({ canvasElement }) => {
const canvas = within(canvasElement)
await waitFor(
() => {
expect(canvas.getByText(TERMS_TYPE.COMMERCIAL_REMIX)).toBeInTheDocument()
expect(canvas.getByText(TERMS_TYPE.COMMERCIAL_USE)).toBeInTheDocument()
expect(canvas.getByText(TERMS_TYPE.NON_COMMERCIAL_SOCIAL_REMIXING)).toBeInTheDocument()
expect(canvas.getByText(TERMS_TYPE.COMMERCIAL_REMIX).nextElementSibling?.classList).toContain(
"skIpPolicyAccordion__item-list--expanded"
)
expect(canvas.getByText(TERMS_TYPE.COMMERCIAL_USE).nextElementSibling?.classList).not.toContain(
"skIpPolicyAccordion__item-list--expanded"
)
expect(canvas.getByText(TERMS_TYPE.NON_COMMERCIAL_SOCIAL_REMIXING).nextElementSibling?.classList).not.toContain(
"skIpPolicyAccordion__item-list--expanded"
)
},
{ timeout: 10000 }
)

await userEvent.click(canvas.getByText(TERMS_TYPE.NON_COMMERCIAL_SOCIAL_REMIXING))
await waitFor(
() => {
expect(canvas.getByText(TERMS_TYPE.NON_COMMERCIAL_SOCIAL_REMIXING).nextElementSibling?.classList).toContain(
"skIpPolicyAccordion__item-list--expanded"
)
expect(canvas.getByText(TERMS_TYPE.COMMERCIAL_REMIX).nextElementSibling?.classList).not.toContain(
"skIpPolicyAccordion__item-list--expanded"
)
},
{ timeout: 10000 }
)

await userEvent.click(canvas.getByText(TERMS_TYPE.NON_COMMERCIAL_SOCIAL_REMIXING))
await waitFor(
() => {
expect(canvas.getByText(TERMS_TYPE.NON_COMMERCIAL_SOCIAL_REMIXING).nextElementSibling?.classList).not.toContain(
"skIpPolicyAccordion__item-list--expanded"
)
},
{ timeout: 10000 }
)

await userEvent.click(canvas.getByText(TERMS_TYPE.COMMERCIAL_USE))
await waitFor(
() => {
expect(canvas.getByText(TERMS_TYPE.COMMERCIAL_USE).nextElementSibling?.classList).toContain(
"skIpPolicyAccordion__item-list--expanded"
)
},
{ timeout: 10000 }
)
},
Copy link

Choose a reason for hiding this comment

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

Enhance interaction handling in the IpOfMultiplePolicies story.

Consider adding more detailed comments or logs within the play function to better trace the sequence of user interactions and their effects, improving maintainability and debuggability.

Copy link
Collaborator

@allenchuang allenchuang left a comment

Choose a reason for hiding this comment

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

Please reuse the types defined other than that LGTM

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 d6b43ec and 23ada0a.

Files selected for processing (1)
  • packages/storykit/src/components/IpPolicyAccordion/docs/IpPolicyAccordion.stories.tsx (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • packages/storykit/src/components/IpPolicyAccordion/docs/IpPolicyAccordion.stories.tsx

Copy link
Collaborator

@allenchuang allenchuang left a comment

Choose a reason for hiding this comment

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

LGTM

@allenchuang allenchuang merged commit 30cd990 into main Jun 12, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants