1
1
import faker from 'faker' ;
2
2
3
3
describe ( 'Courses' , ( ) => {
4
- beforeEach ( ( ) => {
4
+ before ( ( ) => {
5
5
cy . task ( 'reset:db' ) ;
6
6
} ) ;
7
7
8
- it ( 'can create courses' , ( ) => {
8
+ beforeEach ( ( ) => {
9
9
cy . visit ( 'courses' ) ;
10
+ } ) ;
10
11
12
+ it ( 'can create courses' , ( ) => {
11
13
cy . contains ( 'Actualmente CodelyTV Pro cuenta con 0 cursos.' ) ;
12
14
13
15
let i = 0 ;
14
- while ( i <= 5 ) {
16
+ while ( i <= 3 ) {
15
17
i ++ ;
16
- const courseName = faker . lorem . sentence ( 2 ) ;
18
+ const courseName = faker . random . words ( 1 ) ;
17
19
cy . get ( 'input[name="name"]' ) . type ( courseName ) ;
18
20
cy . get ( 'input[name="duration"]' ) . type ( '8 days' ) ;
19
21
cy . get ( 'form' ) . submit ( ) ;
@@ -22,4 +24,109 @@ describe('Courses', () => {
22
24
cy . contains ( `Actualmente CodelyTV Pro cuenta con ${ i } cursos.` ) ;
23
25
}
24
26
} ) ;
27
+
28
+ describe ( 'Course id field' , ( ) => {
29
+ it ( 'has value by default' , ( ) => {
30
+ cy . get ( 'input[name="id"]' ) . invoke ( 'val' ) . should ( 'not.be.empty' ) ;
31
+ } ) ;
32
+
33
+ it ( 'has flash messages when is invalid' , ( ) => {
34
+ cy . get ( 'input[name="id"]' ) . clear ( ) . type ( 'invalid course id' ) ;
35
+ cy . get ( 'form' ) . submit ( ) ;
36
+
37
+ cy . get ( 'input[name="id"] + p' ) . contains ( 'Invalid course id' ) ;
38
+ } ) ;
39
+
40
+ it ( 'maintain the value introduced by the user when invalid' , ( ) => {
41
+ cy . get ( 'input[name="id"]' ) . clear ( ) . type ( 'invalid course id' ) ;
42
+ cy . get ( 'form' ) . submit ( ) ;
43
+
44
+ cy . get ( 'input[name="id"]' ) . should ( 'have.value' , 'invalid course id' ) ;
45
+ } ) ;
46
+
47
+ it ( 'maintain the value introduced by the user when valid' , ( ) => {
48
+ const uuid = faker . random . uuid ( ) ;
49
+
50
+ cy . get ( 'input[name="id"]' ) . clear ( ) . type ( uuid ) ;
51
+ cy . get ( 'form' ) . submit ( ) ;
52
+
53
+ cy . get ( 'input[name="id"]' ) . should ( 'have.value' , uuid ) ;
54
+ } ) ;
55
+ } ) ;
56
+
57
+ describe ( 'Name field' , ( ) => {
58
+ it ( 'has flash messages when is empty' , ( ) => {
59
+ cy . get ( 'form' ) . submit ( ) ;
60
+
61
+ cy . get ( 'input[name="name"] + p' ) . contains ( 'Invalid name' ) ;
62
+ } ) ;
63
+
64
+ it ( 'has flash messages when is longer than 30 character' , ( ) => {
65
+ cy . get ( 'input[name="name"]' ) . type ( faker . random . alphaNumeric ( 31 ) ) ;
66
+
67
+ cy . get ( 'form' ) . submit ( ) ;
68
+
69
+ cy . get ( 'input[name="name"] + p' ) . contains ( 'Invalid name' ) ;
70
+ } ) ;
71
+
72
+ it ( 'maintain the value introduced by the user when invalid' , ( ) => {
73
+ const invalidCourseName = faker . random . alphaNumeric ( 3 ) ;
74
+
75
+ cy . get ( 'input[name="name"]' ) . clear ( ) . type ( invalidCourseName ) ;
76
+ cy . get ( 'form' ) . submit ( ) ;
77
+
78
+ cy . get ( 'input[name="name"]' ) . should ( 'have.value' , invalidCourseName ) ;
79
+ } ) ;
80
+
81
+ it ( 'maintain the value introduced by the user when valid' , ( ) => {
82
+ const validCourseName = faker . random . alphaNumeric ( 1 ) ;
83
+
84
+ cy . get ( 'input[name="name"]' ) . clear ( ) . type ( validCourseName ) ;
85
+ cy . get ( 'form' ) . submit ( ) ;
86
+
87
+ cy . get ( 'input[name="name"]' ) . should ( 'have.value' , validCourseName ) ;
88
+ } ) ;
89
+ } ) ;
90
+
91
+ describe ( 'Duration field' , ( ) => {
92
+ it ( 'has flash messages when is empty' , ( ) => {
93
+ cy . get ( 'form' ) . submit ( ) ;
94
+
95
+ cy . get ( 'input[name="duration"] + p' ) . contains ( 'Invalid duration' ) ;
96
+ } ) ;
97
+
98
+ it ( 'has flash messages when is shorter than 4 character' , ( ) => {
99
+ cy . get ( 'input[name="duration"]' ) . type ( faker . random . alphaNumeric ( 3 ) ) ;
100
+
101
+ cy . get ( 'form' ) . submit ( ) ;
102
+
103
+ cy . get ( 'input[name="duration"] + p' ) . contains ( 'Invalid duration' ) ;
104
+ } ) ;
105
+
106
+ it ( 'has flash messages when is longer than 100 character' , ( ) => {
107
+ cy . get ( 'input[name="duration"]' ) . type ( faker . random . alphaNumeric ( 101 ) ) ;
108
+
109
+ cy . get ( 'form' ) . submit ( ) ;
110
+
111
+ cy . get ( 'input[name="duration"] + p' ) . contains ( 'Invalid duration' ) ;
112
+ } ) ;
113
+
114
+ it ( 'maintain the value introduced by the user when invalid' , ( ) => {
115
+ const invalidCourseDuration = faker . random . alphaNumeric ( 101 ) ;
116
+
117
+ cy . get ( 'input[name="duration"]' ) . clear ( ) . type ( invalidCourseDuration ) ;
118
+ cy . get ( 'form' ) . submit ( ) ;
119
+
120
+ cy . get ( 'input[name="duration"]' ) . should ( 'have.value' , invalidCourseDuration ) ;
121
+ } ) ;
122
+
123
+ it ( 'maintain the value introduced by the user when valid' , ( ) => {
124
+ const validCourseDuration = faker . random . alphaNumeric ( 5 ) ;
125
+
126
+ cy . get ( 'input[name="duration"]' ) . clear ( ) . type ( validCourseDuration ) ;
127
+ cy . get ( 'form' ) . submit ( ) ;
128
+
129
+ cy . get ( 'input[name="duration"]' ) . should ( 'have.value' , validCourseDuration ) ;
130
+ } ) ;
131
+ } ) ;
25
132
} ) ;
0 commit comments