|
| 1 | +/// <reference types="cypress" /> |
| 2 | +/* eslint-disable no-undef */ |
| 3 | + |
| 4 | +const dismissAlerts = () => { |
| 5 | + // Remove all scheduling conflict alert banners from DOM directly |
| 6 | + cy.window().then((win) => { |
| 7 | + win.document.querySelectorAll('[role="alert"]').forEach((alert) => { |
| 8 | + alert.remove(); |
| 9 | + }); |
| 10 | + }); |
| 11 | +}; |
| 12 | + |
| 13 | +const openCreateTaskModal = () => { |
| 14 | + dismissAlerts(); |
| 15 | + cy.contains('button', 'New Event').click({ force: true }); |
| 16 | + cy.get('[role="dialog"]', { timeout: 10000 }).should('exist'); |
| 17 | + cy.get('[role="dialog"]').contains('button', 'Create Task').click({ force: true }); |
| 18 | + cy.get('[role="dialog"]').find('h2').should('contain', 'Create Task'); |
| 19 | +}; |
| 20 | + |
| 21 | +describe('Create Task', () => { |
| 22 | + beforeEach(() => { |
| 23 | + cy.login('Thomas Emrax', '/calendar'); |
| 24 | + }); |
| 25 | + |
| 26 | + it('Can Open Create Task Modal from Calendar', () => { |
| 27 | + openCreateTaskModal(); |
| 28 | + |
| 29 | + // Verify the Create Task modal is open with expected fields |
| 30 | + cy.get('[role="dialog"]').contains('Project').should('exist'); |
| 31 | + cy.get('[role="dialog"]').contains('Title').should('exist'); |
| 32 | + cy.get('[role="dialog"]').contains('Priority').should('exist'); |
| 33 | + cy.get('[role="dialog"]').contains('Status').should('exist'); |
| 34 | + }); |
| 35 | + |
| 36 | + it('Creating a Task Writes to DB and Appears on Calendar', () => { |
| 37 | + const taskTitle = 'E2E Test Task'; |
| 38 | + |
| 39 | + openCreateTaskModal(); |
| 40 | + |
| 41 | + // Select a project |
| 42 | + cy.get('[role="dialog"]').find('input[placeholder="Select a project"]').click({ force: true }); |
| 43 | + cy.get('[role="listbox"]').contains('Impact Attenuator').first().click(); |
| 44 | + |
| 45 | + // Fill in the title - the title textbox has no placeholder, find it via the Title label |
| 46 | + cy.get('[role="dialog"]').contains('Title').siblings().find('input').first().type(taskTitle, { force: true }); |
| 47 | + |
| 48 | + // Submit the form and verify the POST succeeds with the task title in the response |
| 49 | + cy.intercept('POST', '**/tasks/**').as('createTask'); |
| 50 | + cy.get('[role="dialog"]').find('button').contains('Create').click({ force: true }); |
| 51 | + cy.wait('@createTask').then((interception) => { |
| 52 | + expect(interception.response.statusCode).to.eq(200); |
| 53 | + expect(interception.response.body.title).to.eq(taskTitle); |
| 54 | + }); |
| 55 | + }); |
| 56 | + |
| 57 | + it('Creating a Task with Assignee Writes to DB Successfully', () => { |
| 58 | + const taskTitle = 'Assigned Task Test'; |
| 59 | + |
| 60 | + openCreateTaskModal(); |
| 61 | + |
| 62 | + // Select a project |
| 63 | + cy.get('[role="dialog"]').find('input[placeholder="Select a project"]').click({ force: true }); |
| 64 | + cy.get('[role="listbox"]').contains('Impact Attenuator').first().click(); |
| 65 | + |
| 66 | + // Fill in the title |
| 67 | + cy.get('[role="dialog"]').contains('Title').siblings().find('input').first().type(taskTitle, { force: true }); |
| 68 | + |
| 69 | + // Add self as assignee |
| 70 | + cy.get('[role="dialog"]').find('input[placeholder="Select users"]').click({ force: true }); |
| 71 | + cy.get('[role="listbox"]').contains('Thomas Emrax').click(); |
| 72 | + // Close the assignee dropdown by clicking elsewhere in the dialog |
| 73 | + cy.get('[role="dialog"]').find('h2').click({ force: true }); |
| 74 | + |
| 75 | + // Submit and verify the POST succeeds with correct data |
| 76 | + cy.intercept('POST', '**/tasks/**').as('createTask'); |
| 77 | + cy.get('[role="dialog"]').find('button').contains('Create').click({ force: true }); |
| 78 | + cy.wait('@createTask').then((interception) => { |
| 79 | + expect(interception.response.statusCode).to.eq(200); |
| 80 | + expect(interception.response.body.title).to.eq(taskTitle); |
| 81 | + expect(interception.response.body.assignees).to.have.length.greaterThan(0); |
| 82 | + }); |
| 83 | + }); |
| 84 | +}); |
0 commit comments