Skip to content

Commit ba55a49

Browse files
authored
Merge pull request #19 from storyprotocol/license-terms-test
Add tests for license terms
2 parents e3162eb + 49cef48 commit ba55a49

File tree

2 files changed

+147
-2
lines changed

2 files changed

+147
-2
lines changed

packages/storykit/src/components/LicenseTerms/LicenseTerms.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { CircleCheck, CircleMinus } from "lucide-react"
66
import "../../global.css"
77
import "./styles.css"
88

9-
const CANS = {
9+
export const CANS = {
1010
REMIX: "Remix this work",
1111
INCLUDE: "Include this work in their own work(s)",
1212
CREDIT: "Credit you appropriately",
@@ -36,7 +36,7 @@ const ShowCans = ({ type }: { type: string }) => {
3636
}
3737
}
3838

39-
const CANNOTS = {
39+
export const CANNOTS = {
4040
RESELL: "Resell your original work",
4141
COMMERCIALIZE: "Commercialize the remix",
4242
CLAIM_AS_ORIGINAL: "Claim credit for the remix (as original work)",

packages/storykit/src/components/LicenseTerms/__docs__/LicenseTerms.stories.tsx

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { POLICY_TYPE, PolicyType } from "@/types"
22
import type { Meta, StoryObj } from "@storybook/react"
3+
import { expect, waitFor } from "@storybook/test"
34

45
import Example from "../LicenseTerms"
6+
import { CANS, CANNOTS } from "../LicenseTerms"
57

68
const meta = {
79
title: "UI/LicenseTerms",
@@ -28,3 +30,146 @@ export const Select: Story = {
2830
direction: "column",
2931
},
3032
}
33+
34+
export const nonCommercialSocalRemixTerms: Story = {
35+
args: {
36+
type: POLICY_TYPE.NON_COMMERCIAL_SOCIAL_REMIXING as PolicyType,
37+
direction: "column",
38+
size: "small",
39+
},
40+
play: async ({ canvasElement }) => {
41+
const renderredListTitle = canvasElement.querySelectorAll(".skLicenseTerms__item-list-title")
42+
const renderredCanList = canvasElement.querySelectorAll(".skLicenseTerms__property--can")
43+
const renderredCannotList = canvasElement.querySelectorAll(".skLicenseTerms__property--cannot")
44+
45+
const canList = Array.from(renderredCanList).map((item) => item.textContent);
46+
const cannotList = Array.from(renderredCannotList).map((item) => item.textContent);
47+
48+
const expectCanList = [ CANS.REMIX, CANS.INCLUDE, CANS.CREDIT, CANS.DISTRIBUTE ]
49+
const expectCannotList = [ CANNOTS.RESELL, CANNOTS.COMMERCIALIZE, CANNOTS.CLAIM_AS_ORIGINAL ]
50+
51+
await waitFor(
52+
() => {
53+
expect(canvasElement.getElementsByClassName(".skLicenseTerms--column")).toBeTruthy()
54+
expect(renderredListTitle.length).toBe(2)
55+
expect(renderredListTitle[0].textContent).toBe("Others Can")
56+
expect(renderredListTitle[1].textContent).toBe("Others Cannot")
57+
expect(canList).toEqual(expectCanList)
58+
expect(cannotList).toEqual(expectCannotList)
59+
},
60+
)
61+
},
62+
}
63+
64+
export const commercialUseTerms: Story = {
65+
args: {
66+
type: POLICY_TYPE.COMMERCIAL_USE as PolicyType,
67+
direction: "row",
68+
size: "medium",
69+
},
70+
play: async ({ canvasElement }) => {
71+
const renderredListTitle = canvasElement.querySelectorAll(".skLicenseTerms__item-list-title")
72+
const renderredCanList = canvasElement.querySelectorAll(".skLicenseTerms__property--can")
73+
const renderredCannotList = canvasElement.querySelectorAll(".skLicenseTerms__property--cannot")
74+
75+
const canList = Array.from(renderredCanList).map((item) => item.textContent);
76+
const cannotList = Array.from(renderredCannotList).map((item) => item.textContent);
77+
78+
const expectCanList = [ CANS.PURCHASE_RIGHTS, CANS.CREATOR_CREDIT, CANS.PUBLISH ]
79+
const expectCannotList = [ CANNOTS.CLAIM, CANNOTS.REMIX, CANNOTS.RESELL ]
80+
81+
await waitFor(
82+
() => {
83+
expect(canvasElement.getElementsByClassName(".skLicenseTerms--row")).toBeTruthy()
84+
expect(renderredListTitle.length).toBe(2)
85+
expect(renderredListTitle[0].textContent).toBe("Others Can")
86+
expect(renderredListTitle[1].textContent).toBe("Others Cannot")
87+
expect(canList).toEqual(expectCanList)
88+
expect(cannotList).toEqual(expectCannotList)
89+
},
90+
)
91+
},
92+
}
93+
94+
export const commercialRemixTerms: Story = {
95+
args: {
96+
type: POLICY_TYPE.COMMERCIAL_REMIX as PolicyType,
97+
direction: "column",
98+
size: "large",
99+
},
100+
play: async ({ canvasElement }) => {
101+
const renderredListTitle = canvasElement.querySelectorAll(".skLicenseTerms__item-list-title")
102+
const renderredCanList = canvasElement.querySelectorAll(".skLicenseTerms__property--can")
103+
const renderredCannotList = canvasElement.querySelectorAll(".skLicenseTerms__property--cannot")
104+
105+
const canList = Array.from(renderredCanList).map((item) => item.textContent);
106+
const cannotList = Array.from(renderredCannotList).map((item) => item.textContent);
107+
108+
const expectCanList = [ CANS.REMIX, CANS.INCLUDE, CANS.CREDIT, CANS.DISTRIBUTE]
109+
const expectCannotList = [ CANNOTS.RESELL, CANNOTS.COMMERCIALIZE, CANNOTS.CLAIM_AS_ORIGINAL ]
110+
111+
await waitFor(
112+
() => {
113+
expect(canvasElement.getElementsByClassName(".skLicenseTerms--column")).toBeTruthy()
114+
expect(renderredListTitle.length).toBe(2)
115+
expect(renderredListTitle[0].textContent).toBe("Others Can")
116+
expect(renderredListTitle[1].textContent).toBe("Others Cannot")
117+
expect(canList).toEqual(expectCanList)
118+
expect(cannotList).toEqual(expectCannotList)
119+
},
120+
)
121+
},
122+
}
123+
124+
export const openDomainTerms: Story = {
125+
args: {
126+
type: POLICY_TYPE.OPEN_DOMAIN as PolicyType,
127+
direction: "row",
128+
},
129+
play: async ({ canvasElement }) => {
130+
const renderredListTitle = canvasElement.querySelectorAll(".skLicenseTerms__item-list-title")
131+
const renderredCanList = canvasElement.querySelectorAll(".skLicenseTerms__property--can")
132+
const renderredCannotList = canvasElement.querySelectorAll(".skLicenseTerms__property--cannot")
133+
134+
const canList = Array.from(renderredCanList).map((item) => item.textContent);
135+
const cannotList = Array.from(renderredCannotList).map((item) => item.textContent);
136+
137+
const expectCanList = [ CANS.REMIX, CANS.INCLUDE, CANS.DISTRIBUTE, CANS.PUBLISH ]
138+
const expectCannotList = [ CANNOTS.RESELL, CANNOTS.COMMERCIALIZE, CANNOTS.CLAIM_AS_ORIGINAL, CANNOTS.CLAIM ]
139+
140+
await waitFor(
141+
() => {
142+
expect(canvasElement.getElementsByClassName(".skLicenseTerms--row")).toBeTruthy()
143+
expect(renderredListTitle.length).toBe(2)
144+
expect(renderredListTitle[0].textContent).toBe("Others Can")
145+
expect(renderredListTitle[1].textContent).toBe("Others Cannot")
146+
expect(canList).toEqual(expectCanList)
147+
expect(cannotList).toEqual(expectCannotList)
148+
},
149+
)
150+
},
151+
}
152+
153+
export const noDerivativeTerms: Story = {
154+
args: {
155+
type: POLICY_TYPE.NO_DERIVATIVE as PolicyType,
156+
},
157+
play: async ({ canvasElement }) => {
158+
const renderredListTitle = canvasElement.querySelectorAll(".skLicenseTerms__item-list-title")
159+
const renderredCannotList = canvasElement.querySelectorAll(".skLicenseTerms__property--cannot")
160+
161+
const cannotList = Array.from(renderredCannotList).map((item) => item.textContent);
162+
163+
const expectCannotList = [ CANNOTS.RESELL, CANNOTS.CLAIM, CANNOTS.REMIX ]
164+
165+
await waitFor(
166+
() => {
167+
expect(canvasElement.getElementsByClassName(".skLicenseTerms--row")).toBeTruthy()
168+
expect(renderredListTitle.length).toBe(1)
169+
expect(renderredListTitle[0].textContent).toBe("Others Cannot")
170+
expect(cannotList).toEqual(expectCannotList)
171+
},
172+
)
173+
},
174+
}
175+

0 commit comments

Comments
 (0)