|
| 1 | +/// <reference types="Cypress" /> |
| 2 | + |
| 3 | +context('Form', () => { |
| 4 | + beforeEach(() => { |
| 5 | + cy.visit('http://localhost:3000/'); |
| 6 | + }); |
| 7 | + |
| 8 | + it('should change input values', () => { |
| 9 | + const nameText = 'John Deer'; |
| 10 | + const descText = 'This is a desc test'; |
| 11 | + const recurrenceIntervalText = 10; |
| 12 | + const dateText = '2001-03-15'; |
| 13 | + |
| 14 | + cy.get('[id="#/properties/name-input"]').clear().type(nameText); |
| 15 | + cy.get('[id="#/properties/description-input"]').clear().type(descText); |
| 16 | + cy.get('[id="#/properties/done-input"]').uncheck(); |
| 17 | + cy.get('[id="#/properties/recurrence"]').parent().click(); |
| 18 | + cy.get('[id="#/properties/recurrence-option-3"]').click(); // Monthly |
| 19 | + cy.get('[id="#/properties/recurrence_interval-input"]') |
| 20 | + .clear() |
| 21 | + .type(recurrenceIntervalText); |
| 22 | + cy.get('[id="#/properties/due_date-input"]').clear().type(dateText); |
| 23 | + cy.get('[id="#/properties/rating"] span:last').click(); |
| 24 | + cy.get('[id="boundData"]') |
| 25 | + .invoke('text') |
| 26 | + .then(content => { |
| 27 | + const data = JSON.parse(content); |
| 28 | + |
| 29 | + expect(data.name).to.equal(nameText); |
| 30 | + cy.get('[id="#/properties/name"] p').should('be.empty'); |
| 31 | + |
| 32 | + cy.get('[id="#/properties/recurrence_interval"]').should('exist'); |
| 33 | + |
| 34 | + expect(data.description).to.equal(descText); |
| 35 | + expect(data.done).to.equal(false); |
| 36 | + expect(data.recurrence).to.equal('Monthly'); |
| 37 | + expect(data.recurrence_interval).to.equal(recurrenceIntervalText); |
| 38 | + expect(data.due_date).to.equal(dateText); |
| 39 | + expect(data.rating).to.equal(5); |
| 40 | + }); |
| 41 | + }); |
| 42 | + |
| 43 | + it('should show errors', () => { |
| 44 | + cy.get('[id="#/properties/name-input"]').clear(); |
| 45 | + |
| 46 | + cy.get('[id="#/properties/name"] p:first-child').should('not.be.empty'); |
| 47 | + |
| 48 | + cy.get('[id="#/properties/due_date-input"]').clear().type('351'); |
| 49 | + |
| 50 | + cy.get('[id="#/properties/due_date"] p:first-child').should('not.be.empty'); |
| 51 | + |
| 52 | + cy.get('[id="#/properties/recurrence"]').parent().click(); |
| 53 | + cy.get('[id="#/properties/recurrence-option-0"]').click(); // Never |
| 54 | + |
| 55 | + cy.get('[id="#/properties/recurrence_interval"]').should('not.exist'); |
| 56 | + |
| 57 | + cy.get('[id="boundData"]') |
| 58 | + .invoke('text') |
| 59 | + .then(content => { |
| 60 | + const data = JSON.parse(content); |
| 61 | + |
| 62 | + // expect(data.due_date).to.equal('Invalid date'); <- Mui doesn't allow setting invalid date |
| 63 | + expect(data.due_date).to.equal(undefined); |
| 64 | + }); |
| 65 | + }); |
| 66 | +}); |
0 commit comments