1+ import React from 'react' ;
2+ import { http , HttpResponse , delay } from 'msw' ;
3+ import { setupServer } from 'msw/node' ;
4+ import { screen , fireEvent } from '@testing-library/react' ;
5+ import userEvent from '@testing-library/user-event' ;
6+ import '@testing-library/jest-dom' ;
7+
8+ import { renderWithProviders } from 'utils/test-utils' ;
9+ import RegisterSection from './RegisterSection' ;
10+
11+ import type { Tier } from "store/slices/tiers.slice" ;
12+
13+ const server = setupServer (
14+ http . get ( '/ada-usd-price' , async ( ) => {
15+ await delay ( 150 ) ;
16+ return HttpResponse . json ( 10.0 ) ;
17+ } ) ,
18+ ) ;
19+
20+ const tier : Tier = {
21+ id : '1' ,
22+ name : 'Sample Tier' ,
23+ subtitle : 'Sample Tier' ,
24+ features : [ ] ,
25+ usdPrice : 100 ,
26+ enabled : true
27+ } ;
28+
29+ beforeAll ( ( ) => server . listen ( ) ) ;
30+ afterEach ( ( ) => server . resetHandlers ( ) ) ;
31+ afterAll ( ( ) => server . close ( ) ) ;
32+
33+ describe ( 'Landing page > Register section' , ( ) => {
34+
35+ test ( 'should render the register section' , async ( ) => {
36+
37+ renderWithProviders ( < RegisterSection tier = { tier } onSubmit = { ( ) => { } } /> ) ;
38+
39+ expect ( screen . queryByText ( 'Auditor profile' ) ) . toBeInTheDocument ( ) ;
40+
41+ } ) ;
42+
43+ test ( 'should render the subscription price correctly' , async ( ) => {
44+
45+ renderWithProviders ( < RegisterSection tier = { tier } onSubmit = { ( ) => { } } /> ) ;
46+
47+ const submitButton = await screen . findByText ( / 1 0 .0 0 / i) ;
48+
49+ expect ( submitButton ) . toBeInTheDocument ( ) ;
50+
51+ } ) ;
52+
53+ test ( 'should render disabled form if the fetched price is zero' , async ( ) => {
54+
55+ setupServer (
56+ http . get ( '/ada-usd-price' , async ( ) => {
57+ await delay ( 150 ) ;
58+ return HttpResponse . json ( 0.0 ) ;
59+ } ) ,
60+ ) ;
61+
62+ renderWithProviders ( < RegisterSection tier = { tier } onSubmit = { ( ) => { } } /> ) ;
63+
64+ const submitButton = await screen . findByText ( / 0 .0 0 / i) ;
65+
66+ expect ( submitButton ) . toBeDisabled ( ) ;
67+
68+ } ) ;
69+
70+ test ( 'should submit the form successfully' , async ( ) => {
71+
72+ const onSubmit = jest . fn ( ) ;
73+
74+ renderWithProviders ( < RegisterSection tier = { tier } onSubmit = { onSubmit } /> ) ;
75+
76+ const submitButton = await screen . findByText ( / 1 0 .0 0 / i) ;
77+
78+ const companyNameInput = screen . getByRole ( 'textbox' , { name : 'Company name *' } ) ;
79+ const contactEmailInput = screen . getByRole ( 'textbox' , { name : 'Contact email *' } ) ;
80+ const companyEmailInput = screen . getByRole ( 'textbox' , { name : 'Company Email *' } ) ;
81+ const fullNameInput = screen . getByRole ( 'textbox' , { name : 'Full name *' } ) ;
82+ const twitterInput = screen . getByRole ( 'textbox' , { name : 'Twitter' } ) ;
83+ const linkedinInput = screen . getByRole ( 'textbox' , { name : 'LinkedIn' } ) ;
84+ const websiteInput = screen . getByRole ( 'textbox' , { name : 'Website' } ) ;
85+
86+ fireEvent . change ( companyNameInput , { target : { value : 'Test company' } } ) ;
87+ fireEvent . change ( contactEmailInput , { target : { value : 'contact@test.com' } } ) ;
88+ fireEvent . change ( companyEmailInput , { target : { value : 'company@test.com' } } ) ;
89+ fireEvent . change ( fullNameInput , { target : { value : 'Full Name' } } ) ;
90+ fireEvent . change ( twitterInput , { target : { value : 'test' } } ) ;
91+ fireEvent . change ( linkedinInput , { target : { value : 'https://www.linkedin.com/profile/test' } } ) ;
92+ fireEvent . change ( websiteInput , { target : { value : 'https://www.test.com' } } ) ;
93+
94+ await userEvent . click ( submitButton ) ;
95+
96+ expect ( onSubmit . mock . calls ) . toHaveLength ( 1 ) ;
97+ expect ( onSubmit . mock . calls [ 0 ] [ 0 ] . companyName ) . toBe ( 'Test company' ) ;
98+ expect ( onSubmit . mock . calls [ 0 ] [ 0 ] . contactEmail ) . toBe ( 'contact@test.com' ) ;
99+ expect ( onSubmit . mock . calls [ 0 ] [ 0 ] . email ) . toBe ( 'company@test.com' ) ;
100+ expect ( onSubmit . mock . calls [ 0 ] [ 0 ] . fullName ) . toBe ( 'Full Name' ) ;
101+ expect ( onSubmit . mock . calls [ 0 ] [ 0 ] . twitter ) . toBe ( 'test' ) ;
102+ expect ( onSubmit . mock . calls [ 0 ] [ 0 ] . linkedin ) . toBe ( 'https://www.linkedin.com/profile/test' ) ;
103+ expect ( onSubmit . mock . calls [ 0 ] [ 0 ] . website ) . toBe ( 'https://www.test.com' ) ;
104+
105+ } ) ;
106+
107+ } ) ;
0 commit comments