A small Next.js app that renders an interactive price table for Raksul’s paper printing. It follows a feature‑first architecture and ships with unit tests (Jest + RTL) and end‑to‑end tests (Playwright).
- Node.js 18+ (recommended 20 LTS)
- npm 9+ (ships with Node 18+)
- Modern browser (Chrome/Firefox/Edge latest)
- Copy environment file
- Copy .env.example to .env.local
- Adjust
NEXT_PUBLIC_API_BASE_URLif your API runs on a different host/port.
- Install dependencies
npm install
- Start the dev server
npm run dev- Open http://localhost:3000
- Run tests
- Unit tests:
npm test - E2E tests:
npm run test:e2e
NEXT_PUBLIC_API_BASE_URL: Base URL for the pricing API. Must be defined in.env.local(prefixed with NEXT_PUBLIC so it’s available in the browser). Example:NEXT_PUBLIC_API_BASE_URL=https://raksul-functions.example.com
- The app calls
GET {BASE_URL}/prices?paper_size=<A4|A5|B4|B5>.
npm run dev— Start Next.js in development mode.npm run build— Production build.npm start— Start the production server after build.npm test— Run Jest unit tests (jsdom environment).npm run test:e2e— Run Playwright tests.npm run lint— Run ESLint.npm run prepare— Setup Husky git hooks (optional).
src/features/priceTablecomponents/— UI pieces: Paper size select, grid, order barcontainers/— Composes feature, wires hooks, and storehooks/— Data fetching with React Querymisc/— Constants and typesstore/— Redux slice
src/sharedproviders/— App‑level providers (Redux, React Query)store/— Redux storeutils/— Shared utilities (e.g., number formatting)
src/app— Next.js App Router entry pointstests-e2e— Playwright teststest— Jest setup and unit tests
- Data fetching:
usePriceshook callsGET /prices?paper_size=...using Axios via React Query. Responses are cached and requests are deduplicated. - State management: Redux Toolkit stores UI state (paper size, selected cell, expanded rows). Derived UI updates are driven by slice actions/selectors.
- UI: Material UI (MUI) components with Emotion styling; Tailwind utility classes are used for layout scaffolding where convenient.
- Number formatting:
src/shared/utils/numbers.tsimplements a custom comma‑insertion algorithm to format positive integers withouttoLocaleString/Intl.NumberFormat.
- The table shows quantities (rows) vs business days (columns).
- Hover highlights a cell and lightly its row/column.
- Click selects a cell; the selection is outlined and the price appears on the Order bar.
- “See more” expands hidden quantity rows (first 5 are shown initially).
- Next.js (App Router)
- Server rendering, routing, and asset pipeline are built‑in and production‑ready.
- App Router aligns well with React 18+/19 concurrent features and file‑system routing.
- React Query (@tanstack/react-query)
- Provides stale‑while‑revalidate, cache, retries, request dedupe, and background updates with minimal code.
- More granular cache control and mutations than SWR for complex UI states.
- Redux Toolkit (+ redux‑thunk)
- Co‑locates feature reducers/slices with minimal boilerplate and immutable updates out of the box.
- Great devtools and ecosystem; explicit UI state management keeps fetch/cache concerns in React Query.
- MUI (with Emotion)
- MUI offers accessible, themed components (Select, Grid, Typography) that accelerate delivery.
- Emotion integration enables flexible styling; Tailwind remains for quick layout utilities.
- Axios
- Interceptors, timeout, and consistent JSON handling make API code concise and testable.
- Jest + React Testing Library
- jsdom environment matches component behavior; RTL encourages testing user interactions over implementation details.
- Playwright
- Cross‑browser by default (Chromium/Firefox/WebKit), powerful auto‑waits, great parallelization for CI.
- Unit:
npm testruns Jest. Seetest/setupTests.tsfor RTL setup. - E2E:
npm run test:e2eruns Playwright tests intests-e2e/.- To run headed mode:
npx playwright test --headed - To update screenshots (if any):
npx playwright test --update-snapshots
- To run headed mode:
- 404/Network error: Ensure
NEXT_PUBLIC_API_BASE_URLpoints to the correct backend and that CORS is allowed for http://localhost:3000. - Port already in use: stop other processes on 3000 or run
PORT=3001 npm run dev(Windows PowerShell:$env:PORT=3001; npm run dev). - Empty table: Verify API returns data for your chosen
paper_size(A4/A5/B4/B5).
- Works on latest Chrome/Firefox/Edge.
- Enable Husky with
npm run prepareto attach git hooks (e.g., run lint/tests pre‑commit). - Algorithm sources: the number‑format utility uses a standard reverse‑chunk (3‑digit) technique.
See LICENSE.