Skip to content

Commit

Permalink
Working
Browse files Browse the repository at this point in the history
- setup stub response, visit page which triggers API call, but wait before clicking for that API call to resolve
  • Loading branch information
mrWh1te committed Jun 25, 2019
1 parent 95a431a commit 60d3c51
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cypress/integration/books.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ describe('Books', function() {
it('Users should be able to select the first Book (The adventures of Tom Sawyer) & View it in the selected book section', () => {
cy.server()
setupOpenLibraryBooksStubResponse()

cy.visit('http://localhost:4200')
cy.wait('@openLibraryAPI')

cy.get('book').first().find('mat-card').click()
cy.get('selected-book .book-details h2').text().should('eq', 'The adventures of Tom Sawyer')
Expand Down
4 changes: 2 additions & 2 deletions cypress/integration/cart.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ describe('Cart', function() {
it('Users should be able to add any book to their Basket then Remove it to show an Empty message', () => {
cy.server()
setupOpenLibraryBooksStubResponse()

cy.visit('http://localhost:4200')
cy.wait('@openLibraryAPI')

addRandomBookToCart()

Expand All @@ -28,8 +28,8 @@ describe('Cart', function() {
it('Limits Users to 4 books in their Basket', () => {
cy.server()
setupOpenLibraryBooksStubResponse()

cy.visit('http://localhost:4200')
cy.wait('@openLibraryAPI')

cy.get('book').eq(0).find('mat-card').click()
cy.get('selected-book .add-to-basket-btn-container button').click()
Expand Down
4 changes: 2 additions & 2 deletions cypress/integration/checkout.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ describe('Checkout', function() {
it('Users should be able to add any book to their Basket from their Home page, then go to the Checkout page, to see it listed in the Shopping Cart', () => {
cy.server()
setupOpenLibraryBooksStubResponse()

cy.visit('http://localhost:4200')
cy.wait('@openLibraryAPI')

addRandomBookToCart()

Expand All @@ -31,8 +31,8 @@ describe('Checkout', function() {
it('Checkout button can be submitted once the form is filled correctly and there is at least 1 book in the Cart', () => {
cy.server()
setupOpenLibraryBooksStubResponse()

cy.visit('http://localhost:4200')
cy.wait('@openLibraryAPI')

addRandomBookToCart()

Expand Down
3 changes: 1 addition & 2 deletions cypress/support/routing/books.routing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ export function setupOpenLibraryBooksStubResponse() {
// I think we're hitting a limit on image requests from OpenLibrary.org
// so for these tests, let's omit actual images so we're not trying to request over and over again image files
cy.fixture('open-library-books-no-covers.json').as('fxBooks')
cy.route('GET', '**/books*', '@fxBooks')
cy.wait('fxBooks')
cy.route('GET', '**/books*', '@fxBooks').as('openLibraryAPI')
}

0 comments on commit 60d3c51

Please sign in to comment.