Skip to content

Commit

Permalink
Merge pull request reactplay#521 from ShaileshParmar11/cy-home-page
Browse files Browse the repository at this point in the history
Added Cypress test for home page
  • Loading branch information
atapas committed Aug 27, 2022
2 parents 6297ce5 + a68be11 commit bac2211
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/cypress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ jobs:
start: npm start
wait-on: "http:https://localhost:3000"
browser: chrome
env:
# pass GitHub token to detect new build vs re-run build
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
47 changes: 47 additions & 0 deletions cypress/e2e/homePage.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/// <reference types="cypress" />

import { CONTRIBUTORS_COUNT, TWEET_COUNT } from "../support/constant";

describe("Test home page", () => {
beforeEach(() => {
cy.visit("/");
});

it("Header component should render properly", () => {
cy.get('[data-testid="app-header"]').should("be.visible");
cy.get('[data-testid="app-logo"]').should("be.visible");
cy.get('[data-testid="plays-search-box-container"]').should("not.exist");
cy.get('[data-testid="header-links-container"]').should("be.visible");
cy.get('[data-testid="browse-btn"]').should("be.visible").as("browseBtn");
cy.get('[data-testid="create-btn"]').should("be.visible");
cy.get('[data-testid="ideas-btn"]').should("be.visible");
cy.get('[data-testid="github-btn"]').should("be.visible");
cy.get('[data-testid="twitter-btn"]').should("be.visible");
cy.get('[data-testid="share-btn"]').should("be.visible");

cy.get("@browseBtn").click();
cy.get('[data-testid="plays-search-box-container"]').should("be.visible");
});

it("Tweet section should render with all tweets", () => {
cy.intercept("GET", "https://cdn.syndication.twimg.com/*").as("tweets");
cy.wait("@tweets");
cy.get('[data-testid="tweet-container"]')
.scrollIntoView()
.should("be.visible");
cy.get('[data-testid="tweet-container"] [id*="twitter-widget"]').should(
"have.length",
TWEET_COUNT
);
cy.get('[data-testid="watch-svg"]').should("not.exist");
});

it("Contributors section should render with all contributors", () => {
cy.get('[data-testid="contributors-section"]')
.scrollIntoView()
.should("be.visible");
cy.get(
'[data-testid="contributors-section"] [data-testid*="contributor-"]'
).should("have.length", CONTRIBUTORS_COUNT);
});
});
2 changes: 2 additions & 0 deletions cypress/support/constant.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const TWEET_COUNT = 10;
export const CONTRIBUTORS_COUNT = 29;

0 comments on commit bac2211

Please sign in to comment.