Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic E2E Cypress Tests #18

Merged
merged 21 commits into from
Jun 25, 2019
Merged

Add basic E2E Cypress Tests #18

merged 21 commits into from
Jun 25, 2019

Conversation

mrWh1te
Copy link
Owner

@mrWh1te mrWh1te commented Jun 25, 2019

  • Books
    • view them
    • select a book to add to cart
  • Cart
    • drop-down interactions
    • add/remove items
  • Checkout
    • validation testing on button for disabled
  • Added cypress-commands for text()
  • Setup TypeScript with imports
    • using @cypress/webpack-preprocessor and ts-loader

Covers the main "business" logic in viewing books, adding books to cart and checking them out

  • replace http-server with spa-http-server for e2e tests that visit() spa routes ie /checkout
  • stub the OpenLibrary.org API response

Future:
We should create an Integration test so we can be notified when OpenLibrary.org's API response structure changes
Added a basic integration test that checks to see if the response is JSON. In the future, the tests need to be expanded upon based on the structure of the JSON returned (make sure there is title, cover, the correct structure, etc. for which this app depends on)

However, as of writing this, openlibrary.org is down, so we'll have to wait.

- basic e2e tests for main home page
- working on adding TS support and imports
- added basic e2e tests for the Books, Cart, and Checkout
- fixing online issues
- replaced http-server with spa-http-server that has push-state for fallback 404 routing since routing is done in SPA not backend
- added a response fixture to the limits users test in Cart because we need images for the elements to have dimension
- tweaking the spa-http-server setup for travis
- relative linking
- getting close to merge
- min width & height on book to try to fix an issue of some images not loading in time for test
- stubbed the open library books response with less data & without cover images (I believe we hit a limit on requesting images through our test suites, which makes sense since it keeps requesting images over and over in E2E)
- use beforeEach() for clearing local storage between tests
@mrWh1te
Copy link
Owner Author

mrWh1te commented Jun 25, 2019

With the recent commit, our E2E tests are running faster because:

  1. We are no longer waiting for OpenLibrary.org's API to respond, given we've stubbed it out
  2. The stubbed out response data has lots of data omitted (ie subject_places, subjects, etc), including the important cover for every book's images

So we're no longer waiting for the API to resolve, or for images to load. I updated the code with ? on cover where missing so it won't error when there are no cover images to src in an img.

I ran into an issue with both. It just made it easier to stub out the response and take control that way

  1. I believe we hit a DOS limit and basically got black-listed because these tests kept requesting the Images over and over again. It got to a point where no images were loading in the tests, but were fine outside
  2. The API response takes a while, since we're requesting a lot of vertical data on a bunch of books. It's not the ideal setup, I've contemplated changing the way we interact with this API by selecting only a few books per request, instead of them all in 1 request, to try and make the initial data load faster, but I'm on the fence about building a backend for this project so if I do, then I'll switch over to that.

That said, this opens up a hole in our testing coverage. We now need an Integration Test to basically insure our integration with OpenLibrary.org's API. That way we can know through CI when OpenLibrary.org introduces a change to their API that breaks our system.

We could use cypress.request() to mock a network request to OpenLibrary.org to then assert the structure of its response to match our needs....

- book is a smart component that isnt being rendered in the DOM as taking space, but a placeholder for children elements too. So let's find the `mat-card` and click that instead
- basic integration test for OpenLibrary.org API but OpenLibrary.org is down right now! The demo site doesnt work unless you've already visited it recently (so it cached the response data in local storage)
- more reason to add a backend to this project...
- turned off test suite for open library API
- added basic min width & height to mat-card inside Book-Ui
- actually skip api test, not pending
- trying to force mat-card to have some size in DOM with out images... strangely enough it works fine locally with the same command but breaks remotely during CI
- instead of doing it artifically with CSS, when there is no image, just display the Book id (for now)
@mrWh1te
Copy link
Owner Author

mrWh1te commented Jun 25, 2019

so the branch build is passing, but the pr build (branch merged into master then tests ran) is failing

It's for the same reason as the past few. mat-card the element, is of (0, 0)px even though, in this context (inside BookUi), there is now a span that displays the id of the Book therefore giving some kind of dimension to the mat-card parent element.

I'm not sure

- strange, trying to get this to work in PR build too
- use alt attr in img
- let's make cypress wait for the backend stub to resolve before trying to click an element whose rendering is effected
- should have checked locally 1st
- setup stub response, visit page which triggers API call, but wait before clicking for that API call to resolve
@mrWh1te
Copy link
Owner Author

mrWh1te commented Jun 25, 2019

About this bug I've been working on, clicking something with 0 width and 0 height... is a rendering related issue

The solution I applied comes from here: cypress-io/cypress#695 (comment)
The relevant issue is being tracked here: cypress-io/cypress#696

But that thread, never-the-less, is important to follow in regards to rendering stuff that is API data dependent (since as that API resolves, it triggers a change detection which causes a new draw and possibly cypress is clicking while the draw is occurring or before)

@mrWh1te mrWh1te merged commit 6c1a324 into master Jun 25, 2019
@mrWh1te mrWh1te deleted the ml-basic-e2e-tests branch June 25, 2019 17:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant