@@ -2,9 +2,11 @@ import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
2
2
import { Formik } from "formik" ;
3
3
import { Elements } from "@stripe/react-stripe-js" ;
4
4
import { loadStripe } from "@stripe/stripe-js" ;
5
- import { fireEvent , render , screen } from "@testing-library/react" ;
6
- import { UAProduct } from "../../utils/test/Mocks" ;
5
+ import { fireEvent , render , screen , waitFor } from "@testing-library/react" ;
6
+ import { DistributorProduct , UAProduct } from "../../utils/test/Mocks" ;
7
7
import Taxes from "./Taxes" ;
8
+ import userEvent from "@testing-library/user-event" ;
9
+ import { UserSubscriptionMarketplace } from "advantage/api/enum" ;
8
10
9
11
describe ( "TaxesTests" , ( ) => {
10
12
let queryClient : QueryClient ;
@@ -14,6 +16,10 @@ describe("TaxesTests", () => {
14
16
queryClient = new QueryClient ( ) ;
15
17
} ) ;
16
18
19
+ afterEach ( ( ) => {
20
+ jest . clearAllMocks ( ) ;
21
+ } ) ;
22
+
17
23
it ( "renders country select correctly" , ( ) => {
18
24
const products = [
19
25
{
@@ -212,4 +218,96 @@ describe("TaxesTests", () => {
212
218
expect ( screen . getByTestId ( "country" ) ) . toHaveTextContent ( "United Kingdom" ) ;
213
219
expect ( screen . getByTestId ( "vat-number" ) ) . toHaveTextContent ( "GB123123123" ) ;
214
220
} ) ;
221
+
222
+ it ( "Edit should be available for pro users" , async ( ) => {
223
+ global . window = Object . create ( window ) ;
224
+ Object . defineProperty ( window , "accountId" , { value : "ABCDEF" } ) ;
225
+
226
+ const initialValues = {
227
+ country : "GB" ,
228
+ VATNumber : "GB123123123" ,
229
+ marketPlace : "canonical-ua" ,
230
+ } ;
231
+
232
+ const products = [
233
+ {
234
+ product : UAProduct ,
235
+ quantity : 1 ,
236
+ } ,
237
+ ] ;
238
+ render (
239
+ < QueryClientProvider client = { queryClient } >
240
+ < Formik initialValues = { initialValues } onSubmit = { jest . fn ( ) } >
241
+ < Elements stripe = { stripePromise } >
242
+ < Taxes products = { products } setError = { jest . fn ( ) } />
243
+ </ Elements >
244
+ </ Formik >
245
+ </ QueryClientProvider > ,
246
+ ) ;
247
+
248
+ expect ( screen . queryByRole ( "button" , { name : "Edit" } ) ) . toBeInTheDocument ( ) ;
249
+ userEvent . click ( screen . getByRole ( "button" , { name : "Edit" } ) ) ;
250
+ await waitFor ( ( ) => {
251
+ expect ( screen . getByTestId ( "select-country" ) ) . toBeInTheDocument ( ) ;
252
+ expect ( screen . getByTestId ( "field-vat-number" ) ) . toBeInTheDocument ( ) ;
253
+ expect ( screen . getByRole ( "button" , { name : "Save" } ) ) . toBeInTheDocument ( ) ;
254
+ } ) ;
255
+ } ) ;
256
+
257
+ it ( "Edit button should not be displayed for channel users" , ( ) => {
258
+ global . window = Object . create ( window ) ;
259
+ Object . defineProperty ( window , "accountId" , { value : "ABCDEF" } ) ;
260
+ const initialValues = {
261
+ country : "GB" ,
262
+ VATNumber : "GB123123123" ,
263
+ marketPlace : UserSubscriptionMarketplace . CanonicalProChannel ,
264
+ } ;
265
+ const products = [
266
+ {
267
+ product : DistributorProduct ,
268
+ quantity : 1 ,
269
+ } ,
270
+ ] ;
271
+ render (
272
+ < QueryClientProvider client = { queryClient } >
273
+ < Formik initialValues = { initialValues } onSubmit = { jest . fn ( ) } >
274
+ < Elements stripe = { stripePromise } >
275
+ < Taxes products = { products } setError = { jest . fn ( ) } />
276
+ </ Elements >
277
+ </ Formik >
278
+ </ QueryClientProvider > ,
279
+ ) ;
280
+
281
+ expect ( screen . queryByTestId ( "tax-edit-button" ) ) . toBeInTheDocument ( ) ;
282
+ } ) ;
283
+
284
+ it ( "New channel users should be able to add their tax info" , async ( ) => {
285
+ global . window = Object . create ( window ) ;
286
+ Object . defineProperty ( window , "accountId" , { value : "ABCDEF" } ) ;
287
+
288
+ const initialValues = {
289
+ country : "" ,
290
+ VATNumber : "" ,
291
+ marketPlace : UserSubscriptionMarketplace . CanonicalProChannel ,
292
+ } ;
293
+
294
+ const products = [
295
+ {
296
+ product : DistributorProduct ,
297
+ quantity : 1 ,
298
+ } ,
299
+ ] ;
300
+ render (
301
+ < QueryClientProvider client = { queryClient } >
302
+ < Formik initialValues = { initialValues } onSubmit = { jest . fn ( ) } >
303
+ < Elements stripe = { stripePromise } >
304
+ < Taxes products = { products } setError = { jest . fn ( ) } />
305
+ </ Elements >
306
+ </ Formik >
307
+ </ QueryClientProvider > ,
308
+ ) ;
309
+
310
+ expect ( screen . queryByTestId ( "tax-edit-button" ) ) . not . toBeInTheDocument ( ) ;
311
+ expect ( screen . getByRole ( "button" , { name : "Save" } ) ) . toBeInTheDocument ( ) ;
312
+ } ) ;
215
313
} ) ;
0 commit comments