added cypress tests and GitHub action config

This commit is contained in:
Guillermo de Abreu 2025-02-10 15:43:17 -04:00
parent 7f8f9ff1a3
commit 58961f4eff
13 changed files with 2068 additions and 4 deletions

View File

@ -2,6 +2,6 @@ COMPANY_NAME="Vercel Inc."
TWITTER_CREATOR="@vercel"
TWITTER_SITE="https://nextjs.org/commerce"
SITE_NAME="Next.js Commerce"
SHOPIFY_REVALIDATION_SECRET=""
SHOPIFY_STOREFRONT_ACCESS_TOKEN=""
SHOPIFY_STORE_DOMAIN="[your-shopify-store-subdomain].myshopify.com"
SHOPIFY_REVALIDATION_SECRET="3f8fe3fc0f66abd75db02ea3e01f4179"
SHOPIFY_STOREFRONT_ACCESS_TOKEN="f6792ac13373db0526e0871cab1966bd"
SHOPIFY_STORE_DOMAIN="nextjs-prueba.myshopify.com"

24
.github/workflows/main.yml vendored Normal file
View File

@ -0,0 +1,24 @@
name: E2E on Chrome
on: [push]
jobs:
install:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Cypress run
uses: cypress-io/github-action@v3
with:
project: ./site
browser: chrome
build: yarn build
start: yarn start
wait-on: "http://localhost:3000"
env:
COMMERCE_PROVIDER: ${{ secrets.COMMERCE_PROVIDER }}
NEXT_PUBLIC_SHOPIFY_STOREFRONT_ACCESS_TOKEN: ${{ secrets.NEXT_PUBLIC_SHOPIFY_STOREFRONT_ACCESS_TOKEN }}
NEXT_PUBLIC_SHOPIFY_STORE_DOMAIN: ${{ secrets.NEXT_PUBLIC_SHOPIFY_STORE_DOMAIN }}

View File

@ -17,6 +17,7 @@ export default function Search() {
autoComplete="off"
defaultValue={searchParams?.get('q') || ''}
className="text-md w-full rounded-lg border bg-white px-4 py-2 text-black placeholder:text-neutral-500 md:text-sm dark:border-neutral-800 dark:bg-transparent dark:text-white dark:placeholder:text-neutral-400"
data-testid="search-bar-input"
/>
<div className="absolute right-0 top-0 mr-3 flex h-full items-center">
<MagnifyingGlassIcon className="h-4" />

View File

@ -12,6 +12,7 @@ export default function ProductGridItems({ products }: { products: Product[] })
className="relative inline-block h-full w-full"
href={`/product/${product.handle}`}
prefetch={true}
data-testid="product-link"
>
<GridTileImage
alt={product.title}

9
cypress.config.ts Normal file
View File

@ -0,0 +1,9 @@
import { defineConfig } from "cypress";
export default defineConfig({
e2e: {
setupNodeEvents(on, config) {
// implement node event listeners here
},
},
});

11
cypress/e2e/header.cy.js Normal file
View File

@ -0,0 +1,11 @@
/// <reference types="cypress" />
/// <reference types="../support" />
describe("Testing for header elements", () => {
it("return the right product when searched", () => {
cy.visit("http://localhost:3000");
cy.getBySel("search-bar-input").type("camisa{enter}");
cy.getBySel("product-link").first().click();
cy.location("pathname").should("eq", "/product/otra-camisa");
})
})

9
cypress/e2e/home.cy.js Normal file
View File

@ -0,0 +1,9 @@
/// <reference types="cypress" />
describe('Home Page', () => {
it("Displays all 2 products at home page", () => {
cy.visit("http://localhost:3000")
})
})

View File

@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "hello@cypress.io",
"body": "Fixtures are a great way to mock data for responses to routes"
}

View File

@ -0,0 +1,43 @@
/// <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>
// }
// }
// }
Cypress.Commands.add("getBySel", (selector) => {
return cy.get(`[data-testid=${selector}]`)
})

17
cypress/support/e2e.ts Normal file
View File

@ -0,0 +1,17 @@
// ***********************************************************
// 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'

6
cypress/support/index.d.ts vendored Normal file
View File

@ -0,0 +1,6 @@
declare namespace Cypress {
interface Chainable {
getBySel(selector: string): Chainable<JQuery<HTMLElement>>
}
}

View File

@ -6,7 +6,9 @@
"start": "next start",
"prettier": "prettier --write --ignore-unknown .",
"prettier:check": "prettier --check --ignore-unknown .",
"test": "pnpm prettier:check"
"test": "pnpm prettier:check",
"cypress:open": "cypress open",
"cypress:run": "cypress run"
},
"dependencies": {
"@headlessui/react": "^2.2.0",
@ -25,6 +27,7 @@
"@types/node": "22.13.1",
"@types/react": "19.0.8",
"@types/react-dom": "19.0.3",
"cypress": "^14.0.2",
"postcss": "^8.5.1",
"prettier": "3.4.2",
"prettier-plugin-tailwindcss": "^0.6.11",

1935
yarn.lock Normal file

File diff suppressed because it is too large Load Diff