Initial commit

This commit is contained in:
2026-03-10 21:30:52 -03:00
commit 72a4f0be26
145 changed files with 14881 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
import { react } from '@dwellops/config/eslint';
export default react;

View File

@@ -0,0 +1,33 @@
{
"name": "@dwellops/test-utils",
"version": "0.0.0",
"private": true,
"type": "module",
"exports": {
".": {
"types": "./src/index.ts",
"default": "./src/index.ts"
}
},
"scripts": {
"lint": "eslint src",
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@dwellops/types": "workspace:*"
},
"devDependencies": {
"typescript": "catalog:",
"eslint": "catalog:",
"@types/node": "catalog:",
"@dwellops/config": "workspace:*",
"vitest": "catalog:",
"@testing-library/react": "catalog:",
"@testing-library/user-event": "catalog:",
"@testing-library/jest-dom": "catalog:",
"react": "catalog:",
"react-dom": "catalog:",
"@types/react": "catalog:",
"@types/react-dom": "catalog:"
}
}

View File

@@ -0,0 +1,96 @@
import type {
AuthUser,
Hoa,
HoaId,
Membership,
MembershipId,
Unit,
UnitId,
UserId,
} from '@dwellops/types';
let _idCounter = 1;
/**
* Generates a deterministic test ID string.
* Resets on module re-import; do not rely on specific values across test files.
*/
function nextId(prefix: string): string {
return `${prefix}_test_${String(_idCounter++).padStart(4, '0')}`;
}
/**
* Resets the ID counter. Call in beforeEach if deterministic IDs matter.
*/
export function resetIdCounter(): void {
_idCounter = 1;
}
/**
* Creates a mock AuthUser. All fields are overridable.
*
* @param overrides - Partial AuthUser fields to override.
*/
export function makeUser(overrides: Partial<AuthUser> = {}): AuthUser {
return {
id: nextId('user') as UserId,
email: 'test@example.com',
name: 'Test User',
emailVerified: true,
image: null,
...overrides,
};
}
/**
* Creates a mock Hoa record.
*
* @param overrides - Partial Hoa fields to override.
*/
export function makeHoa(overrides: Partial<Hoa> = {}): Hoa {
const id = nextId('hoa') as HoaId;
return {
id,
name: 'Test HOA',
slug: `test-hoa-${id}`,
description: null,
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
...overrides,
};
}
/**
* Creates a mock Unit record.
*
* @param overrides - Partial Unit fields to override.
*/
export function makeUnit(overrides: Partial<Unit> = {}): Unit {
return {
id: nextId('unit') as UnitId,
hoaId: nextId('hoa') as HoaId,
identifier: '101',
address: null,
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
...overrides,
};
}
/**
* Creates a mock Membership record.
*
* @param overrides - Partial Membership fields to override.
*/
export function makeMembership(overrides: Partial<Membership> = {}): Membership {
return {
id: nextId('membership') as MembershipId,
userId: nextId('user') as UserId,
hoaId: nextId('hoa') as HoaId,
unitId: null,
role: 'OWNER',
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
...overrides,
};
}

View File

@@ -0,0 +1,2 @@
export * from './factories';
export * from './render';

View File

@@ -0,0 +1,25 @@
import type { ReactElement } from 'react';
import { render as tlRender } from '@testing-library/react';
import type { RenderOptions, RenderResult } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
export type { RenderResult };
/**
* Wrapped render helper that sets up userEvent alongside the render.
* Prefer this over @testing-library/react render directly.
*
* @param ui - The React element to render.
* @param options - Optional Testing Library render options.
* @returns Render result plus a `user` userEvent instance.
*/
export function render(
ui: ReactElement,
options?: RenderOptions,
): RenderResult & { user: ReturnType<typeof userEvent.setup> } {
const user = userEvent.setup();
const result = tlRender(ui, options);
return { ...result, user };
}
export { screen, within, fireEvent, waitFor, act } from '@testing-library/react';

View File

@@ -0,0 +1,10 @@
{
"extends": "@dwellops/config/tsconfig/react-library.json",
"compilerOptions": {
"outDir": "./dist",
"rootDir": "./src",
"noEmit": true,
"lib": ["ES2022", "DOM"]
},
"include": ["src"]
}