@@ -21,23 +21,20 @@ describe('Device users page - Add new device user', function () {
2121 it ( 'should add new device user with first name and last name' , ( ) => {
2222 const surname = generateRandmString ( ) ;
2323
24- // Ensure table is visible before counting rows
25- cy . get ( 'tbody > tr' , { timeout : 10000 } ) . should ( 'have.length.gt' , 0 ) ;
26-
2724 deviceUsersPage . rowNum ( ) . then ( ( rowCountBeforeCreation ) => {
2825 countDeviceUsersBeforeCreating = rowCountBeforeCreation ;
2926
3027 // Create new device user
3128 cy . get ( '#newDeviceUserBtn' ) . should ( 'be.visible' ) . click ( ) ;
3229 cy . get ( '#firstName' ) . should ( 'be.visible' ) . type ( nameDeviceUser ) ;
3330 cy . get ( '#lastName' ) . should ( 'be.visible' ) . type ( surname ) ;
34-
35- cy . intercept ( 'POST ' , '**/api/device-users/create' ) . as ( 'createUser' ) ;
31+
32+ cy . intercept ( 'PUT ' , '**/api/device-users/create' ) . as ( 'createUser' ) ;
3633 cy . intercept ( 'POST' , '**/api/device-users/index' ) . as ( 'reloadDeviceUsers' ) ;
3734 cy . get ( '#saveCreateBtn' ) . should ( 'be.visible' ) . should ( 'be.enabled' ) . click ( ) ;
3835 cy . wait ( '@createUser' , { timeout : 30000 } ) ;
3936 cy . wait ( '@reloadDeviceUsers' , { timeout : 30000 } ) ;
40- cy . get ( '#newDeviceUserBtn' ) . should ( 'be.visible' ) ;
37+ cy . get ( '#newDeviceUserBtn' , { timeout : 40000 } ) . should ( 'be.visible' ) ;
4138
4239 // Verify the user was created
4340 deviceUsersPage . rowNum ( ) . then ( ( rowCountAfterCreation ) => {
@@ -55,7 +52,7 @@ describe('Device users page - Add new device user', function () {
5552} ) ;
5653
5754describe ( 'Device users page - Should not add new device user' , function ( ) {
58- before ( ( ) => {
55+ beforeEach ( ( ) => {
5956 cy . visit ( 'http://localhost:4200' ) ;
6057 loginPage . login ( ) ;
6158 cy . intercept ( 'POST' , '**/api/device-users/index' ) . as ( 'loadDeviceUsers' ) ;
@@ -67,8 +64,10 @@ describe('Device users page - Should not add new device user', function () {
6764 it ( 'should NOT add device user with only first name' , ( ) => {
6865 const name = generateRandmString ( ) ;
6966
70- cy . get ( '#newDeviceUserBtn' ) . should ( 'be.visible' ) . click ( ) ;
67+ cy . get ( '#newDeviceUserBtn' , { timeout : 40000 } ) . should ( 'be.visible' ) . click ( ) ;
68+ cy . wait ( 500 ) ;
7169 cy . get ( '#firstName' ) . should ( 'be.visible' ) . type ( name ) ;
70+ cy . get ( '#lastName' ) . should ( 'be.visible' ) . type ( '' ) ;
7271
7372 // Verify save button is disabled
7473 cy . get ( '#saveCreateBtn' ) . should ( 'be.disabled' ) ;
@@ -80,38 +79,38 @@ describe('Device users page - Should not add new device user', function () {
8079 it ( 'should NOT add device user with only last name' , ( ) => {
8180 const lastName = generateRandmString ( ) ;
8281
83- cy . get ( '#newDeviceUserBtn' , { timeout : 10000 } ) . should ( 'be.visible' ) . click ( ) ;
82+ cy . get ( '#newDeviceUserBtn' , { timeout : 40000 } ) . should ( 'be.visible' ) . click ( ) ;
83+ cy . wait ( 500 ) ;
84+ cy . get ( '#firstName' ) . should ( 'be.visible' ) . type ( '' ) ;
8485 cy . get ( '#lastName' ) . should ( 'be.visible' ) . type ( lastName ) ;
8586
8687 // Verify save button is disabled
8788 cy . get ( '#saveCreateBtn' ) . should ( 'be.disabled' ) ;
8889
8990 cy . get ( '#cancelCreateBtn' ) . should ( 'be.visible' ) . click ( ) ;
90- cy . get ( '#newDeviceUserBtn' , { timeout : 10000 } ) . should ( 'be.visible' ) ;
91+ cy . wait ( 500 ) ;
9192 } ) ;
9293
9394 it ( 'should NOT add device user without first and last names' , ( ) => {
94- cy . get ( '#newDeviceUserBtn' , { timeout : 10000 } ) . should ( 'be.visible' ) . click ( ) ;
95- cy . get ( '#firstName' ) . should ( 'be.visible' ) ;
95+ cy . get ( '#newDeviceUserBtn' , { timeout : 40000 } ) . should ( 'be.visible' ) . click ( ) ;
96+ cy . wait ( 500 ) ;
97+ cy . get ( '#firstName' ) . should ( 'be.visible' ) . type ( '' ) ;
98+ cy . get ( '#lastName' ) . should ( 'be.visible' ) . type ( '' ) ;
9699
97100 // Verify save button is disabled
98101 cy . get ( '#saveCreateBtn' ) . should ( 'be.disabled' ) ;
99102
100103 cy . get ( '#cancelCreateBtn' ) . should ( 'be.visible' ) . click ( ) ;
101- cy . get ( '#newDeviceUserBtn' , { timeout : 10000 } ) . should ( 'be.visible' ) ;
102104 cy . wait ( 500 ) ;
103105 } ) ;
104106
105107 it ( 'should NOT create user if cancel was clicked' , ( ) => {
106- // Ensure table is visible before counting rows
107- cy . get ( 'tbody > tr' , { timeout : 10000 } ) . should ( 'have.length.gt' , 0 ) ;
108-
109108 deviceUsersPage . rowNum ( ) . then ( ( rowCountBeforeCreation ) => {
110- cy . get ( '#newDeviceUserBtn' , { timeout : 10000 } ) . should ( 'be.visible' ) . click ( ) ;
111- cy . get ( '#firstName' ) . should ( 'be.visible' ) ;
109+ cy . get ( '#newDeviceUserBtn' , { timeout : 40000 } ) . should ( 'be.visible' ) . click ( ) ;
112110 cy . wait ( 500 ) ;
111+ cy . get ( '#firstName' ) . should ( 'be.visible' ) ;
113112 cy . get ( '#cancelCreateBtn' ) . should ( 'be.visible' ) . click ( ) ;
114- cy . get ( '#newDeviceUserBtn' , { timeout : 10000 } ) . should ( 'be.visible' ) ;
113+ cy . get ( '#newDeviceUserBtn' , { timeout : 40000 } ) . should ( 'be.visible' ) ;
115114 cy . wait ( 500 ) ;
116115
117116 deviceUsersPage . rowNum ( ) . then ( ( rowCountAfterCreation ) => {
@@ -124,26 +123,21 @@ describe('Device users page - Should not add new device user', function () {
124123 } ) ;
125124
126125 it ( 'should clean up created test data' , ( ) => {
127- // Ensure table is visible before finding user
128- cy . get ( 'tbody > tr' , { timeout : 10000 } ) . should ( 'have.length.gt' , 0 ) ;
129-
130126 // Find and delete the test user
131127 cy . get ( '#deviceUserFirstName' ) . each ( ( $el , index ) => {
132128 if ( $el . text ( ) === nameDeviceUser ) {
133- cy . intercept ( 'POST ' , '**/api/device-users/delete' ) . as ( 'deleteUser' ) ;
129+ cy . intercept ( 'DELETE ' , '**/api/device-users/delete/* ' ) . as ( 'deleteUser' ) ;
134130 cy . intercept ( 'POST' , '**/api/device-users/index' ) . as ( 'reloadDeviceUsers' ) ;
135131 cy . get ( '#deleteDeviceUserBtn' ) . eq ( index ) . click ( ) ;
132+ cy . wait ( 500 ) ;
136133 cy . get ( '#saveDeleteBtn' ) . should ( 'be.visible' ) . click ( ) ;
137134 cy . wait ( '@deleteUser' , { timeout : 30000 } ) ;
138135 cy . wait ( '@reloadDeviceUsers' , { timeout : 30000 } ) ;
139- cy . get ( '#newDeviceUserBtn' , { timeout : 10000 } ) . should ( 'be.visible' ) ;
136+ cy . get ( '#newDeviceUserBtn' , { timeout : 40000 } ) . should ( 'be.visible' ) ;
140137 return false ; // break the loop
141138 }
142139 } ) ;
143140
144- // Ensure table is visible before counting rows
145- cy . get ( 'tbody > tr' , { timeout : 10000 } ) . should ( 'have.length.gt' , 0 ) ;
146-
147141 // Verify count is back to original
148142 deviceUsersPage . rowNum ( ) . then ( ( currentCount ) => {
149143 expect ( currentCount ) . to . equal ( countDeviceUsersBeforeCreating ) ;
0 commit comments