Skip to content

Commit

Permalink
test(e2): complete test-suite
Browse files Browse the repository at this point in the history
  • Loading branch information
luhmann committed Mar 18, 2018
1 parent cab6bfa commit 4405765
Show file tree
Hide file tree
Showing 2 changed files with 148 additions and 30 deletions.
42 changes: 38 additions & 4 deletions cypress/integration/home/routing_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,51 @@ import { sel } from '../../support/utils';

describe('GIVEN a search-term set in the route', () => {
beforeEach(() => {
cy.visit('/');
cy.server();

cy.route({
method: 'GET',
url: /https:\/\/api.punkapi.com\/v2/,
response: 'fixture:beers-successful.json',
});

cy.visit('/#Burger');
});

it('should show a list of results', () => {});
it('should show a list of results', () => {
cy.get(sel('beer-card')).should('have.length', 14);
});

describe('WHEN searching again', () => {
beforeEach(() => {
cy
.get(sel('search-box'))
.clear()
.type('Steak')
.should('have.value', 'Steak')
.type('{enter}');
});

it('should change the url', () => {
cy.url().should('contain', '/#Steak');
});

describe('AND hitting the browsers `back`-button', () => {
it('should set the original url', () => {});
beforeEach(() => {
cy.go('back');
});

it('should set the original url', () => {
cy.url().should('contain', '/#Burger');
});

describe('AND hitting the browsers `forward`-button', () => {
it('should set the next-url', () => {});
beforeEach(() => {
cy.go('forward');
});
it('should set the next-url', () => {
cy.url().should('contain', '/#Steak');
});
});
});
});
Expand Down
136 changes: 110 additions & 26 deletions cypress/integration/home/search_beers_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,52 +29,136 @@ describe('searching for beers', () => {
.its('status')
.should('eq', 200);
});

cy.url().should('contain', '/#Burger');

cy.get(sel('beer-card')).should('have.length.above', 0);
});
});

describe('with a stubbed backend', () => {
beforeEach(() => {
cy.server();
describe('with a slow response', () => {
beforeEach(() => {
cy.server();

cy.route({
method: 'GET',
url: /https:\/\/api.punkapi.com\/v2/,
response: 'fixture:beers-successful.json',
delay: 500,
});

cy.route({
method: 'GET',
url: /https:\/\/api.punkapi.com\/v2/,
response: 'fixture:beers-successful.json',
delay: 500,
cy
.get(sel('search-box'))
.clear()
.type('Burger')
.should('have.value', 'Burger')
.type('{enter}');
});

cy
.get(sel('search-box'))
.clear()
.type('Burger')
.should('have.value', 'Burger')
.type('{enter}');
it('should display a loading indicator', () => {
cy.get(sel('loading-indicator'));
});
});

it('should change the url', () => {
cy.url().should('contain', '/#Burger');
});
describe('with a successful response', () => {
beforeEach(() => {
cy.server();

it('should display a loading indicator', () => {
cy.get(sel('loading-indicator'));
});
cy.route({
method: 'GET',
url: /https:\/\/api.punkapi.com\/v2/,
response: 'fixture:beers-successful.json',
});

cy
.get(sel('search-box'))
.clear()
.type('Burger')
.should('have.value', 'Burger')
.type('{enter}');
});

it('should change the url', () => {
cy.url().should('contain', '/#Burger');
});

describe('with a successful response', () => {
it('should display a list of beers', () => {
cy.get(sel('beer-card')).should('have.length', 14);
});

it('should display complete and correct information on a beer', () => {
// should have a name
// should have a tagline
// should have a description
// should have tags
// should have food-pairings
cy
.get(sel('beer-card'))
.first()
.find(sel('beer-card-name'))
.should('contain', 'Libertine Porter');

cy
.get(sel('beer-card'))
.first()
.find(sel('beer-card-tagline'))
.should('contain', 'Dry-Hopped Aggressive Porter');

cy
.get(sel('beer-card'))
.first()
.find(sel('beer-card-description'))
.should(
'contain',
'An avalanche of cross-continental hop varieties'
);

cy
.get(sel('beer-card'))
.first()
.find(sel('beer-card-tags'))
.should('contain', 'ABV 6.1%')
.and('contain', 'IBU 45');

cy
.get(sel('beer-card'))
.first()
.find(sel('beer-card-food-pairing'))
.should('have.length', 3);

cy
.get(sel('beer-card'))
.first()
.find(sel('beer-card-food-pairing'))
.eq(0)
.should('contain', 'Blue cheese beef burger');
});
});

describe('with an error-response', () => {
it('should display an error-message', () => {});
beforeEach(() => {
cy.server();

cy.route({
method: 'GET',
url: /https:\/\/api.punkapi.com\/v2/,
response: {
errors: ['Network Error'],
},
status: 503,
});

cy
.get(sel('search-box'))
.clear()
.type('Burger')
.should('have.value', 'Burger')
.type('{enter}');
});

it('should change the url', () => {
cy.url().should('contain', '/#Burger');
});

it('should display an error-message', () => {
cy.get(sel('error-message'));
});
});
});
});
Expand Down

0 comments on commit 4405765

Please sign in to comment.