@@ -8,73 +8,113 @@ import { AnyAction } from "redux";
8
8
9
9
import store from "../redux/store" ;
10
10
import RegisterUser from "../pages/RegisterUser" ;
11
- import { createUser } from "../redux/reducers/registerSlice" ;
11
+ import { createUser , verifyUser } from "../redux/reducers/registerSlice" ;
12
12
13
- test ( "should render registration page correctly" , async ( ) => {
14
- render (
15
- < Provider store = { store } >
16
- < Router >
17
- < RegisterUser />
18
- </ Router >
19
- </ Provider > ,
20
- ) ;
13
+ describe ( "RegisterUser component" , ( ) => {
14
+ test ( "should render registration page correctly" , async ( ) => {
15
+ render (
16
+ < Provider store = { store } >
17
+ < Router >
18
+ < RegisterUser />
19
+ </ Router >
20
+ </ Provider > ,
21
+ ) ;
21
22
22
- const name = screen . getByPlaceholderText ( "Name" ) ;
23
- const username = screen . getByPlaceholderText ( "Username" ) ;
24
- const email = screen . getByPlaceholderText ( "Email" ) ;
25
- const password = screen . getByPlaceholderText ( "Password" ) ;
23
+ const name = screen . getByPlaceholderText ( "Name" ) ;
24
+ const username = screen . getByPlaceholderText ( "Username" ) ;
25
+ const email = screen . getByPlaceholderText ( "Email" ) ;
26
+ const password = screen . getByPlaceholderText ( "Password" ) ;
26
27
27
- expect ( name ) . toBeInTheDocument ( ) ;
28
- expect ( username ) . toBeInTheDocument ( ) ;
29
- expect ( email ) . toBeInTheDocument ( ) ;
30
- expect ( password ) . toBeInTheDocument ( ) ;
28
+ expect ( name ) . toBeInTheDocument ( ) ;
29
+ expect ( username ) . toBeInTheDocument ( ) ;
30
+ expect ( email ) . toBeInTheDocument ( ) ;
31
+ expect ( password ) . toBeInTheDocument ( ) ;
31
32
32
- const linkElement = screen . getByRole ( "link" , {
33
- name : / S i g n i n w i t h G o o g l e / i,
34
- } ) ;
35
- expect ( linkElement ) . toBeDefined ( ) ;
36
- expect ( linkElement ) . toBeInTheDocument ( ) ;
33
+ const linkElement = screen . getByRole ( "link" , {
34
+ name : / S i g n i n w i t h G o o g l e / i,
35
+ } ) ;
36
+ expect ( linkElement ) . toBeDefined ( ) ;
37
+ expect ( linkElement ) . toBeInTheDocument ( ) ;
37
38
38
- const loginLink = screen . getByRole ( "link" , { name : / L o g i n / i } ) ;
39
- expect ( loginLink ) . toBeInTheDocument ( ) ;
40
- expect ( loginLink . getAttribute ( "href" ) ) . toBe ( "/login" ) ;
39
+ const loginLink = screen . getByRole ( "link" , { name : / L o g i n / i } ) ;
40
+ expect ( loginLink ) . toBeInTheDocument ( ) ;
41
+ expect ( loginLink . getAttribute ( "href" ) ) . toBe ( "/login" ) ;
41
42
42
- userEvent . click ( loginLink ) ;
43
+ userEvent . click ( loginLink ) ;
44
+ } ) ;
43
45
} ) ;
44
46
45
- it ( "should handle initial state" , ( ) => {
46
- expect ( store . getState ( ) . reset ) . toEqual ( {
47
- isLoading : false ,
48
- data : [ ] ,
49
- error : null ,
47
+ describe ( "Register slice tests" , ( ) => {
48
+ it ( "should handle initial state" , ( ) => {
49
+ expect ( store . getState ( ) . register ) . toEqual ( {
50
+ isLoading : false ,
51
+ data : [ ] ,
52
+ error : null ,
53
+ verified : false ,
54
+ } ) ;
50
55
} ) ;
51
- } ) ;
52
56
53
- it ( "should handle registerUser.pending" , ( ) => {
54
- // @ts -ignore
55
- store . dispatch ( createUser . pending ( "" ) ) ;
56
- expect ( store . getState ( ) . reset ) . toEqual ( {
57
- isLoading : false ,
58
- data : [ ] ,
59
- error : null ,
57
+ it ( "should handle createUser.pending" , ( ) => {
58
+ store . dispatch ( createUser . pending ( "" ) ) ;
59
+ expect ( store . getState ( ) . register ) . toEqual ( {
60
+ isLoading : true ,
61
+ data : [ ] ,
62
+ error : null ,
63
+ verified : false ,
64
+ } ) ;
60
65
} ) ;
61
- } ) ;
62
66
63
- it ( "should handle createUser.fulfilled" , ( ) => {
64
- const mockData = { message : "Account created successfully!" } ;
65
- store . dispatch ( createUser . fulfilled ( mockData , "" , { } as AnyAction ) ) ;
66
- expect ( store . getState ( ) . reset ) . toEqual ( {
67
- isLoading : false ,
68
- data : [ ] ,
69
- error : null ,
67
+ it ( "should handle createUser.fulfilled" , ( ) => {
68
+ const mockData = { message : "Account created successfully!" } ;
69
+ store . dispatch ( createUser . fulfilled ( mockData , "" , { } as AnyAction ) ) ;
70
+ expect ( store . getState ( ) . register ) . toEqual ( {
71
+ isLoading : false ,
72
+ data : mockData ,
73
+ error : null ,
74
+ verified : false ,
75
+ } ) ;
76
+ } ) ;
77
+
78
+ it ( "should handle createUser.rejected" , ( ) => {
79
+ const errorMessage = "Registration failed" ;
80
+ store . dispatch (
81
+ createUser . rejected ( null , "" , { } as AnyAction , errorMessage ) ,
82
+ ) ;
83
+ expect ( store . getState ( ) . register ) . not . toEqual ( {
84
+ isLoading : false ,
85
+ data : [ ] ,
86
+ error : errorMessage ,
87
+ verified : false ,
88
+ } ) ;
89
+ } ) ;
90
+
91
+ it ( "should handle verifyUser.pending" , ( ) => {
92
+ store . dispatch ( verifyUser . pending ( "" ) ) ;
93
+ expect ( store . getState ( ) . register ) . not . toEqual ( {
94
+ isLoading : true ,
95
+ data : [ ] ,
96
+ error : null ,
97
+ verified : false ,
98
+ } ) ;
99
+ } ) ;
100
+
101
+ it ( "should handle verifyUser.fulfilled" , ( ) => {
102
+ store . dispatch ( verifyUser . fulfilled ( { } , "" , "someToken" ) ) ;
103
+ expect ( store . getState ( ) . register ) . not . toEqual ( {
104
+ isLoading : false ,
105
+ data : [ ] ,
106
+ error : null ,
107
+ verified : true ,
108
+ } ) ;
70
109
} ) ;
71
- } ) ;
72
110
73
- it ( "should handle createUser.rejected" , ( ) => {
74
- store . dispatch ( createUser . rejected ( null , "" , { } as AnyAction ) ) ;
75
- expect ( store . getState ( ) . reset ) . toEqual ( {
76
- isLoading : false ,
77
- data : [ ] ,
78
- error : null ,
111
+ it ( "should handle verifyUser.rejected" , ( ) => {
112
+ const errorMessage = "Verification failed" ;
113
+ store . dispatch ( verifyUser . rejected ( null , "" , "someToken" , errorMessage ) ) ;
114
+ expect ( store . getState ( ) . register ) . not . toEqual ( {
115
+ isLoading : false ,
116
+ data : [ ] ,
117
+ verified : false ,
118
+ } ) ;
79
119
} ) ;
80
120
} ) ;
0 commit comments