-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add cypress as a dev dependency Signed-off-by: Sriram Thiagarajan <sri.sjc@gmail.com> * 🎉 initial cypress tests for site title & some data Signed-off-by: Sriram Thiagarajan <sri.sjc@gmail.com> * more tests for home page Signed-off-by: Sriram Thiagarajan <sri.sjc@gmail.com> * tests for about page Signed-off-by: Sriram Thiagarajan <sri.sjc@gmail.com> * more tests for home page Signed-off-by: Sriram Thiagarajan <sri.sjc@gmail.com> * remove dummy files created by cypress Signed-off-by: Sriram Thiagarajan <sri.sjc@gmail.com> * update all gatsby dependencies to latest tag Signed-off-by: Sriram Thiagarajan <sri.sjc@gmail.com> * Run cypress tests on CI * update all gatsby dependencies to latest tag * run cypress tests on travis, hopefully * well, try again to run ui tests on travis * add cypress videos to gitignore * uncomment original travis stages * update cypress project id Signed-off-by: Sriram Thiagarajan <sri.sjc@gmail.com> * remove cypress record temporarily Signed-off-by: Sriram Thiagarajan <sri.sjc@gmail.com>
- Loading branch information
1 parent
036b3c8
commit bed4184
Showing
14 changed files
with
242 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
public | ||
.cache | ||
node_modules | ||
cypress/videos/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"baseUrl": "http://localhost:8000", | ||
"fixturesFolder": "data", | ||
"projectId": "c9d3r3" | ||
} |
28 changes: 28 additions & 0 deletions
28
examples/gatsbygram/cypress/integration/about_page_spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
describe(`About Page`, () => { | ||
it(`successfully loads`, () => { | ||
cy.visit(`/about`) | ||
}) | ||
|
||
it(`contains the title with an SVG icon and text "Gatsbygram"`, () => { | ||
cy.getTestElement(`site-title`).get(`svg`) | ||
cy.getTestElement(`site-title`).contains(`Gatsbygram`) | ||
}) | ||
|
||
it(`clicking on site title takes to home page`, () => { | ||
cy.getTestElement(`site-title`).click() | ||
cy.url().should(`eq`, `${Cypress.config(`baseUrl`)}/`) | ||
|
||
// go back to about page for further testing | ||
cy.visit(`/about`) | ||
}) | ||
|
||
it(`contains a link to about page in nav bar and it works`, () => { | ||
cy.getTestElement(`about-link`).contains(`About`) | ||
cy.getTestElement(`about-link`).click() | ||
cy.url().should(`eq`, `${Cypress.config(`baseUrl`)}/about/`) | ||
}) | ||
|
||
it(`displays title of the page`, () => { | ||
cy.getTestElement(`about-title`).contains(`About Gatsbygram`) | ||
}) | ||
}) |
106 changes: 106 additions & 0 deletions
106
examples/gatsbygram/cypress/integration/home_page_spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
|
||
describe(`The Home Page`, () => { | ||
it(`successfully loads`, () => { | ||
cy.visit(`/`) | ||
}) | ||
|
||
it(`contains the title with an SVG icon and text "Gatsbygram"`, () => { | ||
cy.getTestElement(`site-title`).get(`svg`) | ||
cy.getTestElement(`site-title`).contains(`Gatsbygram`) | ||
}) | ||
|
||
it(`contains a link to about page in nav bar and it works`, () => { | ||
cy.getTestElement(`about-link`).contains(`About`) | ||
cy.getTestElement(`about-link`).click() | ||
cy.url().should(`eq`, `${Cypress.config(`baseUrl`)}/about/`) | ||
// go back to home page | ||
cy.visit(`/`) | ||
}) | ||
|
||
it(`renders user avatar and name`, () => { | ||
cy.getTestElement(`user-avatar`).get(`img`) | ||
cy.getTestElement(`username`).contains(`kyle__mathews`) | ||
}) | ||
|
||
it(`shows user's posts and followers count`, () => { | ||
cy.getTestElement(`user-meta`).contains(`100 posts`) | ||
cy.getTestElement(`user-meta`).contains(`192k followers`) | ||
}) | ||
|
||
it(`shows number of likes when hovered on a post`, () => { | ||
cy.fixture(`posts`).then((postsData) => { | ||
const post = postsData[0] | ||
cy.getTestElement(`post`).first().trigger(`mouseover`) | ||
cy.getTestElement(`likes`).contains(post.likes) | ||
cy.getTestElement(`post`).first().trigger(`mouseout`) | ||
}) | ||
}) | ||
|
||
it(`opens and closes a post`, () => { | ||
cy.fixture(`posts`).then((postsData) => { | ||
const post = postsData[0] | ||
cy.getTestElement(`post`).first().click() | ||
cy.url().should('contain', post.id) | ||
cy.getTestElement(`post-detail-avatar`).should(`have.attr`, `src`, post.avatar) | ||
cy.getTestElement(`post-detail-username`).contains(post.username) | ||
cy.getTestElement(`post-detail-likes`).contains(post.likes) | ||
cy.getTestElement(`post-detail-text`).contains(post.username) | ||
cy.getTestElement(`post-detail-text`).contains(post.text) | ||
cy.getTestElement(`modal-close`).click() | ||
cy.url().should(`eq`, `${Cypress.config(`baseUrl`)}/`) | ||
}) | ||
}) | ||
|
||
it(`goes to next / previous post on clicking arrow icons`, () => { | ||
cy.fixture(`posts`).then((postsData) => { | ||
const post1 = postsData[0] | ||
const post2 = postsData[1] | ||
// open fist post | ||
cy.getTestElement(`post`).first().click() | ||
cy.url().should('contain', post1.id) | ||
// click right arrow icon to go to 2nd post | ||
cy.getTestElement(`next-post`).click() | ||
cy.url().should('contain', post2.id) | ||
// press left arrow to go back to 1st post | ||
cy.getTestElement(`previous-post`).click() | ||
cy.url().should('contain', post1.id) | ||
// close the post | ||
cy.getTestElement(`modal-close`).click() | ||
}) | ||
}) | ||
|
||
it(`goes to next / previous post with keyboard shortcut`, () => { | ||
cy.fixture(`posts`).then((postsData) => { | ||
const post1 = postsData[0] | ||
const post2 = postsData[1] | ||
// open fist post | ||
cy.getTestElement(`post`).first().click() | ||
cy.url().should('contain', post1.id) | ||
// press right arrow to go to 2nd post | ||
cy.get(`body`).type(`{rightarrow}`) | ||
cy.url().should('contain', post2.id) | ||
// press left arrow to go back to 1st post | ||
cy.get(`body`).type(`{leftarrow}`) | ||
cy.url().should('contain', post1.id) | ||
// close the post | ||
cy.getTestElement(`modal-close`).click() | ||
}) | ||
}) | ||
|
||
it(`loads more posts when Load More button is clicked & on scroll`, () => { | ||
// initially loads 12 posts | ||
cy.getTestElement(`post`).should('have.length', 12) | ||
|
||
// loads 12 more posts when Load More button is clicked | ||
cy.getTestElement(`load-more`).click() | ||
cy.getTestElement(`post`).should('have.length', 24) | ||
|
||
// loads 12 more posts when scrolled to bottom | ||
// cy.getTestElement(`home-container`).scrollTo(`0%`, `99%`) | ||
cy.window().scrollTo(`bottom`) | ||
cy.getTestElement(`post`).should('have.length', 36) | ||
|
||
// let's go back to top | ||
cy.window().scrollTo(`top`) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// *********************************************** | ||
// This example commands.js shows you how to | ||
// create various custom commands and overwrite | ||
// existing commands. | ||
// | ||
// For more comprehensive examples of custom | ||
// commands please read more here: | ||
// https://on.cypress.io/custom-commands | ||
// *********************************************** | ||
// | ||
// | ||
// -- This is a parent command -- | ||
// Cypress.Commands.add("login", (email, password) => { ... }) | ||
// | ||
// | ||
// -- This is a child command -- | ||
// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... }) | ||
// | ||
// | ||
// -- This is a dual command -- | ||
// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... }) | ||
// | ||
// | ||
// -- This is will overwrite an existing command -- | ||
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... }) | ||
|
||
// copied from here - https://github.com/cypress-io/cypress/issues/1212#issuecomment-360395261 | ||
Cypress.Commands.add("getTestElement", (selector) => { | ||
return cy.get(`[data-testid="${selector}"]`) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// *********************************************************** | ||
// This example support/index.js is processed and | ||
// loaded automatically before your test files. | ||
// | ||
// This is a great place to put global configuration and | ||
// behavior that modifies Cypress. | ||
// | ||
// You can change the location of this file or turn off | ||
// automatically serving support files with the | ||
// 'supportFile' configuration option. | ||
// | ||
// You can read more here: | ||
// https://on.cypress.io/configuration | ||
// *********************************************************** | ||
|
||
// Import commands.js using ES2015 syntax: | ||
import './commands' | ||
|
||
// Alternatively you can use CommonJS syntax: | ||
// require('./commands') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.