Skip to content
Merged
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
48 changes: 48 additions & 0 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,51 @@ jobs:
pnpm install
- name: Build
run: pnpm run build

e2e:
name: E2E Tests
runs-on: ubuntu-latest
needs: [build]
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "20"

- name: Install dependencies
run: |
corepack enable
corepack prepare pnpm@latest --activate
pnpm install

- name: Build application
run: pnpm run build

- name: Start application
run: |
pnpm run preview &
sleep 10

- name: Run Cypress E2E tests
run: pnpm run cy:run
env:
CYPRESS_baseUrl: http://localhost:4173

- name: Upload Cypress screenshots
uses: actions/upload-artifact@v4
if: failure()
with:
name: cypress-screenshots
path: cypress/screenshots
if-no-files-found: ignore

- name: Upload Cypress videos
uses: actions/upload-artifact@v4
if: always()
with:
name: cypress-videos
path: cypress/videos
if-no-files-found: ignore
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ lerna-debug.log*

node_modules
dist
coverage
dist-ssr
*.local

Expand Down
14 changes: 14 additions & 0 deletions cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { defineConfig } from "cypress";

export default defineConfig({
e2e: {
baseUrl: "https://reactive-api-console.vercel.app/",
supportFile: "cypress/support/e2e.{js,jsx,ts,tsx}",
},
component: {
devServer: {
framework: "react",
bundler: "vite",
},
},
});
11 changes: 11 additions & 0 deletions cypress/component/ChatTitle.cy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/// <reference types="cypress" />

import React from "react";
import { ChatTitle } from "../../src/components/atoms/ChatTitle/ChatTitle";

describe("<ChatTitle />", () => {
it("renders", () => {
// see: https://on.cypress.io/mounting-react
cy.mount(<ChatTitle />);
});
});
63 changes: 63 additions & 0 deletions cypress/e2e/api-console.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/// <reference types="cypress" />

describe("Reactive API Console", () => {
beforeEach(() => {
cy.visit("/");
});

it("should display the main interface", () => {
cy.contains("Reactive API Console").should("be.visible");
cy.contains("Chat Console").should("be.visible");
cy.contains("Available API").should("be.visible");
});

it("should execute help command", () => {
cy.get('input[placeholder*="Type a command"]').type("help");
cy.get("button").contains("Send").click();

cy.contains("Available Commands").should("be.visible");
cy.contains("get cat fact").should("be.visible");
});

it("should toggle API activation", () => {
cy.get('[data-testid="api-list-item-cat-facts"]').should(
"have.class",
"ring-orange-500"
);
cy.contains("Cat Facts").click();
cy.get('[data-testid="api-list-item-cat-facts"]').not(
"have.class",
"ring-orange-500"
);
});

it("should execute cat fact command", () => {
cy.intercept("GET", "https://catfact.ninja/fact", {
fixture: "cat-fact.json",
}).as("getCatFact");

cy.get('input[placeholder*="Type a command"]').type("get cat fact");
cy.get("button").contains("Send").click();

cy.wait("@getCatFact");
cy.contains("✅ Executed: get cat fact").should("be.visible");
});

it("should filter results globally", () => {
// First execute some commands to get results
cy.intercept("GET", "https://catfact.ninja/fact", {
body: { fact: "Cats are amazing animals" },
}).as("getCatFact");

cy.get('input[placeholder*="Type a command"]').type("get cat fact");
cy.get("button").contains("Send").click();
cy.wait("@getCatFact");

// Now test global search
cy.get(".input-search").type("amazing");

// Results should be filtered
cy.contains("Cat Facts").click();
cy.contains("cat").should("be.visible");
});
});
35 changes: 35 additions & 0 deletions cypress/e2e/highlighting.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
describe("Highlighting", () => {
beforeEach(() => {
cy.visit("/");
});

it("should execute cat fact command", () => {
cy.intercept("GET", "https://catfact.ninja/fact", {
fixture: "cat-fact.json",
}).as("getCatFact");

cy.get('input[placeholder*="Type a command"]').type("get cat fact");
cy.get("button").contains("Send").click();

cy.wait("@getCatFact");
cy.contains("✅ Executed: get cat fact").should("be.visible");
});

it("should filter results globally", () => {
// First execute some commands to get results
cy.intercept("GET", "https://catfact.ninja/fact", {
body: { fact: "Cats are amazing animals" },
}).as("getCatFact");

cy.get('input[placeholder*="Type a command"]').type("get cat fact");
cy.get("button").contains("Send").click();
cy.wait("@getCatFact");

// Now test global search
cy.get(".input-search").type("amazing");

// Results should be filtered
cy.contains("Cat Facts").click();
cy.contains("cat").should("be.visible");
});
});
4 changes: 4 additions & 0 deletions cypress/fixtures/cat-fact.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"fact": "Cats have been domesticated for over 4,000 years.",
"length": 49
}
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": "hello@cypress.io",
"body": "Fixtures are a great way to mock data for responses to routes"
}
37 changes: 37 additions & 0 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/// <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>
// }
// }
// }
12 changes: 12 additions & 0 deletions cypress/support/component-index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>Components App</title>
</head>
<body>
<div data-cy-root></div>
</body>
</html>
37 changes: 37 additions & 0 deletions cypress/support/component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// ***********************************************************
// This example support/component.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";

import { mount } from "cypress/react";

// Augment the Cypress namespace to include type definitions for
// your custom command.
// Alternatively, can be defined in cypress/support/component.d.ts
// with a <reference path="./component" /> at the top of your spec.
declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace Cypress {
interface Chainable {
mount: typeof mount;
}
}
}

Cypress.Commands.add("mount", mount);

// Example use:
// cy.mount(<MyComponent />)
1 change: 1 addition & 0 deletions cypress/support/e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
"test": "vitest",
"start": "next start",
"test:ui": "vitest --ui",
"test:coverage": "vitest --coverage"
"test:coverage": "vitest --coverage.enabled --coverage.reportsDirectory ./coverage",
"cy:open": "cypress open",
"cy:run": "cypress run"
},
"dependencies": {
"@reduxjs/toolkit": "^2.8.2",
Expand All @@ -33,6 +35,7 @@
"@vitejs/plugin-react": "^4.0.0",
"@vitest/coverage-v8": "^3.2.4",
"@vitest/ui": "3.2.4",
"cypress": "^14.5.1",
"eslint": "^9.30.1",
"eslint-plugin-react-hooks": "^5.2.0",
"eslint-plugin-react-refresh": "^0.4.20",
Expand Down
Loading
Loading