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

Final #35

Open
wants to merge 4 commits into
base: start
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineConfig } from "cypress";

export default defineConfig({
e2e: {
setupNodeEvents(on, config) {
// implement node event listeners here
},
},
});
6 changes: 6 additions & 0 deletions cypress/e2e/Home.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
describe('home page', () => {
it('the h1 contains the correct text', () => {
cy.visit('http://localhost:3000')
cy.get('h1').contains("Testing Next.js Applications with Cypress")
})
})
6 changes: 6 additions & 0 deletions cypress/e2e/home.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
describe('home page', () => {
it('the h1 contains the correct text', () => {
cy.visit('http://localhost:3000')
cy.get('h1').contains("Testing Next.js Applications with Cypress")
})
})
25 changes: 25 additions & 0 deletions cypress/e2e/subscribe.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
describe("Newsletter Subscribe Form", () => {
beforeEach(() => {
cy.visit("http://localhost:3000")
})

it("allows users to subscribe to the email list", () => {
cy.getByData("email-input").type("[email protected]")
cy.getByData("submit-button").click()
cy.getByData("success-message").should("exist").contains("[email protected]")
})

it("does NOT allow an invalid email address", () => {
cy.getByData("email-input").type("tom")
cy.getByData("submit-button").click()
cy.getByData("success-message").should("not.exist")
})

it("does NOT allow already subscribed email addresses", () => {
cy.getByData("email-input").type("[email protected]")
cy.getByData("submit-button").click()
cy.getByData("server-error-message")
.should("exist")
.contains("already exists. Please use a different email address.")
})
})
18 changes: 18 additions & 0 deletions cypress/e2e/user-journey.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
describe("User Journey", () => {
it("a user can find a course on the home page and complete the courses lessons", () => {
cy.visit("http://localhost:3000")
cy.getByData("course-0").find("a").contains("Get started").click()
cy.location("pathname").should("equal", "/testing-your-first-application")
cy.getByData("next-lesson-button").click()
cy.location("pathname").should(
"eq",
"/testing-your-first-application/app-install-and-overview"
)
cy.getByData("challenge-answer-0").click()
cy.getByData("next-lesson-button").should("exist").click()
cy.location("pathname").should(
"eq",
"/testing-your-first-application/installing-cypress-and-writing-our-first-test"
)
})
})
5 changes: 5 additions & 0 deletions cypress/fixtures/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "[email protected]",
"body": "Fixtures are a great way to mock data for responses to routes"
}
51 changes: 51 additions & 0 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/// <reference types="cypress" />
// ***********************************************
// This example commands.ts 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 will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
//
// declare global {
// namespace Cypress {
// interface Chainable {
// login(email: string, password: string): Chainable<void>
// drag(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
// dismiss(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
// visit(originalFn: CommandOriginalFn, url: string, options: Partial<VisitOptions>): Chainable<Element>
// }
// }
<<<<<<< Updated upstream
// }

declare namespace Cypress {
interface Chainable {
getByData(dataTestAttribute: string): Chainable<JQuery<HTMLElement>>
}
}

Cypress.Commands.add("getByData", (selector) => {
return cy.get(`[data-test=${selector}]`)
})
=======
// }
>>>>>>> Stashed changes
20 changes: 20 additions & 0 deletions cypress/support/e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// ***********************************************************
// This example support/e2e.ts 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')
Loading