Compare commits
5 commits
093b15c881
...
479e31987e
Author | SHA1 | Date | |
---|---|---|---|
479e31987e | |||
70571bdaf9 | |||
354674ad5c | |||
436d64d4cb | |||
ece3a3fd4c |
13 changed files with 1455 additions and 78 deletions
26
.github/workflows/tests.yml
vendored
Normal file
26
.github/workflows/tests.yml
vendored
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
name: tests
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
- renovate/*
|
||||||
|
pull_request:
|
||||||
|
jobs:
|
||||||
|
tests:
|
||||||
|
name: Tests
|
||||||
|
runs-on: docker
|
||||||
|
container:
|
||||||
|
image: ghcr.io/di0ik/forgejo_runner_container:main@sha256:672aee9a5dfc35531db3a218ad9486eb5c5d7d9ac10bdcba13110470c10403ee
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
|
||||||
|
|
||||||
|
- name: Enable corepack
|
||||||
|
run: corepack enable
|
||||||
|
|
||||||
|
- name: Cypress run
|
||||||
|
uses: cypress-io/github-action@v6
|
||||||
|
with:
|
||||||
|
build: yarn run build
|
||||||
|
start: yarn start
|
||||||
|
component: true
|
10
cypress.config.ts
Normal file
10
cypress.config.ts
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
import { defineConfig } from 'cypress';
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
component: {
|
||||||
|
devServer: {
|
||||||
|
framework: 'next',
|
||||||
|
bundler: 'webpack',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
5
cypress/fixtures/example.json
Normal file
5
cypress/fixtures/example.json
Normal 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"
|
||||||
|
}
|
62
cypress/support/commands.ts
Normal file
62
cypress/support/commands.ts
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
/// <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, ...args) => {
|
||||||
|
return cy.get(`[data-cy=${selector}]`, ...args);
|
||||||
|
});
|
||||||
|
|
||||||
|
Cypress.Commands.add('getBySelLike', (selector, ...args) => {
|
||||||
|
return cy.get(`[data-cy*=${selector}]`, ...args);
|
||||||
|
});
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
namespace Cypress {
|
||||||
|
interface Chainable {
|
||||||
|
getBySel(
|
||||||
|
selector: string,
|
||||||
|
...args: any[]
|
||||||
|
): Chainable<JQuery<HTMLElement>>;
|
||||||
|
getBySelLike(
|
||||||
|
selector: string,
|
||||||
|
...args: any[]
|
||||||
|
): Chainable<JQuery<HTMLElement>>;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export {};
|
14
cypress/support/component-index.html
Normal file
14
cypress/support/component-index.html
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
<!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>
|
||||||
|
<!-- Used by Next.js to inject CSS. -->
|
||||||
|
<div id="__next_css__DO_NOT_USE__"></div>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div data-cy-root></div>
|
||||||
|
</body>
|
||||||
|
</html>
|
38
cypress/support/component.ts
Normal file
38
cypress/support/component.ts
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
// ***********************************************************
|
||||||
|
// 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 '@/app/globals.css';
|
||||||
|
|
||||||
|
// 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 {
|
||||||
|
namespace Cypress {
|
||||||
|
interface Chainable {
|
||||||
|
mount: typeof mount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Cypress.Commands.add('mount', mount);
|
||||||
|
|
||||||
|
// Example use:
|
||||||
|
// cy.mount(<MyComponent />)
|
17
cypress/support/e2e.ts
Normal file
17
cypress/support/e2e.ts
Normal 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';
|
|
@ -5,9 +5,11 @@
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "next dev --turbopack",
|
"dev": "next dev --turbopack",
|
||||||
"build": "prettier --check . && next build",
|
"build": "prettier --check . && next build",
|
||||||
"start": "next start",
|
"start": "node .next/standalone/server.js",
|
||||||
"lint": "next lint",
|
"lint": "next lint",
|
||||||
"format": "prettier --write ."
|
"format": "prettier --write .",
|
||||||
|
"cypress:open": "cypress open",
|
||||||
|
"cypress:run": "cypress run"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@fortawesome/fontawesome-svg-core": "^6.7.2",
|
"@fortawesome/fontawesome-svg-core": "^6.7.2",
|
||||||
|
@ -40,6 +42,7 @@
|
||||||
"@types/node": "22.15.17",
|
"@types/node": "22.15.17",
|
||||||
"@types/react": "19.1.3",
|
"@types/react": "19.1.3",
|
||||||
"@types/react-dom": "19.1.4",
|
"@types/react-dom": "19.1.4",
|
||||||
|
"cypress": "14.3.3",
|
||||||
"eslint": "9.26.0",
|
"eslint": "9.26.0",
|
||||||
"eslint-config-next": "15.3.2",
|
"eslint-config-next": "15.3.2",
|
||||||
"eslint-config-prettier": "10.1.5",
|
"eslint-config-prettier": "10.1.5",
|
||||||
|
|
24
src/components/icon-button.cy.tsx
Normal file
24
src/components/icon-button.cy.tsx
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
/* eslint-disable @typescript-eslint/no-unused-expressions */
|
||||||
|
import React from 'react';
|
||||||
|
import { IconButton } from './icon-button';
|
||||||
|
import { faOpenid } from '@fortawesome/free-brands-svg-icons';
|
||||||
|
|
||||||
|
describe('<IconButton />', () => {
|
||||||
|
it('renders', () => {
|
||||||
|
cy.mount(<IconButton icon={faOpenid}>Button</IconButton>);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('is clickable', () => {
|
||||||
|
const onClick = cy.stub();
|
||||||
|
cy.mount(
|
||||||
|
<IconButton icon={faOpenid} onClick={onClick} data-cy='icon-button'>
|
||||||
|
Button
|
||||||
|
</IconButton>,
|
||||||
|
);
|
||||||
|
cy.getBySel('icon-button')
|
||||||
|
.click()
|
||||||
|
.then(() => {
|
||||||
|
expect(onClick).to.be.calledOnce;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
41
src/components/user/theme-picker.cy.tsx
Normal file
41
src/components/user/theme-picker.cy.tsx
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
import React from 'react';
|
||||||
|
import { ThemePicker } from '@/components/user/theme-picker';
|
||||||
|
import { ThemeProvider } from '../theme-provider';
|
||||||
|
|
||||||
|
describe('<ThemePicker />', () => {
|
||||||
|
it('renders', () => {
|
||||||
|
cy.mount(<ThemePicker />);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('toggle open and close', () => {
|
||||||
|
cy.mount(<ThemePicker />);
|
||||||
|
cy.getBySel('theme-picker').click();
|
||||||
|
cy.getBySel('theme-picker-content').should('exist');
|
||||||
|
cy.get('html').click();
|
||||||
|
cy.getBySel('theme-picker-content').should('not.exist');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('enable dark mode', () => {
|
||||||
|
cy.mount(
|
||||||
|
<ThemeProvider>
|
||||||
|
<ThemePicker />
|
||||||
|
</ThemeProvider>,
|
||||||
|
);
|
||||||
|
|
||||||
|
cy.getBySel('theme-picker').click();
|
||||||
|
cy.getBySel('dark-theme').click();
|
||||||
|
cy.get('html').should('have.attr', 'data-theme', 'dark');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('enable light mode', () => {
|
||||||
|
cy.mount(
|
||||||
|
<ThemeProvider>
|
||||||
|
<ThemePicker />
|
||||||
|
</ThemeProvider>,
|
||||||
|
);
|
||||||
|
|
||||||
|
cy.getBySel('theme-picker').click();
|
||||||
|
cy.getBySel('light-theme').click();
|
||||||
|
cy.get('html').should('have.attr', 'data-theme', 'light');
|
||||||
|
});
|
||||||
|
});
|
|
@ -18,20 +18,26 @@ export function ThemePicker() {
|
||||||
return (
|
return (
|
||||||
<DropdownMenu>
|
<DropdownMenu>
|
||||||
<DropdownMenuTrigger asChild>
|
<DropdownMenuTrigger asChild>
|
||||||
<Button variant='outline' size='icon'>
|
<Button variant='outline' size='icon' data-cy='theme-picker'>
|
||||||
<Sun className='h-[1.2rem] w-[1.2rem] rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0' />
|
<Sun className='h-[1.2rem] w-[1.2rem] rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0' />
|
||||||
<Moon className='absolute h-[1.2rem] w-[1.2rem] rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100' />
|
<Moon className='absolute h-[1.2rem] w-[1.2rem] rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100' />
|
||||||
<span className='sr-only'>Toggle theme</span>
|
<span className='sr-only'>Toggle theme</span>
|
||||||
</Button>
|
</Button>
|
||||||
</DropdownMenuTrigger>
|
</DropdownMenuTrigger>
|
||||||
<DropdownMenuContent align='end'>
|
<DropdownMenuContent align='end' data-cy='theme-picker-content'>
|
||||||
<DropdownMenuItem onClick={() => setTheme('light')}>
|
<DropdownMenuItem
|
||||||
|
onClick={() => setTheme('light')}
|
||||||
|
data-cy='light-theme'
|
||||||
|
>
|
||||||
Light
|
Light
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
<DropdownMenuItem onClick={() => setTheme('dark')}>
|
<DropdownMenuItem onClick={() => setTheme('dark')} data-cy='dark-theme'>
|
||||||
Dark
|
Dark
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
<DropdownMenuItem onClick={() => setTheme('system')}>
|
<DropdownMenuItem
|
||||||
|
onClick={() => setTheme('system')}
|
||||||
|
data-cy='system-theme'
|
||||||
|
>
|
||||||
System
|
System
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
</DropdownMenuContent>
|
</DropdownMenuContent>
|
||||||
|
|
|
@ -20,7 +20,8 @@
|
||||||
],
|
],
|
||||||
"paths": {
|
"paths": {
|
||||||
"@/*": ["./src/*"]
|
"@/*": ["./src/*"]
|
||||||
}
|
},
|
||||||
|
"types": ["node", "cypress"]
|
||||||
},
|
},
|
||||||
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
|
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
|
||||||
"exclude": ["node_modules"]
|
"exclude": ["node_modules"]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue