1
1
import { POLICY_TYPE , PolicyType } from "@/types"
2
2
import type { Meta , StoryObj } from "@storybook/react"
3
+ import { expect , waitFor } from "@storybook/test"
3
4
4
5
import Example from "../LicenseTerms"
6
+ import { CANS , CANNOTS } from "../LicenseTerms"
5
7
6
8
const meta = {
7
9
title : "UI/LicenseTerms" ,
@@ -28,3 +30,146 @@ export const Select: Story = {
28
30
direction : "column" ,
29
31
} ,
30
32
}
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