Merge pull request 'test: integrate testing library' (#56)
Reviewed-on: #56 Reviewed-by: Maximilian Liebmann <lima@noreply.git.dominikstahl.dev>
This commit is contained in:
commit
0e24f7917b
21 changed files with 1396 additions and 39 deletions
6
.env.test
Normal file
6
.env.test
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
AUTH_SECRET="auth_secret"
|
||||||
|
AUTH_URL="http://127.0.0.1:3000"
|
||||||
|
HOSTNAME="127.0.0.1"
|
||||||
|
DATABASE_URL="file:/tmp/dev.db"
|
||||||
|
AUTH_AUTHENTIK_ID="id"
|
||||||
|
AUTH_AUTHENTIK_ISSUER="issuer"
|
34
.github/workflows/tests.yml
vendored
Normal file
34
.github/workflows/tests.yml
vendored
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
name: tests
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
- renovate/*
|
||||||
|
pull_request:
|
||||||
|
jobs:
|
||||||
|
tests:
|
||||||
|
name: Tests
|
||||||
|
runs-on: docker
|
||||||
|
container:
|
||||||
|
image: cypress/browsers:latest
|
||||||
|
options: --user 1001
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
|
||||||
|
|
||||||
|
- name: Enable corepack
|
||||||
|
run: corepack enable
|
||||||
|
|
||||||
|
- name: Cypress run (e2e)
|
||||||
|
uses: https://github.com/cypress-io/github-action@v6
|
||||||
|
with:
|
||||||
|
build: yarn cypress:build
|
||||||
|
start: yarn cypress:start_server
|
||||||
|
e2e: true
|
||||||
|
wait-on: 'http://127.0.0.1:3000'
|
||||||
|
|
||||||
|
- name: Cypress run (component)
|
||||||
|
uses: https://github.com/cypress-io/github-action@v6
|
||||||
|
with:
|
||||||
|
component: true
|
||||||
|
install: false
|
6
.gitignore
vendored
6
.gitignore
vendored
|
@ -33,6 +33,7 @@ yarn-error.log*
|
||||||
# env files (can opt-in for committing if needed)
|
# env files (can opt-in for committing if needed)
|
||||||
.env*
|
.env*
|
||||||
!.env.example
|
!.env.example
|
||||||
|
!.env.test
|
||||||
|
|
||||||
# vercel
|
# vercel
|
||||||
.vercel
|
.vercel
|
||||||
|
@ -45,3 +46,8 @@ next-env.d.ts
|
||||||
/prisma/*.db*
|
/prisma/*.db*
|
||||||
src/generated/*
|
src/generated/*
|
||||||
data
|
data
|
||||||
|
|
||||||
|
# cypress
|
||||||
|
cypress/videos
|
||||||
|
cypress/screenshots
|
||||||
|
cypress/coverage
|
||||||
|
|
16
cypress.config.ts
Normal file
16
cypress.config.ts
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
import { defineConfig } from 'cypress';
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
component: {
|
||||||
|
devServer: {
|
||||||
|
framework: 'next',
|
||||||
|
bundler: 'webpack',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
e2e: {
|
||||||
|
setupNodeEvents(on, config) {
|
||||||
|
// implement node event listeners here
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
12
cypress/e2e/auth-user.ts
Normal file
12
cypress/e2e/auth-user.ts
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
export default function authUser() {
|
||||||
|
cy.visit('http://127.0.0.1:3000/login');
|
||||||
|
cy.getBySel('login-header').should('exist');
|
||||||
|
cy.getBySel('login-form').should('exist');
|
||||||
|
cy.getBySel('email-input').should('exist');
|
||||||
|
cy.getBySel('password-input').should('exist');
|
||||||
|
cy.getBySel('login-button').should('exist');
|
||||||
|
cy.getBySel('email-input').type('cypress@example.com');
|
||||||
|
cy.getBySel('password-input').type('Password123!');
|
||||||
|
cy.getBySel('login-button').click();
|
||||||
|
cy.url().should('include', '/home');
|
||||||
|
}
|
9
cypress/e2e/event-create.cy.ts
Normal file
9
cypress/e2e/event-create.cy.ts
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
import authUser from './auth-user';
|
||||||
|
|
||||||
|
describe('event creation', () => {
|
||||||
|
it('loads', () => {
|
||||||
|
authUser();
|
||||||
|
|
||||||
|
// cy.visit('http://127.0.0.1:3000/events/new'); // TODO: Add event creation tests
|
||||||
|
});
|
||||||
|
});
|
45
cypress/e2e/login.cy.ts
Normal file
45
cypress/e2e/login.cy.ts
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
describe('login and register', () => {
|
||||||
|
it('loads', () => {
|
||||||
|
cy.visit('http://127.0.0.1:3000/');
|
||||||
|
|
||||||
|
cy.getBySel('login-header').should('exist');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('shows register form', () => {
|
||||||
|
cy.visit('http://127.0.0.1:3000/');
|
||||||
|
|
||||||
|
cy.getBySel('register-switch').click();
|
||||||
|
|
||||||
|
cy.getBySel('register-form').should('exist');
|
||||||
|
cy.getBySel('first-name-input').should('exist');
|
||||||
|
cy.getBySel('last-name-input').should('exist');
|
||||||
|
cy.getBySel('email-input').should('exist');
|
||||||
|
cy.getBySel('username-input').should('exist');
|
||||||
|
cy.getBySel('password-input').should('exist');
|
||||||
|
cy.getBySel('confirm-password-input').should('exist');
|
||||||
|
cy.getBySel('register-button').should('exist');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('allows to register', async () => {
|
||||||
|
cy.visit('http://127.0.0.1:3000/');
|
||||||
|
|
||||||
|
cy.getBySel('register-switch').click();
|
||||||
|
|
||||||
|
cy.getBySel('first-name-input').type('Test');
|
||||||
|
cy.getBySel('last-name-input').type('User');
|
||||||
|
cy.getBySel('email-input').type('test@example.com');
|
||||||
|
cy.getBySel('username-input').type('testuser');
|
||||||
|
cy.getBySel('password-input').type('Password123!');
|
||||||
|
cy.getBySel('confirm-password-input').type('Password123!');
|
||||||
|
cy.getBySel('register-button').click();
|
||||||
|
cy.getBySel('login-header').should('exist');
|
||||||
|
cy.getBySel('login-form').should('exist');
|
||||||
|
cy.getBySel('email-input').should('exist');
|
||||||
|
cy.getBySel('password-input').should('exist');
|
||||||
|
cy.getBySel('login-button').should('exist');
|
||||||
|
cy.getBySel('email-input').type('test@example.com');
|
||||||
|
cy.getBySel('password-input').type('Password123!');
|
||||||
|
cy.getBySel('login-button').click();
|
||||||
|
cy.url().should('include', '/home');
|
||||||
|
});
|
||||||
|
});
|
29
cypress/e2e/seed.ts
Normal file
29
cypress/e2e/seed.ts
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
import { PrismaClient } from '../../src/generated/prisma';
|
||||||
|
|
||||||
|
const prisma = new PrismaClient();
|
||||||
|
|
||||||
|
export default async function requireUser() {
|
||||||
|
await prisma.$transaction(async (tx) => {
|
||||||
|
const { id } = await tx.user.create({
|
||||||
|
data: {
|
||||||
|
email: 'cypress@example.com',
|
||||||
|
name: 'cypress',
|
||||||
|
password_hash:
|
||||||
|
'$2a$10$FmkVRHXzMb63dLHHwG1mDOepZJirL.U964wU/3Xr7cFis8XdRh8sO',
|
||||||
|
first_name: 'Cypress',
|
||||||
|
last_name: 'Tester',
|
||||||
|
emailVerified: new Date(),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await tx.account.create({
|
||||||
|
data: {
|
||||||
|
userId: id,
|
||||||
|
type: 'credentials',
|
||||||
|
provider: 'credentials',
|
||||||
|
providerAccountId: id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
requireUser();
|
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';
|
|
@ -22,16 +22,15 @@ async function exportSwagger() {
|
||||||
);
|
);
|
||||||
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
filesToImport.map((file) => {
|
filesToImport.map(async (file) => {
|
||||||
return import(file)
|
try {
|
||||||
.then((module) => {
|
const moduleImp = await import(file);
|
||||||
if (module.default) {
|
if (moduleImp.default) {
|
||||||
module.default(registry);
|
moduleImp.default(registry);
|
||||||
}
|
}
|
||||||
})
|
} catch (error) {
|
||||||
.catch((error) => {
|
|
||||||
console.error(`Error importing ${file}:`, error);
|
console.error(`Error importing ${file}:`, error);
|
||||||
});
|
}
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
"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 .",
|
||||||
"prisma:migrate": "dotenv -e .env.local -- prisma migrate dev",
|
"prisma:migrate": "dotenv -e .env.local -- prisma migrate dev",
|
||||||
|
@ -15,7 +15,11 @@
|
||||||
"prisma:migrate:reset": "dotenv -e .env.local -- prisma migrate reset",
|
"prisma:migrate:reset": "dotenv -e .env.local -- prisma migrate reset",
|
||||||
"dev_container": "docker compose -f docker-compose.dev.yml up --watch --build",
|
"dev_container": "docker compose -f docker-compose.dev.yml up --watch --build",
|
||||||
"swagger:generate": "ts-node -r tsconfig-paths/register exportSwagger.ts",
|
"swagger:generate": "ts-node -r tsconfig-paths/register exportSwagger.ts",
|
||||||
"orval:generate": "orval"
|
"orval:generate": "orval",
|
||||||
|
"cypress:build": "rm -rf /tmp/dev.db && DATABASE_URL=\"file:/tmp/dev.db\" yarn prisma:generate && yarn swagger:generate && yarn orval:generate && DATABASE_URL=\"file:/tmp/dev.db\" yarn prisma:db:push && prettier --check . && NODE_ENV=test next build",
|
||||||
|
"cypress:start_server": "DATABASE_URL=\"file:/tmp/dev.db\" ts-node cypress/e2e/seed.ts && cp .env.test .next/standalone && cp public .next/standalone/ -r && cp .next/static/ .next/standalone/.next/ -r && NODE_ENV=test HOSTNAME=\"0.0.0.0\" dotenv -e .env.test -- node .next/standalone/server.js",
|
||||||
|
"cypress:open": "cypress open",
|
||||||
|
"cypress:run": "cypress run"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@asteasolutions/zod-to-openapi": "^8.0.0-beta.4",
|
"@asteasolutions/zod-to-openapi": "^8.0.0-beta.4",
|
||||||
|
@ -63,6 +67,7 @@
|
||||||
"@types/react-dom": "19.1.6",
|
"@types/react-dom": "19.1.6",
|
||||||
"@types/swagger-ui-react": "5",
|
"@types/swagger-ui-react": "5",
|
||||||
"@types/webpack-env": "1.18.8",
|
"@types/webpack-env": "1.18.8",
|
||||||
|
"cypress": "14.5.0",
|
||||||
"dotenv-cli": "8.0.0",
|
"dotenv-cli": "8.0.0",
|
||||||
"eslint": "9.29.0",
|
"eslint": "9.29.0",
|
||||||
"eslint-config-next": "15.3.4",
|
"eslint-config-next": "15.3.4",
|
||||||
|
|
|
@ -33,7 +33,10 @@ export default async function LoginPage() {
|
||||||
</div>
|
</div>
|
||||||
<div className='mt-auto mb-auto'>
|
<div className='mt-auto mb-auto'>
|
||||||
<Card className='w-[350px] max-w-screen;'>
|
<Card className='w-[350px] max-w-screen;'>
|
||||||
<CardHeader className='grid place-items-center'>
|
<CardHeader
|
||||||
|
className='grid place-items-center'
|
||||||
|
data-cy='login-header'
|
||||||
|
>
|
||||||
<Logo colorType='colored' logoType='secondary'></Logo>
|
<Logo colorType='colored' logoType='secondary'></Logo>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent className='gap-6 flex flex-col items-center'>
|
<CardContent className='gap-6 flex flex-col items-center'>
|
||||||
|
@ -46,6 +49,7 @@ export default async function LoginPage() {
|
||||||
key={provider.id}
|
key={provider.id}
|
||||||
provider={provider.id}
|
provider={provider.id}
|
||||||
providerDisplayName={provider.name}
|
providerDisplayName={provider.name}
|
||||||
|
data-cy={'sso-login-button_' + provider.name.toLowerCase()}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</CardContent>
|
</CardContent>
|
||||||
|
|
|
@ -5,10 +5,11 @@ import { faOpenid } from '@fortawesome/free-brands-svg-icons';
|
||||||
export default function SSOLogin({
|
export default function SSOLogin({
|
||||||
provider,
|
provider,
|
||||||
providerDisplayName,
|
providerDisplayName,
|
||||||
|
...props
|
||||||
}: {
|
}: {
|
||||||
provider: string;
|
provider: string;
|
||||||
providerDisplayName: string;
|
providerDisplayName: string;
|
||||||
}) {
|
} & React.HTMLAttributes<HTMLButtonElement>) {
|
||||||
return (
|
return (
|
||||||
<form
|
<form
|
||||||
className='flex flex-col items-center w-full'
|
className='flex flex-col items-center w-full'
|
||||||
|
@ -22,6 +23,7 @@ export default function SSOLogin({
|
||||||
type='submit'
|
type='submit'
|
||||||
variant='secondary'
|
variant='secondary'
|
||||||
icon={faOpenid}
|
icon={faOpenid}
|
||||||
|
{...props}
|
||||||
>
|
>
|
||||||
Login with {providerDisplayName}
|
Login with {providerDisplayName}
|
||||||
</IconButton>
|
</IconButton>
|
||||||
|
|
|
@ -48,13 +48,18 @@ function LoginFormElement({
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form className='flex flex-col gap-5 w-full' onSubmit={onSubmit}>
|
<form
|
||||||
|
className='flex flex-col gap-5 w-full'
|
||||||
|
onSubmit={onSubmit}
|
||||||
|
data-cy='login-form'
|
||||||
|
>
|
||||||
<LabeledInput
|
<LabeledInput
|
||||||
type='text'
|
type='text'
|
||||||
label='E-Mail or Username'
|
label='E-Mail or Username'
|
||||||
placeholder='What you are known as'
|
placeholder='What you are known as'
|
||||||
error={formState.errors.email?.message}
|
error={formState.errors.email?.message}
|
||||||
{...register('email')}
|
{...register('email')}
|
||||||
|
data-cy='email-input'
|
||||||
/>
|
/>
|
||||||
<LabeledInput
|
<LabeledInput
|
||||||
type='password'
|
type='password'
|
||||||
|
@ -62,9 +67,10 @@ function LoginFormElement({
|
||||||
placeholder="Let's hope you remember it"
|
placeholder="Let's hope you remember it"
|
||||||
error={formState.errors.password?.message}
|
error={formState.errors.password?.message}
|
||||||
{...register('password')}
|
{...register('password')}
|
||||||
|
data-cy='password-input'
|
||||||
/>
|
/>
|
||||||
<div className='grid grid-rows-2 gap-2'>
|
<div className='grid grid-rows-2 gap-2'>
|
||||||
<Button type='submit' variant='primary'>
|
<Button type='submit' variant='primary' data-cy='login-button'>
|
||||||
Login
|
Login
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
|
@ -74,6 +80,7 @@ function LoginFormElement({
|
||||||
formRef?.current?.reset();
|
formRef?.current?.reset();
|
||||||
setIsSignUp((v) => !v);
|
setIsSignUp((v) => !v);
|
||||||
}}
|
}}
|
||||||
|
data-cy='register-switch'
|
||||||
>
|
>
|
||||||
Sign Up
|
Sign Up
|
||||||
</Button>
|
</Button>
|
||||||
|
@ -129,6 +136,7 @@ function RegisterFormElement({
|
||||||
ref={formRef}
|
ref={formRef}
|
||||||
className='flex flex-col gap-5 w-full'
|
className='flex flex-col gap-5 w-full'
|
||||||
onSubmit={onSubmit}
|
onSubmit={onSubmit}
|
||||||
|
data-cy='register-form'
|
||||||
>
|
>
|
||||||
<LabeledInput
|
<LabeledInput
|
||||||
type='text'
|
type='text'
|
||||||
|
@ -137,6 +145,7 @@ function RegisterFormElement({
|
||||||
autocomplete='given-name'
|
autocomplete='given-name'
|
||||||
error={formState.errors.firstName?.message}
|
error={formState.errors.firstName?.message}
|
||||||
{...register('firstName')}
|
{...register('firstName')}
|
||||||
|
data-cy='first-name-input'
|
||||||
/>
|
/>
|
||||||
<LabeledInput
|
<LabeledInput
|
||||||
type='text'
|
type='text'
|
||||||
|
@ -145,6 +154,7 @@ function RegisterFormElement({
|
||||||
autocomplete='family-name'
|
autocomplete='family-name'
|
||||||
error={formState.errors.lastName?.message}
|
error={formState.errors.lastName?.message}
|
||||||
{...register('lastName')}
|
{...register('lastName')}
|
||||||
|
data-cy='last-name-input'
|
||||||
/>
|
/>
|
||||||
<LabeledInput
|
<LabeledInput
|
||||||
type='email'
|
type='email'
|
||||||
|
@ -153,6 +163,7 @@ function RegisterFormElement({
|
||||||
autocomplete='email'
|
autocomplete='email'
|
||||||
error={formState.errors.email?.message}
|
error={formState.errors.email?.message}
|
||||||
{...register('email')}
|
{...register('email')}
|
||||||
|
data-cy='email-input'
|
||||||
/>
|
/>
|
||||||
<LabeledInput
|
<LabeledInput
|
||||||
type='text'
|
type='text'
|
||||||
|
@ -161,6 +172,7 @@ function RegisterFormElement({
|
||||||
autocomplete='username'
|
autocomplete='username'
|
||||||
error={formState.errors.username?.message}
|
error={formState.errors.username?.message}
|
||||||
{...register('username')}
|
{...register('username')}
|
||||||
|
data-cy='username-input'
|
||||||
/>
|
/>
|
||||||
<LabeledInput
|
<LabeledInput
|
||||||
type='password'
|
type='password'
|
||||||
|
@ -169,6 +181,7 @@ function RegisterFormElement({
|
||||||
autocomplete='new-password'
|
autocomplete='new-password'
|
||||||
error={formState.errors.password?.message}
|
error={formState.errors.password?.message}
|
||||||
{...register('password')}
|
{...register('password')}
|
||||||
|
data-cy='password-input'
|
||||||
/>
|
/>
|
||||||
<LabeledInput
|
<LabeledInput
|
||||||
type='password'
|
type='password'
|
||||||
|
@ -177,9 +190,10 @@ function RegisterFormElement({
|
||||||
autocomplete='new-password'
|
autocomplete='new-password'
|
||||||
error={formState.errors.confirmPassword?.message}
|
error={formState.errors.confirmPassword?.message}
|
||||||
{...register('confirmPassword')}
|
{...register('confirmPassword')}
|
||||||
|
data-cy='confirm-password-input'
|
||||||
/>
|
/>
|
||||||
<div className='grid grid-rows-2 gap-2'>
|
<div className='grid grid-rows-2 gap-2'>
|
||||||
<Button type='submit' variant='primary'>
|
<Button type='submit' variant='primary' data-cy='register-button'>
|
||||||
Sign Up
|
Sign Up
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
|
|
41
src/components/misc/theme-picker.cy.tsx
Normal file
41
src/components/misc/theme-picker.cy.tsx
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
import React from 'react';
|
||||||
|
import { ThemePicker } from '@/components/misc/theme-picker';
|
||||||
|
import { ThemeProvider } from '@/components/wrappers/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_primary' size='icon'>
|
<Button variant='outline_primary' 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", "@types/webpack-env"]
|
||||||
},
|
},
|
||||||
"ts-node": {
|
"ts-node": {
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue