Skip to content

Commit

Permalink
Merge pull request #18 from storyprotocol/add-ip-policy-test
Browse files Browse the repository at this point in the history
Add ipPolicy and ipWidget tests
  • Loading branch information
allenchuang authored Jun 12, 2024
2 parents ba55a49 + 23ada0a commit 30cd990
Show file tree
Hide file tree
Showing 2 changed files with 257 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { PREVIEW_IP_ASSETS } from "@/stories/data"
import { POLICY_TYPE } from "@/types/assets"
import type { Meta, StoryObj } from "@storybook/react"
import { expect, userEvent, waitFor, within } from "@storybook/test"

import Example from "./Example"

Expand Down Expand Up @@ -38,3 +40,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()
})
},
}
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(POLICY_TYPE.COMMERCIAL_REMIX)).toBeInTheDocument()
},
{ timeout: 10000 }
)

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

await userEvent.click(canvas.getByText(POLICY_TYPE.COMMERCIAL_REMIX))
await waitFor(
() => {
expect(canvas.getByText(POLICY_TYPE.COMMERCIAL_REMIX).nextElementSibling?.classList).toContain(
"skIpPolicyAccordion__item-list--expanded"
)
},
{ timeout: 10000 }
)
},
}
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(POLICY_TYPE.COMMERCIAL_USE)).toBeInTheDocument()
},
{ timeout: 10000 }
)

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

await userEvent.click(canvas.getByText(POLICY_TYPE.COMMERCIAL_USE))
await waitFor(
() => {
expect(canvas.getByText(POLICY_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(POLICY_TYPE.NON_COMMERCIAL_SOCIAL_REMIXING)).toBeInTheDocument()
},
{ timeout: 10000 }
)

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

await userEvent.click(canvas.getByText(POLICY_TYPE.NON_COMMERCIAL_SOCIAL_REMIXING))
await waitFor(
() => {
expect(canvas.getByText(POLICY_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(POLICY_TYPE.COMMERCIAL_REMIX)).toBeInTheDocument()
expect(canvas.getByText(POLICY_TYPE.COMMERCIAL_USE)).toBeInTheDocument()
expect(canvas.getByText(POLICY_TYPE.NON_COMMERCIAL_SOCIAL_REMIXING)).toBeInTheDocument()
expect(canvas.getByText(POLICY_TYPE.COMMERCIAL_REMIX).nextElementSibling?.classList).toContain(
"skIpPolicyAccordion__item-list--expanded"
)
expect(canvas.getByText(POLICY_TYPE.COMMERCIAL_USE).nextElementSibling?.classList).not.toContain(
"skIpPolicyAccordion__item-list--expanded"
)
expect(
canvas.getByText(POLICY_TYPE.NON_COMMERCIAL_SOCIAL_REMIXING).nextElementSibling?.classList
).not.toContain("skIpPolicyAccordion__item-list--expanded")
},
{ timeout: 10000 }
)

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

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

await userEvent.click(canvas.getByText(POLICY_TYPE.COMMERCIAL_USE))
await waitFor(
() => {
expect(canvas.getByText(POLICY_TYPE.COMMERCIAL_USE).nextElementSibling?.classList).toContain(
"skIpPolicyAccordion__item-list--expanded"
)
},
{ timeout: 10000 }
)
},
}
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 },
},
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 }
)
},
}

0 comments on commit 30cd990

Please sign in to comment.