|
| 1 | +describe('Whatsapp Forms', () => { |
| 2 | + beforeEach(() => { |
| 3 | + cy.login(); |
| 4 | + |
| 5 | + // Mock API responses for create operation |
| 6 | + cy.intercept('POST', '**/api', (req) => { |
| 7 | + if (req.body.operationName === 'CreateWhatsappForm') { |
| 8 | + req.reply({ |
| 9 | + statusCode: 200, |
| 10 | + body: { |
| 11 | + data: { |
| 12 | + createWhatsappForm: { |
| 13 | + __typename: 'WhatsappFormResult', |
| 14 | + whatsappForm: { |
| 15 | + __typename: 'WhatsappForm', |
| 16 | + id: '2', |
| 17 | + name: req.body.variables.input.name, |
| 18 | + }, |
| 19 | + errors: null, |
| 20 | + }, |
| 21 | + }, |
| 22 | + }, |
| 23 | + }); |
| 24 | + } |
| 25 | + }).as('createWhatsappForm'); |
| 26 | + |
| 27 | + // Mock API responses for list operation |
| 28 | + cy.intercept('POST', '**/api', (req) => { |
| 29 | + if (req.body.operationName === 'listWhatsappForms') { |
| 30 | + req.reply({ |
| 31 | + statusCode: 200, |
| 32 | + body: { |
| 33 | + data: { |
| 34 | + listWhatsappForms: [ |
| 35 | + { |
| 36 | + __typename: 'WhatsappForm', |
| 37 | + id: '1', |
| 38 | + name: 'first form', |
| 39 | + description: 'first form description', |
| 40 | + status: 'DRAFT', |
| 41 | + categories: ['other'], |
| 42 | + }, |
| 43 | + { |
| 44 | + __typename: 'WhatsappForm', |
| 45 | + id: '2', |
| 46 | + name: 'second form', |
| 47 | + description: 'second form description', |
| 48 | + status: 'PUBLISHED', |
| 49 | + categories: ['lead_generation'], |
| 50 | + }, |
| 51 | + { |
| 52 | + __typename: 'WhatsappForm', |
| 53 | + id: '3', |
| 54 | + name: 'third form', |
| 55 | + description: 'third form description', |
| 56 | + status: 'INACTIVE', |
| 57 | + categories: ['lead_generation'], |
| 58 | + }, |
| 59 | + ], |
| 60 | + }, |
| 61 | + }, |
| 62 | + }); |
| 63 | + } |
| 64 | + }).as('listWhatsappForms'); |
| 65 | + |
| 66 | + // Mock API responses for get single form operation (for edit) |
| 67 | + cy.intercept('POST', '**/api', (req) => { |
| 68 | + if (req.body.operationName === 'WhatsappForm') { |
| 69 | + |
| 70 | + const formId = req.body.variables.id; |
| 71 | + const status = formId === '2' ? 'PUBLISHED' : 'DRAFT'; |
| 72 | + req.reply({ |
| 73 | + statusCode: 200, |
| 74 | + body: { |
| 75 | + data: { |
| 76 | + whatsappForm: { |
| 77 | + __typename: 'WhatsappFormResult', |
| 78 | + whatsappForm: { |
| 79 | + __typename: 'WhatsappForm', |
| 80 | + id: req.body.variables.id, |
| 81 | + name: 'first form', |
| 82 | + description: 'first form description', |
| 83 | + definition: |
| 84 | + '{"version":"7.2","screens":[{"title":"Page 1 of 2","layout":{"type":"SingleColumnLayout","children":[{"type":"Form","name":"flow_path","children":[{"type":"TextSubheading","text":"Sample form"}]}]}}]}', |
| 85 | + categories: ['survey'], |
| 86 | + status: status, |
| 87 | + metaFlowId: '869324785433064', |
| 88 | + insertedAt: '2025-11-21 10:59:02.415115Z', |
| 89 | + updatedAt: '2025-11-21 10:59:17.506001Z', |
| 90 | + }, |
| 91 | + }, |
| 92 | + }, |
| 93 | + }, |
| 94 | + }); |
| 95 | + } |
| 96 | + }).as('getWhatsappForm'); |
| 97 | + |
| 98 | + // Mock API responses for update operation |
| 99 | + cy.intercept('POST', '**/api', (req) => { |
| 100 | + if (req.body.operationName === 'UpdateWhatsappForm') { |
| 101 | + req.reply({ |
| 102 | + statusCode: 200, |
| 103 | + body: { |
| 104 | + data: { |
| 105 | + updateWhatsappForm: { |
| 106 | + __typename: 'WhatsappFormResult', |
| 107 | + whatsappForm: { |
| 108 | + __typename: 'WhatsappForm', |
| 109 | + id: req.body.variables.id || '2', |
| 110 | + name: req.body.variables.input.name, |
| 111 | + }, |
| 112 | + errors: null, |
| 113 | + }, |
| 114 | + }, |
| 115 | + }, |
| 116 | + }); |
| 117 | + } |
| 118 | + }).as('updateWhatsappForm'); |
| 119 | + |
| 120 | + // Mock API responses for delete, publish, deactivate, activate operations |
| 121 | + cy.intercept('POST', '**/api', (req) => { |
| 122 | + if (req.body.operationName === 'DeactivateWhatsappForm') { |
| 123 | + req.reply({ |
| 124 | + statusCode: 200, |
| 125 | + body: { |
| 126 | + data: { |
| 127 | + deactivateWhatsappForm: { |
| 128 | + __typename: 'WhatsappFormResult', |
| 129 | + whatsappForm: { |
| 130 | + __typename: 'WhatsappForm', |
| 131 | + id: req.body.variables.id, |
| 132 | + status: 'INACTIVE', |
| 133 | + }, |
| 134 | + errors: null, |
| 135 | + }, |
| 136 | + }, |
| 137 | + }, |
| 138 | + }); |
| 139 | + } |
| 140 | + }).as('deactivateWhatsappForm'); |
| 141 | + |
| 142 | + cy.intercept('POST', '**/api', (req) => { |
| 143 | + if (req.body.operationName === 'ActivateWhatsappForm') { |
| 144 | + req.reply({ |
| 145 | + statusCode: 200, |
| 146 | + body: { |
| 147 | + data: { |
| 148 | + activateWhatsappForm: { |
| 149 | + __typename: 'WhatsappFormResult', |
| 150 | + whatsappForm: { |
| 151 | + __typename: 'WhatsappForm', |
| 152 | + id: req.body.variables.activateWhatsappFormId, |
| 153 | + status: 'DRAFT', |
| 154 | + }, |
| 155 | + errors: null, |
| 156 | + }, |
| 157 | + }, |
| 158 | + }, |
| 159 | + }); |
| 160 | + } |
| 161 | + }).as('activateWhatsappForm'); |
| 162 | + |
| 163 | + cy.intercept('POST', '**/api', (req) => { |
| 164 | + if (req.body.operationName === 'PublishWhatsappForm') { |
| 165 | + req.reply({ |
| 166 | + statusCode: 200, |
| 167 | + body: { |
| 168 | + data: { |
| 169 | + publishWhatsappForm: { |
| 170 | + __typename: 'WhatsappFormResult', |
| 171 | + whatsappForm: { |
| 172 | + __typename: 'WhatsappForm', |
| 173 | + id: req.body.variables.id, |
| 174 | + status: 'PUBLISHED', |
| 175 | + }, |
| 176 | + errors: null, |
| 177 | + }, |
| 178 | + }, |
| 179 | + }, |
| 180 | + }); |
| 181 | + } |
| 182 | + }).as('publishWhatsappForm'); |
| 183 | + |
| 184 | + cy.intercept('POST', '**/api', (req) => { |
| 185 | + if (req.body.operationName === 'DeleteWhatsappForm') { |
| 186 | + req.reply({ |
| 187 | + statusCode: 200, |
| 188 | + body: { |
| 189 | + data: { |
| 190 | + deleteWhatsappForm: { |
| 191 | + __typename: 'WhatsappFormResult', |
| 192 | + whatsappForm: { |
| 193 | + __typename: 'WhatsappForm', |
| 194 | + id: req.body.variables.id, |
| 195 | + }, |
| 196 | + errors: null, |
| 197 | + }, |
| 198 | + }, |
| 199 | + }, |
| 200 | + }); |
| 201 | + } |
| 202 | + }).as('deleteWhatsappForm'); |
| 203 | + |
| 204 | + cy.visit('/whatsapp-forms'); |
| 205 | + cy.wait('@listWhatsappForms'); |
| 206 | + }); |
| 207 | + |
| 208 | + it('it should open the Whatsapp Forms page', () => { |
| 209 | + cy.get('[data-testid="listHeader"]').should('contain', 'WhatsApp Forms'); |
| 210 | + }); |
| 211 | + |
| 212 | + it('should show all validation errors while creating a form', () => { |
| 213 | + cy.get('[data-testid="newItemButton"]').click(); |
| 214 | + |
| 215 | + cy.get('[data-testid="submitActionButton"]').click({ force: true }); |
| 216 | + |
| 217 | + cy.get('p').should('contain', 'Title is required'); |
| 218 | + cy.get('p').should('contain', 'Form JSON is required'); |
| 219 | + |
| 220 | + cy.get('input[name=name]').first().type('Test Form'); |
| 221 | + |
| 222 | + cy.get('textarea[name=formJson]').first().type('Invalid JSON'); |
| 223 | + |
| 224 | + cy.get('[data-testid="submitActionButton"]').click({ force: true }); |
| 225 | + |
| 226 | + cy.get('p').should('contain', 'Must be valid JSON'); |
| 227 | + |
| 228 | + cy.get('[data-testid="cancelActionButton"]').click(); |
| 229 | + }); |
| 230 | + |
| 231 | + it('should create a new Whatsapp Form', () => { |
| 232 | + const formJson = { |
| 233 | + type: 'form', |
| 234 | + title: 'Sample Form', |
| 235 | + fields: [ |
| 236 | + { type: 'text', label: 'Name' }, |
| 237 | + { type: 'email', label: 'Email' }, |
| 238 | + ], |
| 239 | + }; |
| 240 | + cy.get('[data-testid="newItemButton"]').click(); |
| 241 | + |
| 242 | + cy.get('input[name=name]').first().type('Title for Whatsapp Form'); |
| 243 | + cy.get('textarea[name=description]').first().type('This is a description for Whatsapp Form.\n'); |
| 244 | + cy.get('textarea[name=formJson]') |
| 245 | + .first() |
| 246 | + .type(JSON.stringify(formJson), { parseSpecialCharSequences: false }); |
| 247 | + |
| 248 | + cy.get('[data-testid="AutocompleteInput"]').eq(0).click().wait(500); |
| 249 | + cy.get('.MuiAutocomplete-option').eq(0).click().wait(500); |
| 250 | + |
| 251 | + cy.get('[data-testid="submitActionButton"]').click({ force: true }); |
| 252 | + |
| 253 | + cy.wait('@createWhatsappForm'); |
| 254 | + |
| 255 | + cy.get('div').should('contain', 'Whatsapp Form created successfully!'); |
| 256 | + }); |
| 257 | + |
| 258 | + it('should edit an existing Whatsapp Form', () => { |
| 259 | + cy.get('[data-testid="EditIcon"]').first().click(); |
| 260 | + |
| 261 | + cy.wait('@getWhatsappForm'); |
| 262 | + |
| 263 | + cy.get('input[name=name]').first().clear().type('Updated Title for Whatsapp Form'); |
| 264 | + cy.get('textarea[name=description]') |
| 265 | + .first() |
| 266 | + .clear() |
| 267 | + .type('This is an updated description for Whatsapp Form.\n'); |
| 268 | + |
| 269 | + cy.get('[data-testid="submitActionButton"]').click({ force: true }); |
| 270 | + |
| 271 | + cy.wait('@updateWhatsappForm'); |
| 272 | + |
| 273 | + cy.get('div').should('contain', 'Whatsapp Form edited successfully!'); |
| 274 | + }); |
| 275 | + |
| 276 | + it('published flows should be read-only', () => { |
| 277 | + cy.get('[data-testid="EditIcon"]').eq(1).click(); |
| 278 | + cy.wait('@getWhatsappForm'); |
| 279 | + |
| 280 | + cy.get('input[name=name]').should('be.disabled'); |
| 281 | + |
| 282 | + cy.get('[data-testid="cancelActionButton"]').click(); |
| 283 | + }); |
| 284 | + |
| 285 | + it('should publish a Whatsapp Form', () => { |
| 286 | + cy.get('[data-testid="additionalButton"]').first().click(); |
| 287 | + |
| 288 | + cy.get('[data-testid="ok-button"]').click({ force: true }); |
| 289 | + cy.wait('@publishWhatsappForm'); |
| 290 | + |
| 291 | + |
| 292 | + cy.get('div').should('contain', 'Form published successfully'); |
| 293 | + }); |
| 294 | + |
| 295 | + it('should make a form inactive', () => { |
| 296 | + cy.get('[data-testid="MoreIcon"]').eq(1).click(); |
| 297 | + cy.contains('Deactivate').click(); |
| 298 | + cy.wait('@deactivateWhatsappForm'); |
| 299 | + |
| 300 | + cy.get('[data-testid="ok-button"]').click({ force: true }); |
| 301 | + |
| 302 | + cy.get('div').should('contain', 'Form deactivated successfully'); |
| 303 | + }); |
| 304 | + |
| 305 | + it('should make a form active', () => { |
| 306 | + cy.get('[data-testid="MoreIcon"]').eq(2).click(); |
| 307 | + cy.contains('Activate').click(); |
| 308 | + cy.wait('@activateWhatsappForm'); |
| 309 | + |
| 310 | + cy.get('div').should('contain', 'Form activated successfully'); |
| 311 | + }); |
| 312 | + |
| 313 | + it('should delete a Whatsapp Form', () => { |
| 314 | + cy.get('[data-testid="MoreIcon"]').first().click(); |
| 315 | + cy.contains('Delete').click(); |
| 316 | + cy.wait('@deleteWhatsappForm'); |
| 317 | + |
| 318 | + cy.get('[data-testid="ok-button"]').click({ force: true }); |
| 319 | + |
| 320 | + cy.get('div').should('contain', 'Form deleted successfully'); |
| 321 | + }); |
| 322 | +}); |
0 commit comments