1
+ import Form from "@/components/sections/feedbacks/Form"
2
+ import "@testing-library/jest-dom"
3
+ import { fireEvent , screen } from "@testing-library/react"
4
+ import { renderWithRedux } from "../../../../__mocks__/renderWithRedux" ;
5
+ import { mockUser } from "@__mocks__/fixtures/user" ;
6
+ import { colors } from "@__mocks__/fixtures/colors" ;
7
+ import { challenge , challengeSliceData } from "@__mocks__/fixtures/challenge" ;
8
+ jest . mock ( "next/router" , ( ) => ( {
9
+ useRouter : ( ) => ( {
10
+ push : jest . fn ( ) ,
11
+ isFallback : false ,
12
+ } ) ,
13
+ } ) ) ;
14
+ const handleSave = jest . fn ( )
15
+
16
+ const user = {
17
+ data : mockUser ,
18
+ userBalance : null ,
19
+ balance : null ,
20
+ walletAddresses : null ,
21
+ token : null ,
22
+ referrals : null ,
23
+ fetchingUserLoading : false ,
24
+ filteredUsers : null ,
25
+ }
26
+
27
+ const ui = {
28
+ colors, locked : false ,
29
+ showReferralPopup : false ,
30
+ showJobOffersPopup : false ,
31
+ }
32
+ const renderForm = ( ) => {
33
+ renderWithRedux ( < Form onSave = { handleSave } /> , { ui, user } )
34
+ }
35
+ describe ( 'FeedbackForm' , ( ) => {
36
+ it ( 'should render the feedback form' , ( ) => {
37
+ renderForm ( )
38
+ const form = screen . getByTestId ( 'feedback-form' )
39
+ expect ( form ) . toBeInTheDocument ( )
40
+ } )
41
+
42
+ it ( "should render the user avatar " , ( ) => {
43
+ renderForm ( )
44
+ const avatar = screen . getByTestId ( 'avatar' )
45
+ expect ( avatar ) . toBeInTheDocument ( )
46
+ } )
47
+
48
+ it ( 'should preserve the text case and format' , ( ) => {
49
+ renderForm ( )
50
+ const inputText = screen . getByTestId ( 'textarea' ) . getElementsByTagName ( "textarea" ) [ 0 ]
51
+ fireEvent . change ( inputText , { target : { value : 'Test input' } } )
52
+ expect ( inputText . value ) . toBe ( 'Test input' )
53
+ } )
54
+
55
+ it ( "should not show the github input link when the challenge does need one" , ( ) => {
56
+ renderWithRedux ( < Form onSave = { handleSave } /> , {
57
+ ui, user, challenges : {
58
+ ...challengeSliceData ,
59
+ current : {
60
+ ...challenge ,
61
+ format : {
62
+ githubLink : false ,
63
+ text : true ,
64
+ disclaimer : true ,
65
+ }
66
+ } ,
67
+ }
68
+ } )
69
+
70
+ const githubLinkInput = screen . queryByTestId ( "githubLinkInput" ) ;
71
+ expect ( githubLinkInput ) . not . toBeInTheDocument ( ) ;
72
+ } )
73
+
74
+ } )
0 commit comments