|
- describe('form', () => {
- beforeEach(() => {
- cy.task('db:reset');
- });
-
- after(() => {
- cy.task('db:shutdown');
- });
-
- 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$/);
- });
- });
- });
|