test submit creates plan and closes modal
This commit is contained in:
parent
e7d30d364a
commit
e1b02f0ba9
1 changed files with 50 additions and 0 deletions
|
|
@ -45,4 +45,54 @@ describe('Create plan modal on the home page', () => {
|
|||
cy.get('#create-plan-modal button.cancel-plan').click()
|
||||
cy.get('#create-plan-modal').should('not.be.visible')
|
||||
})
|
||||
|
||||
it('submits plan details to /api/plans', () => {
|
||||
cy.intercept('POST', '/api/plans').as('createPlan')
|
||||
cy.get('#texts-list li').first()
|
||||
.find('button.create-plan').click()
|
||||
cy.get('#create-plan-modal input.plan-name')
|
||||
.type('My reading plan')
|
||||
cy.get('#create-plan-modal input.plan-date-start')
|
||||
.type('2025-01-01')
|
||||
cy.get('#create-plan-modal input.plan-date-end')
|
||||
.type('2025-01-31')
|
||||
cy.get('#create-plan-modal button.save-plan').click()
|
||||
cy.wait('@createPlan').then((createPlanRequest) => {
|
||||
expect(createPlanRequest.response.statusCode).to.eq(201)
|
||||
expect(createPlanRequest.request.body).to.deep.equal({
|
||||
userId: 0,
|
||||
textId: 0,
|
||||
name: 'My reading plan',
|
||||
dateStart: '2025-01-01',
|
||||
dateEnd: '2025-01-31',
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('closes the modal after successful submit', () => {
|
||||
cy.intercept('POST', '/api/plans').as('createPlan')
|
||||
cy.get('#texts-list li').first()
|
||||
.find('button.create-plan').click()
|
||||
cy.get('#create-plan-modal input.plan-name')
|
||||
.type('Another plan')
|
||||
cy.get('#create-plan-modal input.plan-date-start')
|
||||
.type('2025-02-01')
|
||||
cy.get('#create-plan-modal input.plan-date-end')
|
||||
.type('2025-02-28')
|
||||
cy.get('#create-plan-modal button.save-plan').click()
|
||||
cy.wait('@createPlan')
|
||||
cy.get('#create-plan-modal').should('not.be.visible')
|
||||
})
|
||||
|
||||
it('does not submit if name is empty', () => {
|
||||
cy.intercept('POST', '/api/plans').as('createPlan')
|
||||
cy.get('#texts-list li').first()
|
||||
.find('button.create-plan').click()
|
||||
cy.get('#create-plan-modal input.plan-date-start')
|
||||
.type('2025-01-01')
|
||||
cy.get('#create-plan-modal input.plan-date-end')
|
||||
.type('2025-01-31')
|
||||
cy.get('#create-plan-modal button.save-plan').click()
|
||||
cy.get('@createPlan.all').should('have.length', 0)
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue