1
1
import page from '../../pages/login' ;
2
2
3
+ const setupLoggedInServer = ( ) => {
4
+ cy . server ( ) ;
5
+ cy . route ( 'POST' , '/api/2.0/users/login' , 'fx:loginSuccess' ) . as ( 'login' ) ;
6
+ cy . route ( '/api/2.0/users/instance' , 'fx:parentLoggedIn' ) . as ( 'instance' ) ;
7
+ cy . route ( 'POST' , '/api/2.0/dojos/users' , 'fx:userDojosChampion' ) . as ( 'userDojosChampion' ) ;
8
+ } ;
9
+
3
10
describe ( 'Login Page' , ( ) => {
4
- it ( 'should show the header, login box , and all login box elements' , ( ) => {
5
- cy . visit ( '/login' ) ;
6
- cy . get ( page . header ) . should ( 'be.visible' ) ;
7
- cy . get ( page . loginBox ) . should ( 'be.visible' ) ;
8
- cy . get ( page . email ) . should ( 'be.visible' ) ;
9
- cy . get ( page . password ) . should ( 'be.visible' ) ;
10
- cy . get ( page . login ) . should ( 'be.visible' ) ;
11
- cy . get ( page . forgotPassword ) . should ( 'be.visible' ) ;
12
- cy . get ( page . register ) . should ( 'be.visible' ) ;
13
- cy . get ( page . forgotPasswordLink ) . should ( 'have.attr' , 'href' , '/reset' ) ;
14
- cy . get ( page . registerLink ) . should ( 'have.attr' , 'href' , '/register' ) ;
11
+ describe ( 'Form Validation' , ( ) => {
12
+ beforeEach ( ( ) => {
13
+ cy . visit ( '/login' ) ;
14
+ } ) ;
15
+
16
+ it ( 'should show the header, login box, and all login box elements' , ( ) => {
17
+ cy . get ( page . header ) . should ( 'be.visible' ) ;
18
+ cy . get ( page . loginBox ) . should ( 'be.visible' ) ;
19
+ cy . get ( page . email ) . should ( 'be.visible' ) ;
20
+ cy . get ( page . password ) . should ( 'be.visible' ) ;
21
+ cy . get ( page . login ) . should ( 'be.visible' ) ;
22
+ cy . get ( page . forgotPassword ) . should ( 'be.visible' ) ;
23
+ cy . get ( page . register ) . should ( 'be.visible' ) ;
24
+ cy . get ( page . forgotPasswordLink ) . should ( 'have.attr' , 'href' , '/reset' ) ;
25
+ cy . get ( page . registerLink ) . should ( 'have.attr' , 'href' , '/register' ) ;
26
+ } ) ;
27
+
28
+ it ( 'should show an error when no email is provided on a blur event' , ( ) => {
29
+ cy . get ( page . emailFormatError ) . should ( 'not.be.visible' ) ; // TODO: Should be emailReqError?
30
+ cy . get ( page . email ) . click ( ) ;
31
+ cy . get ( page . email ) . invoke ( 'text' ) . should ( 'eq' , '' ) ;
32
+ cy . get ( page . password ) . click ( ) ;
33
+ cy . get ( page . emailFormatError ) . should ( 'be.visible' ) ;
34
+ } ) ;
35
+
36
+ it ( 'should show an error when no password is provided on a blur event' , ( ) => {
37
+ cy . get ( page . passwordReqError ) . should ( 'not.be.visible' ) ;
38
+ cy . get ( page . password ) . click ( ) ;
39
+ cy . get ( page . password ) . invoke ( 'text' ) . should ( 'eq' , '' ) ;
40
+ cy . get ( page . loginBox ) . click ( ) ;
41
+ cy . get ( page . passwordReqError ) . should ( 'be.visible' ) ;
42
+ } ) ;
43
+
44
+ it ( 'should show an error when the email input is not in the correct format' , ( ) => {
45
+ cy . get ( page . emailFormatError ) . should ( 'not.be.visible' ) ;
46
+ cy . get ( page . email ) . click ( ) ;
47
+ cy . get ( page . email ) . type ( 'janedoe' ) ;
48
+ cy . get ( page . password ) . click ( ) ;
49
+ cy . get ( page . emailFormatError ) . should ( 'be.visible' ) ;
50
+ } ) ;
51
+
52
+ it ( 'should show an error when the login fails (on mock server this is only when the incorrect email is provided)' , ( ) => {
53
+ cy . server ( ) ;
54
+ cy . route ( 'POST' , '/api/2.0/users/login' , 'fx:loginFail' ) . as ( 'loginFail' ) ;
55
+ cy . get ( page . loginFailed ) . should ( 'not.be.visible' ) ;
56
+ cy . get ( page . email ) . click ( ) ;
57
+ cy . get ( page . email ) . type ( '[email protected] ' ) ;
58
+ cy . get ( page . password ) . type ( 'wrongpassword' ) ;
59
+ cy . get ( page . login ) . click ( ) ;
60
+ cy . wait ( '@loginFail' ) ;
61
+ cy . get ( page . loginFailed ) . should ( 'be.visible' ) ;
62
+ } ) ;
63
+
64
+ it ( 'should show both requirement errors when a login is attempted if no email and no password is provided' , ( ) => {
65
+ cy . get ( page . emailFormatError ) . should ( 'not.be.visible' ) ; // TODO: Should be emailReqError?
66
+ cy . get ( page . passwordReqError ) . should ( 'not.be.visible' ) ;
67
+ cy . get ( page . login ) . click ( ) ;
68
+ cy . get ( page . emailFormatError ) . should ( 'be.visible' ) ;
69
+ cy . get ( page . passwordReqError ) . should ( 'be.visible' ) ;
70
+ } ) ;
71
+
72
+ it ( 'should show only the email format error when a login is attempted if no password and incorrect form of email is provided' , ( ) => {
73
+ cy . get ( page . emailFormatError ) . should ( 'not.be.visible' ) ;
74
+ cy . get ( page . email ) . type ( 'janedoe' ) ;
75
+ cy . get ( page . login ) . click ( ) ;
76
+ cy . get ( page . emailFormatError ) . should ( 'be.visible' ) ;
77
+ } ) ;
78
+
79
+ it ( 'should show password requirement error when a login is attempted if no password but an email is provided' , ( ) => {
80
+ cy . get ( page . passwordReqError ) . should ( 'not.be.visible' ) ;
81
+ cy . get ( page . email ) . type ( '[email protected] ' ) ;
82
+ cy . get ( page . login ) . click ( ) ;
83
+ cy . get ( page . passwordReqError ) . should ( 'be.visible' ) ;
84
+ } ) ;
85
+
86
+ it ( 'should show email requirement error when a login is attempted if no email but a password is provided' , ( ) => {
87
+ cy . get ( page . emailFormatError ) . should ( 'not.be.visible' ) ; // TODO: Should be emailReqError?
88
+ cy . get ( page . password ) . type ( 'test123' ) ;
89
+ cy . get ( page . login ) . click ( ) ;
90
+ cy . get ( page . emailFormatError ) . should ( 'be.visible' ) ;
91
+ } ) ;
92
+ } ) ;
93
+
94
+ describe ( 'Successful Login' , ( ) => {
95
+ it ( 'should login successfully without a referrer query param' , ( ) => {
96
+ cy . visit ( '/login' ) ;
97
+ setupLoggedInServer ( ) ;
98
+ cy . get ( page . email ) . type ( '[email protected] ' ) ;
99
+ cy . get ( page . password ) . type ( 'testparent1' ) ;
100
+ cy . get ( page . login ) . click ( ) ;
101
+ cy . url ( ) . should ( 'include' , '/home' ) ;
102
+ } ) ;
103
+
104
+ it ( 'should login successfully with a referrer query param' , ( ) => {
105
+ cy . visit ( '/login?referrer=%2Fdashboard%2Ftickets' ) ;
106
+ setupLoggedInServer ( ) ;
107
+ cy . get ( page . email ) . type ( '[email protected] ' ) ;
108
+ cy . get ( page . password ) . type ( 'testparent1' ) ;
109
+ cy . get ( page . login ) . click ( ) ;
110
+ cy . url ( ) . should ( 'include' , '/dashboard/tickets' ) ;
111
+ } ) ;
15
112
} ) ;
16
- } )
113
+ } ) ;
0 commit comments