|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- describe('form', () => {
- beforeEach(() => {
- cy.task('resetDb');
- });
-
- describe('script', () => {
- it('submits form with complete data', () => {
- cy.visit('http://localhost:3000/notes');
- cy.intercept('POST', '/api/notes').as('action');
- cy.get('form').should('exist').within(() => {
- cy.get('input[name="title"]').type('test title');
- cy.get('input[name="image"]').selectFile('cypress/fixtures/file.jpg');
- cy.get('textarea[name="content"]').type('test content');
- cy.get('button[type="submit"]').click();
- cy.wait('@action').its('response.statusCode').should('eq', 201);
- });
-
- cy.url().should('match', /\/notes\/[a-z0-9-]+$/);
- });
-
- it('submits form with incomplete data', () => {
- cy.visit('http://localhost:3000/notes');
- cy.intercept('POST', '/api/notes').as('action');
- cy.get('form').should('exist').within(() => {
- cy.get('input[name="title"]').type('test title');
- cy.get('textarea[name="content"]').type('test content');
- cy.get('button[type="submit"]').click();
- cy.wait('@action').its('response.statusCode').should('eq', 201);
- });
-
- cy.url().should('match', /\/notes\/[a-z0-9-]+$/);
- });
-
- it('handles redirects', () => {
- cy.visit('http://localhost:3000/notes');
- cy.intercept('DELETE', '/api/notes/*').as('action');
- cy.get('form').should('exist').within(() => {
- cy.get('input[name="title"]').type('test title');
- cy.get('textarea[name="content"]').type('test content');
- cy.get('button[type="submit"]').click();
- });
- cy.get('button').contains('Delete').click();
- cy.wait('@action').its('response.statusCode').should('eq', 204);
- cy.url().should('match', /\/notes$/);
- });
- });
-
- describe('noscript', () => {
- it('submits form with complete data', () => {
- cy.visit('http://localhost:3000/notes?noscript=true');
- cy.intercept('POST', '/a/notes?noscript=true').as('action');
- cy.intercept('POST', '/notes/*').as('destination');
- cy.get('form').should('exist').within(() => {
- cy.get('input[name="title"]').type('test title');
- cy.get('input[name="image"]').selectFile('cypress/fixtures/file.jpg');
- cy.get('textarea[name="content"]').type('test content');
- cy.get('button[type="submit"]').click();
- });
- cy.wait('@action').its('response.statusCode').should('eq', 307);
- cy.wait('@destination').its('response.statusCode').should('eq', 201);
- cy.url().should('match', /\/notes\/[a-z0-9-]+\?/);
- });
-
- it('submits form with incomplete data', () => {
- cy.visit('http://localhost:3000/notes?noscript=true');
- cy.intercept('POST', '/a/notes?noscript=true').as('action');
- cy.intercept('POST', '/notes/*').as('destination');
- cy.get('form').should('exist').within(() => {
- cy.get('input[name="title"]').type('test title');
- cy.get('textarea[name="content"]').type('test content');
- cy.get('button[type="submit"]').click();
- });
- cy.wait('@action').its('response.statusCode').should('eq', 307);
- cy.wait('@destination').its('response.statusCode').should('eq', 201);
- cy.url().should('match', /\/notes\/[a-z0-9-]+\?/);
- });
-
- it('handles redirects', () => {
- cy.visit('http://localhost:3000/notes?noscript=true');
- cy.get('form').should('exist').within(() => {
- cy.get('input[name="title"]').type('test title');
- cy.get('textarea[name="content"]').type('test content');
- cy.get('button[type="submit"]').click();
- });
- cy.intercept('POST', '/a/notes/*').as('action');
- cy.intercept('POST', '/notes').as('destination');
- cy.get('button').contains('Delete').click();
- cy.wait('@action').its('response.statusCode').should('eq', 307);
- cy.wait('@destination').its('response.statusCode').should('eq', 200);
- cy.url().should('match', /\/notes$/);
- });
- });
- });
|