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
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { PREVIEW_IP_ASSETS } from "@/stories/data"
import type { Meta, StoryObj } from "@storybook/react"
import { expect, userEvent, waitFor, within } from "@storybook/test"

import Example from "./Example"

const TERMS_TYPE = {
NON_COMMERCIAL_SOCIAL_REMIXING: "Non-Commercial Social Remixing",
COMMERCIAL_USE: "Commercial Use",
COMMERCIAL_REMIX: "Commercial Remix",
}

const meta = {
title: "IP Assets/IpPolicyAccordion",
component: Example,
Expand Down Expand Up @@ -38,3 +45,204 @@ export const Input: Story = {
size: "medium",
},
}
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()
})
},
Comment on lines +43 to +58
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.

}
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.

},
}
export const IpOfCommercialUse: Story = {
argTypes: {
ipId: {
options: ["0x86Fd9B1abbF0BeCBdA6F50e39dEfb5D4b50392D7"],
},
},
args: {
ipId: "0x86Fd9B1abbF0BeCBdA6F50e39dEfb5D4b50392D7",
size: "small",
},
play: async ({ canvasElement }) => {
const canvas = within(canvasElement)
await waitFor(
() => {
expect(canvas.getByText(TERMS_TYPE.COMMERCIAL_USE)).toBeInTheDocument()
},
{ timeout: 10000 }
)

await userEvent.click(canvas.getByText(TERMS_TYPE.COMMERCIAL_USE))
await waitFor(
() => {
expect(canvas.getByText(TERMS_TYPE.COMMERCIAL_USE).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 }
)
},
}
export const IpOfNonCommercialSocialRemixing: Story = {
argTypes: {
ipId: {
options: ["0x2cd96d28842e2445c6A1378A07F1FBD788Ee074F"],
},
},
args: {
ipId: "0x2cd96d28842e2445c6A1378A07F1FBD788Ee074F",
size: "large",
},
play: async ({ canvasElement }) => {
const canvas = within(canvasElement)
await waitFor(
() => {
expect(canvas.getByText(TERMS_TYPE.NON_COMMERCIAL_SOCIAL_REMIXING)).toBeInTheDocument()
},
{ 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.NON_COMMERCIAL_SOCIAL_REMIXING))
await waitFor(
() => {
expect(canvas.getByText(TERMS_TYPE.NON_COMMERCIAL_SOCIAL_REMIXING).nextElementSibling?.classList).toContain(
"skIpPolicyAccordion__item-list--expanded"
)
},
{ timeout: 10000 }
)
},
}
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.

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ export const Input: Story = {
},
}
export const TopNavigation: Story = {
argTypes: {
ipId: { options: ["0x22Fe8C376919586F344fED952A9448df442b10f2"] },
isBottomNav: { control: false },
},
Comment on lines +44 to +47
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

args: {
ipId: "0x22Fe8C376919586F344fED952A9448df442b10f2",
isBottomNav: false,
Expand All @@ -59,7 +63,7 @@ export const TopNavigation: Story = {
{ timeout: 10000 }
)

userEvent.click(canvas.getByText("Licensing"))
await userEvent.click(canvas.getByText("Licensing"))
await waitFor(
() => {
expect(canvas.getByText("Licensing").classList).not.toContain("skIpWidget__tab--active")
Expand Down Expand Up @@ -93,6 +97,10 @@ export const TopNavigation: Story = {
},
}
export const BottomNavigation: Story = {
argTypes: {
ipId: { options: ["0x22Fe8C376919586F344fED952A9448df442b10f2"] },
isBottomNav: { control: false },
},
args: {
ipId: "0x22Fe8C376919586F344fED952A9448df442b10f2",
isBottomNav: true,
Expand All @@ -111,7 +119,7 @@ export const BottomNavigation: Story = {
{ timeout: 10000 }
)

userEvent.click(canvas.getByText("Licensing"))
await userEvent.click(canvas.getByText("Licensing"))
await waitFor(
() => {
expect(canvas.getByText("Licensing").classList).not.toContain("skIpWidget__tab--active")
Expand Down Expand Up @@ -145,8 +153,12 @@ export const BottomNavigation: Story = {
},
}
export const IpFoundOverview: Story = {
argTypes: {
ipId: { options: ["0x22Fe8C376919586F344fED952A9448df442b10f2"] },
},
args: {
ipId: "0x22Fe8C376919586F344fED952A9448df442b10f2",
isBottomNav: true,
},
play: async ({ canvasElement }) => {
const canvas = within(canvasElement)
Expand All @@ -166,8 +178,12 @@ export const IpFoundOverview: Story = {
},
}
export const IpNotFoundOverview: Story = {
argTypes: {
ipId: { options: ["0x22Fe8C376919586F344fED952A9448df442b1999"] },
},
args: {
ipId: "0x22Fe8C376919586F344fED952A9448df442b1999",
isBottomNav: true,
},
play: async ({ canvasElement }) => {
const canvas = within(canvasElement)
Expand All @@ -181,5 +197,41 @@ export const IpNotFoundOverview: Story = {
},
{ timeout: 10000 }
)

await userEvent.click(canvas.getByRole("button", { expanded: false }))
},
}
export const MenuOpenAndClose: Story = {
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 }
)
Comment on lines +205 to +235
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.

},
}