Skip to content

Commit

Permalink
added cypress
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan-Roberts123 committed Apr 29, 2024
1 parent e1b80c9 commit 872c9fb
Show file tree
Hide file tree
Showing 10 changed files with 850 additions and 20 deletions.
6 changes: 5 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
"es6": true,
"node": true
},
"extends": ["eslint:recommended", "plugin:react/recommended"],
"extends": [
"eslint:recommended",
"plugin:react/recommended",
"eslint-plugin-cypress"
],
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
Expand Down
4 changes: 3 additions & 1 deletion components/Header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ const Header = () => (
<nav className="flex justify-between">
{useRouter().pathname !== '/' && (
<li className="self-center text-2xl hover:text-gray-500">
<Link href="/">Clients</Link>
<Link href="/" data-cy="Clients-link">
Clients
</Link>
</li>
)}
{useRouter().pathname !== '/add-client' && (
Expand Down
9 changes: 9 additions & 0 deletions cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const { defineConfig } = require("cypress");

module.exports = defineConfig({
e2e: {
setupNodeEvents(on, config) {
// implement node event listeners here
},
},
});
44 changes: 44 additions & 0 deletions cypress/e2e/clientFlow.spec.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
describe('Create update delete client', () => {
it('Does it metch', () => {
cy.visit('http://localhost:3000')
cy.contains('Add').click()

cy.url().should('include', '/add-client')

cy.get('[data-cy="name-filed"]').type('Test Client')
cy.get('[data-cy="name-filed"]').should('have.value', 'Test Client')

cy.get('[data-cy="email-filed"]').type('[email protected]')
cy.get('[data-cy="email-filed"]').should(
'have.value',
'[email protected]'
)

cy.get('[data-cy="phone-filed"]').type('78788833')
cy.get('[data-cy="phone-filed"]').should('have.value', '78788833')

cy.get('[data-cy="address-filed"]').type('123 Test RD')
cy.get('[data-cy="address-filed"]').should('have.value', '123 Test RD')

cy.get('[data-cy="company-filed"]').type('space-test')
cy.get('[data-cy="company-filed"]').should('have.value', 'space-test')

cy.get('[data-cy="notes-filed"]').type(
'Client for space-test, making a million doller deal'
)
cy.get('[data-cy="notes-filed"]').should(
'have.value',
'Client for space-test, making a million doller deal'
)

cy.get('[type="submit"]').click()
cy.contains('Test Client successfully added')

cy.get('[data-cy="Clients-link"]').click()

cy.get('[name="edit Test Client"]').click()
cy.contains('Delete').click()

cy.contains('Test Client successfully deleted')
})
})
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"
}
25 changes: 25 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// ***********************************************
// 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 will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
20 changes: 20 additions & 0 deletions cypress/support/e2e.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// ***********************************************************
// This example support/e2e.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')
15 changes: 9 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
"dev": "sst bind next dev",
"build": "next build",
"start": "next start",
"format": "prettier \"**/*.+(js|json|css|)\" --write --check"
"format": "prettier \"**/*.+(js|json|css|)\" --write --check",
"cy:open": "cypress open"
},
"dependencies": {
"@tailwindcss/custom-forms": "^0.2.1",
"autoprefixer": "^9.7.5",
"dotenv": "^8.2.0",
"isomorphic-unfetch": "^3.0.0",
Expand All @@ -23,14 +25,15 @@
"react-dom": "18.2.0",
"react-icons": "^3.9.0",
"react-notifications-component": "^3.1.0",
"tailwindcss": "^1.2.0",
"@tailwindcss/custom-forms": "^0.2.1"
"tailwindcss": "^1.2.0"
},
"devDependencies": {
"aws-cdk-lib": "2.132.1",
"constructs": "10.3.0",
"cypress": "^13.8.1",
"eslint": "^7.32.0",
"eslint-plugin-cypress": "^3.0.2",
"eslint-plugin-react": "^7.26.1",
"sst": "^2.41.4",
"aws-cdk-lib": "2.132.1",
"constructs": "10.3.0"
"sst": "^2.41.4"
}
}
6 changes: 6 additions & 0 deletions pages/add-client.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ const Add = () => {
value={newClient.name}
onChange={handleChange}
required={true}
data-cy="name-filed"
/>
</label>

Expand All @@ -90,6 +91,7 @@ const Add = () => {
value={newClient.email}
onChange={handleChange}
required={true}
data-cy="email-filed"
/>
</label>

Expand All @@ -108,6 +110,7 @@ const Add = () => {
value={newClient.phone}
onChange={handleChange}
required={true}
data-cy="phone-filed"
/>
</label>

Expand All @@ -123,6 +126,7 @@ const Add = () => {
name="address"
value={newClient.address}
onChange={handleChange}
data-cy="address-filed"
/>
</label>

Expand All @@ -138,6 +142,7 @@ const Add = () => {
name="company"
value={newClient.company}
onChange={handleChange}
data-cy="company-filed"
/>
</label>

Expand All @@ -153,6 +158,7 @@ const Add = () => {
name="notes"
value={newClient.notes}
onChange={handleChange}
data-cy="notes-filed"
/>
</label>
</div>
Expand Down
Loading

0 comments on commit 872c9fb

Please sign in to comment.