feat: migrate to Next.js for Mini App and enhance project structure

- Replaced the previous webapp with a new Mini App built using Next.js, improving performance and maintainability.
- Updated the `.gitignore` to exclude Next.js build artifacts and node modules.
- Revised documentation in `AGENTS.md`, `README.md`, and `architecture.md` to reflect the new Mini App structure and technology stack.
- Enhanced Dockerfile to support the new build process for the Next.js application.
- Updated CI workflow to build and test the Next.js application.
- Added new configuration options for the Mini App, including `MINI_APP_SHORT_NAME` for improved deep linking.
- Refactored frontend testing setup to accommodate the new structure and testing framework.
- Removed legacy webapp files and dependencies to streamline the project.
This commit is contained in:
2026-03-03 16:04:08 +03:00
parent 2de5c1cb81
commit 16bf1a1043
148 changed files with 20240 additions and 7270 deletions

View File

@@ -2,7 +2,7 @@
description: Rules for writing and running tests
globs:
- tests/**
- webapp/js/**/*.test.js
- webapp-next/src/**/*.test.{ts,tsx}
---
# Testing
@@ -51,48 +51,28 @@ def test_get_or_create_user_creates_new(test_db_url):
assert user.telegram_user_id == 123
```
## JavaScript tests (Vitest)
## Frontend tests (Vitest + React Testing Library)
### Configuration
- Config: `webapp/vitest.config.js`.
- Environment: `happy-dom` (lightweight DOM implementation).
- Test files: `webapp/js/**/*.test.js`.
- Run: `npm run test` (from `webapp/`).
- Config: `webapp-next/vitest.config.ts`.
- Environment: jsdom; React Testing Library for components.
- Test files: `webapp-next/src/**/*.test.{ts,tsx}` (co-located or in test files).
- Setup: `webapp-next/src/test/setup.ts`.
- Run: `cd webapp-next && npm test` (or `npm run test`).
### DOM setup
### Writing frontend tests
Modules that import from `dom.js` expect DOM elements to exist at import time.
Use `beforeAll` to set up the required HTML structure before the first import:
```js
import { beforeAll, describe, it, expect } from "vitest";
beforeAll(() => {
document.body.innerHTML = `
<div id="calendar"></div>
<h2 id="monthTitle"></h2>
<button id="prevBtn"></button>
<button id="nextBtn"></button>
<div id="dutyList"></div>
<div id="dayDetail"></div>
<div id="accessDenied" class="hidden"></div>
<div id="errorBanner" class="hidden"></div>
`;
});
```
### Writing JS tests
- File naming: `webapp/js/<module>.test.js` (co-located with the source module).
- Test pure functions first (`dateUtils`, `i18n`, `utils`); mock DOM for render tests.
- Use `describe` blocks to group by function, `it` blocks for individual cases.
- Pure lib modules: unit test with Vitest (`describe` / `it` / `expect`).
- React components: use `@testing-library/react` (render, screen, userEvent); wrap with required providers (e.g. TelegramProvider, store) via `src/test/test-utils.tsx` where needed.
- Mock Telegram SDK and API fetch where necessary.
- File naming: `<module>.test.ts` or `<Component>.test.tsx`.
### Example structure
```js
```ts
import { describe, it, expect } from "vitest";
import { localDateString } from "./dateUtils.js";
import { localDateString } from "./date-utils";
describe("localDateString", () => {
it("formats date as YYYY-MM-DD", () => {