diff --git a/TESTING.md b/TESTING.md new file mode 100644 index 0000000..e798d7f --- /dev/null +++ b/TESTING.md @@ -0,0 +1,53 @@ +# Running Storefront Tests (`acupedia_store_ui`) + +All commands below should be run from the `acupedia_store_ui/` directory: + +```bash +cd acupedia_store_ui +``` + +--- + +## 1. Prerequisites (First Time Only) +If dependencies or Playwright browsers are not installed yet: + +```bash +npm install +npx playwright install chromium +``` + +--- + +## 2. Run Playwright E2E Tests + +### Run all E2E tests (headless, Desktop + Mobile) +```bash +npm run test:e2e +``` +> Playwright automatically starts the Vite dev server on `http://localhost:3000/store/` if it is not already running. + +### Run in Interactive UI Mode (recommended for watching & debugging) +```bash +npm run test:e2e:ui +``` + +### Run in Headed Mode (watch the browser window) +```bash +npm run test:e2e:headed +``` + +### Run a specific test file +```bash +npx playwright test tests/e2e/smoke.spec.ts +``` + +### Run only Desktop or only Mobile +```bash +npx playwright test --project=chromium-desktop +npx playwright test --project=chromium-mobile +``` + +### View the HTML Test Report (after a run) +```bash +npm run test:e2e:report +``` diff --git a/package-lock.json b/package-lock.json index 03498b4..17ff48b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,22 +18,35 @@ "@eslint/js": "^9.0.0", "@playwright/test": "^1.65.1", "@tailwindcss/postcss": "^4.0.0", + "@testing-library/jest-dom": "^8.0.0", + "@testing-library/react": "^16.3.3", + "@testing-library/user-event": "^14.6.13", "@types/node": "^22.0.0", "@types/react": "^19.0.0", "@types/react-dom": "^19.0.0", "@vitejs/plugin-react": "^4.3.0", + "@vitest/coverage-v8": "^5.1.2", "autoprefixer": "^10.4.0", "eslint": "^9.0.0", "eslint-plugin-react-hooks": "^5.0.0", "eslint-plugin-react-refresh": "^0.4.0", "globals": "^15.0.0", + "jsdom": "^31.0.1", "postcss": "^8.4.0", "tailwindcss": "^4.0.0", "typescript": "^5.8.0", "typescript-eslint": "^8.0.0", - "vite": "^6.0.0" + "vite": "^6.0.0", + "vitest": "^5.1.2" } }, + "node_modules/@adobe/css-tools": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/@adobe/css-tools/-/css-tools-4.5.0.tgz", + "integrity": "sha512-6OzddxPio9UiWTCemp4N8cYLV2ZN1ncRnV1cVGtve7dhPOtRkleRyx32GQCYSwDYgaHU3USMm84tNsvKzRCa1Q==", + "dev": true, + "license": "MIT" + }, "node_modules/@alloc/quick-lru": { "version": "5.2.0", "resolved": "https://registry.npmjs.org/@alloc/quick-lru/-/quick-lru-5.2.0.tgz", @@ -281,6 +294,16 @@ "@babel/core": "^7.0.0-0" } }, + "node_modules/@babel/runtime": { + "version": "7.29.15", + "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.29.15.tgz", + "integrity": "sha512-304gsbbGVmQc+cNGHzwHBlqepYdWLKj3VXCQBGt/EGcV7PUPfKI7kAUNW1FZEOCwlQiLvQjg1JEaAlRQ616h+Q==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6.9.0" + } + }, "node_modules/@babel/template": { "version": "7.29.7", "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.29.7.tgz", @@ -329,6 +352,16 @@ "node": ">=6.9.0" } }, + "node_modules/@bcoe/v8-coverage": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@bcoe/v8-coverage/-/v8-coverage-1.0.2.tgz", + "integrity": "sha512-6zABk/ECA/QYSCQ1NGiVwwbQerUCZ+TQbp64Q3AgmfNvurHH0j8TtXa1qbShXA6qqkpAj4V5W8pP6mLe1mcMqA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + } + }, "node_modules/@emnapi/core": { "version": "1.10.0", "resolved": "https://registry.npmjs.org/@emnapi/core/-/core-1.10.0.tgz", @@ -1024,6 +1057,24 @@ "node": "^18.18.0 || ^20.9.0 || >=21.1.0" } }, + "node_modules/@exodus/bytes": { + "version": "1.16.0", + "resolved": "https://registry.npmjs.org/@exodus/bytes/-/bytes-1.16.0.tgz", + "integrity": "sha512-IcpW84uEn3N7ETtNZMlxKhfl6Pec8rUNGOTBtWbK1FKhJxIFAptZyVrvVRVBimAJxJCgc3PxepxkdWWG4DVzfA==", + "dev": true, + "license": "MIT", + "engines": { + "node": "^20.19.0 || ^22.12.0 || >=24.0.0" + }, + "peerDependencies": { + "@noble/hashes": "^1.8.0 || ^2.0.0" + }, + "peerDependenciesMeta": { + "@noble/hashes": { + "optional": true + } + } + }, "node_modules/@humanfs/core": { "version": "0.19.2", "resolved": "https://registry.npmjs.org/@humanfs/core/-/core-0.19.2.tgz", @@ -1123,9 +1174,9 @@ } }, "node_modules/@jridgewell/sourcemap-codec": { - "version": "1.5.5", - "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.5.tgz", - "integrity": "sha512-cYQ9310grqxueWbl+WuIUIaiUaDcj7WOq5fVhEljNVgRfOUhY9fy2zTvfoqWsnebh8Sl70VScFbICvJnLKB0Og==", + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.6.0.tgz", + "integrity": "sha512-T7jf+5zgsZHwNJ4lvQ7/aezbyk0nNX+zJVWpmHA7VYsEx7a7qr5Rg5IbtJFqkgze5Y2sruq1RUY8Q837Od7iFw==", "dev": true, "license": "MIT" }, @@ -1862,6 +1913,105 @@ "tailwindcss": "4.3.0" } }, + "node_modules/@testing-library/dom": { + "version": "10.4.2", + "resolved": "https://registry.npmjs.org/@testing-library/dom/-/dom-10.4.2.tgz", + "integrity": "sha512-yzr2S9HyAIdhz2/6qHgbs665Q7PKVcDF05vsOlHPxG1mo36gKVesdYVeDLnXgfjJ03CrKRk08knc6+E/9m8v2Q==", + "dev": true, + "license": "MIT", + "peer": true, + "dependencies": { + "@babel/code-frame": "^7.10.4", + "@babel/runtime": "^7.12.5", + "@types/aria-query": "^5.0.1", + "aria-query": "5.3.0", + "dom-accessibility-api": "^0.5.9", + "lz-string": "^1.5.0", + "picocolors": "1.1.1", + "pretty-format": "^27.0.2" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/@testing-library/jest-dom": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/@testing-library/jest-dom/-/jest-dom-8.0.0.tgz", + "integrity": "sha512-Nu45KEeFgP/ydCMipnisMblq6YHViqEFi3fKN0a40s+zdKDDD7vEPCEavS0i7i4RxmclcEIL8q2o42pu+WgNgg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@adobe/css-tools": "^4.4.0", + "aria-query": "^5.0.0", + "css.escape": "^1.5.1", + "dom-accessibility-api": "^0.6.3", + "picocolors": "^1.1.1", + "redent": "^3.0.0" + }, + "engines": { + "node": ">=22", + "npm": ">=6", + "yarn": ">=1" + }, + "peerDependencies": { + "@testing-library/dom": ">=10 <11", + "vitest": ">=5 <6" + }, + "peerDependenciesMeta": { + "vitest": { + "optional": true + } + } + }, + "node_modules/@testing-library/jest-dom/node_modules/dom-accessibility-api": { + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/dom-accessibility-api/-/dom-accessibility-api-0.6.3.tgz", + "integrity": "sha512-7ZgogeTnjuHbo+ct10G9Ffp0mif17idi0IyWNVA/wcwcm7NPOD/WEHVP3n7n3MhXqxoIYm8d6MuZohYWIZ4T3w==", + "dev": true, + "license": "MIT" + }, + "node_modules/@testing-library/react": { + "version": "16.3.3", + "resolved": "https://registry.npmjs.org/@testing-library/react/-/react-16.3.3.tgz", + "integrity": "sha512-Uo193NgQbPMz6lrrhtRQQFcMC6Re/ELLFbbuVL30WDlZxlpZf9/lMHTAVxPRLw1q1iu9OJmR1c2BLiENRstdBg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/runtime": "^7.12.5" + }, + "engines": { + "node": ">=18" + }, + "peerDependencies": { + "@testing-library/dom": "^10.0.0", + "@types/react": "^18.0.0 || ^19.0.0", + "@types/react-dom": "^18.0.0 || ^19.0.0", + "react": "^18.0.0 || ^19.0.0", + "react-dom": "^18.0.0 || ^19.0.0" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "@types/react-dom": { + "optional": true + } + } + }, + "node_modules/@testing-library/user-event": { + "version": "14.6.13", + "resolved": "https://registry.npmjs.org/@testing-library/user-event/-/user-event-14.6.13.tgz", + "integrity": "sha512-2LVZGptuB5un1Cu/u31o9adkCwbsUTMp4B4p04xupI7uobvTIpgKidSdShqZiReo/mQmvR9xjgdgTgge4oAbYA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12", + "npm": ">=6" + }, + "peerDependencies": { + "@testing-library/dom": ">=7.21.4" + } + }, "node_modules/@tybys/wasm-util": { "version": "0.10.2", "resolved": "https://registry.npmjs.org/@tybys/wasm-util/-/wasm-util-0.10.2.tgz", @@ -1873,6 +2023,14 @@ "tslib": "^2.4.0" } }, + "node_modules/@types/aria-query": { + "version": "5.0.4", + "resolved": "https://registry.npmjs.org/@types/aria-query/-/aria-query-5.0.4.tgz", + "integrity": "sha512-rfT93uj5s0PRL7EzccGMs3brplhcrghnDoV26NqKhCAS1hVo+WdNsPvE/yb6ilfr5hi2MEk6d5EWJTKdxg8jVw==", + "dev": true, + "license": "MIT", + "peer": true + }, "node_modules/@types/babel__core": { "version": "7.20.5", "resolved": "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.20.5.tgz", @@ -1918,6 +2076,24 @@ "@babel/types": "^7.28.2" } }, + "node_modules/@types/chai": { + "version": "5.2.3", + "resolved": "https://registry.npmjs.org/@types/chai/-/chai-5.2.3.tgz", + "integrity": "sha512-Mw558oeA9fFbv65/y4mHtXDs9bPnFMZAL/jxdPFUpOHHIXX91mcgEHbS5Lahr+pwZFR8A7GQleRWeI6cGFC2UA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/deep-eql": "*", + "assertion-error": "^2.0.1" + } + }, + "node_modules/@types/deep-eql": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/@types/deep-eql/-/deep-eql-4.0.2.tgz", + "integrity": "sha512-c9h9dVVMigMPc4bwTvC5dxqtqJZwQPePsWjPlpSOnojbor6pGqdk541lfA7AqFQr5pB1BRdq0juY9db81BwyFw==", + "dev": true, + "license": "MIT" + }, "node_modules/@types/estree": { "version": "1.0.9", "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.9.tgz", @@ -2226,6 +2402,106 @@ "vite": "^4.2.0 || ^5.0.0 || ^6.0.0 || ^7.0.0" } }, + "node_modules/@vitest/coverage-v8": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/@vitest/coverage-v8/-/coverage-v8-5.1.2.tgz", + "integrity": "sha512-VG0JLv0T4kr1fR6QAfe8PTou+Frc4t0u4j+oKgDH3djJpFawzBfGyX14/z56NXoCTNem3OEphzCJhc4DkE62xQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@bcoe/v8-coverage": "^1.0.2", + "@vitest/istanbul-lib-coverage": "^2.1.1", + "@vitest/istanbul-lib-report": "^2.1.1", + "ast-v8-to-istanbul": "^1.0.8", + "magicast": "^0.5.5", + "obug": "^3.0.0", + "std-env": "^4.3.0", + "tinyrainbow": "^3.2.0" + }, + "funding": { + "url": "https://opencollective.com/vitest" + }, + "peerDependencies": { + "@vitest/browser": "5.1.2", + "vitest": "5.1.2" + }, + "peerDependenciesMeta": { + "@vitest/browser": { + "optional": true + } + } + }, + "node_modules/@vitest/istanbul-lib-coverage": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/@vitest/istanbul-lib-coverage/-/istanbul-lib-coverage-2.1.1.tgz", + "integrity": "sha512-pF9nMHHuyQzyEXdkWX3d4wElEKjymfL5TEoofegJn/jK2WjmTLOcJKfJ7/YwYGYdbZf8Ebrt4VDUoBPiTuO9zg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=22" + } + }, + "node_modules/@vitest/istanbul-lib-report": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/@vitest/istanbul-lib-report/-/istanbul-lib-report-2.1.1.tgz", + "integrity": "sha512-Qba+8OpQQAbWrmq3u1olh6jqE/vyW4OYJe6TLrrTBpXhjJhbY7Os69wyVvMQmNA64KJhGd5nQ/c7l4io8tPCHQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@vitest/istanbul-lib-coverage": "2.1.1" + }, + "engines": { + "node": ">=22" + } + }, + "node_modules/@vitest/mocker": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/@vitest/mocker/-/mocker-5.1.2.tgz", + "integrity": "sha512-UGc97wUIy0Ji2+9GxzHEJiOhiwkaukgE7VYcUNnjpX3sWnwQ8XogmNXX4WyOukxYgKb8Nh2XFa7KId0ZjpmVhQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@jridgewell/trace-mapping": "0.3.31", + "@vitest/spy": "5.1.2", + "estree-walker": "^3.0.3", + "magic-string": "^1.4.5" + }, + "funding": { + "url": "https://opencollective.com/vitest" + }, + "peerDependencies": { + "msw": "^2.4.9 || ^3.0.0", + "vite": "^6.0.0 || ^7.0.0 || ^8.0.0" + }, + "peerDependenciesMeta": { + "msw": { + "optional": true + }, + "vite": { + "optional": true + } + } + }, + "node_modules/@vitest/mocker/node_modules/magic-string": { + "version": "1.4.5", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-1.4.5.tgz", + "integrity": "sha512-oLLC2+YvQUfAa+vxoufE/yc1icb87M9iXIRqAoR/2EhE/8cb3SF/+Gi0c2By1B+5Vz2e2vQtUvHiu1+63Znh+w==", + "dev": true, + "license": "MIT", + "dependencies": { + "@jridgewell/sourcemap-codec": "^1.6.0" + } + }, + "node_modules/@vitest/spy": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/@vitest/spy/-/spy-5.1.2.tgz", + "integrity": "sha512-PQl0/3+p9GaY71+MHywN6oyHfLhVDD5kcbm7oNRldA2F0ExMU3S8RQdnpteJ9gFAdK5P6KCgE6LqCpUgy57KzA==", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://opencollective.com/vitest" + } + }, "node_modules/acorn": { "version": "8.18.0", "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.18.0.tgz", @@ -2278,6 +2554,17 @@ "url": "https://github.com/sponsors/epoberezkin" } }, + "node_modules/ansi-regex": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "dev": true, + "license": "MIT", + "peer": true, + "engines": { + "node": ">=8" + } + }, "node_modules/ansi-styles": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", @@ -2301,6 +2588,45 @@ "dev": true, "license": "Python-2.0" }, + "node_modules/aria-query": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/aria-query/-/aria-query-5.3.0.tgz", + "integrity": "sha512-b0P0sZPKtyu8HkeRAfCq0IfURZK+SuwMjY1UXGBU27wpAiTwQAIlq56IbIO+ytk/JjS1fMR14ee5WBBfKi5J6A==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "dequal": "^2.0.3" + } + }, + "node_modules/assertion-error": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-2.0.1.tgz", + "integrity": "sha512-Izi8RQcffqCeNVgFigKli1ssklIbpHnCYc6AknXGYoB6grJqyeby7jv12JUQgmTAnIDnbck1uxksT4dzN3PWBA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12" + } + }, + "node_modules/ast-v8-to-istanbul": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/ast-v8-to-istanbul/-/ast-v8-to-istanbul-1.0.8.tgz", + "integrity": "sha512-lPdpagk13ANXV+HClJEpCZM7kUsl5XcvgqKzZhaj6Ve1ZFICcY2sGhAN1n1vT0tML6EclT7bfVgTxqL57Gkpow==", + "dev": true, + "license": "MIT", + "dependencies": { + "@jridgewell/trace-mapping": "^0.3.31", + "estree-walker": "^3.0.3", + "js-tokens": "^10.0.0" + } + }, + "node_modules/ast-v8-to-istanbul/node_modules/js-tokens": { + "version": "10.0.2", + "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-10.0.2.tgz", + "integrity": "sha512-DXL98F5NsFBwDz7kcb4UUlrg9ePDgBCPjK4inUYi5gahxsTrKNW8Oh6F3WAuh7hntbP41EL/DkUYccRsDfLQLQ==", + "dev": true, + "license": "MIT" + }, "node_modules/asynckit": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", @@ -2379,6 +2705,33 @@ "node": ">=6.0.0" } }, + "node_modules/bcp-47": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/bcp-47/-/bcp-47-2.1.2.tgz", + "integrity": "sha512-wsv86UuNFuPnVieKLyECTT+CP1WSAHeoIg5P3xu2kA9Z+7fVPoKt7dxzSeEhtJel0AI+NW3fIW3KtTKQKUCngg==", + "dev": true, + "license": "MIT", + "dependencies": { + "is-alphabetical": "^2.0.0", + "is-alphanumerical": "^2.0.0", + "is-decimal": "^2.0.0" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } + }, + "node_modules/bcp-47-match": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/bcp-47-match/-/bcp-47-match-2.0.3.tgz", + "integrity": "sha512-JtTezzbAibu8G0R9op9zb3vcWZd9JF6M0xOYGPn0fNCd7wOpRB1mU2mH9T8gaBGbAAyIIVgB2G7xG0GP98zMAQ==", + "dev": true, + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } + }, "node_modules/brace-expansion": { "version": "5.0.9", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.9.tgz", @@ -2470,6 +2823,16 @@ ], "license": "CC-BY-4.0" }, + "node_modules/chai": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/chai/-/chai-6.3.0.tgz", + "integrity": "sha512-XWAtwJ6OHO+tj0EKCs0Y2UamnyOxseZWltU4x2U2wh8g4AigdjwvtUjvLP2tqkA/avxHEtzxNaqGq/YGNwckKg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + } + }, "node_modules/chalk": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", @@ -2548,6 +2911,13 @@ "node": ">= 8" } }, + "node_modules/css.escape": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/css.escape/-/css.escape-1.5.1.tgz", + "integrity": "sha512-YUifsXXuknHlUsmlgyY0PKzgPOr7/FjCePfHNt0jxm83wHZi44VDMQ7/fGNkjY3/jV1MC+1CmZbaHzugyeRtpg==", + "dev": true, + "license": "MIT" + }, "node_modules/csstype": { "version": "3.2.3", "resolved": "https://registry.npmjs.org/csstype/-/csstype-3.2.3.tgz", @@ -2555,6 +2925,20 @@ "dev": true, "license": "MIT" }, + "node_modules/data-urls": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/data-urls/-/data-urls-8.0.0.tgz", + "integrity": "sha512-JQUCCK+/CAGbGGx618PlFZMXH81Jtj7t73CHv9dd/zVWvxgGT2zLFRjnKb+Ng46GIwcy+f7f88qd4duqllK+WQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "whatwg-mimetype": "^5.0.0", + "whatwg-url": "^17.1.2" + }, + "engines": { + "node": "^22.14.0 || >=24.0.0" + } + }, "node_modules/debug": { "version": "4.4.3", "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz", @@ -2572,6 +2956,13 @@ } } }, + "node_modules/decimal.js": { + "version": "10.6.0", + "resolved": "https://registry.npmjs.org/decimal.js/-/decimal.js-10.6.0.tgz", + "integrity": "sha512-YpgQiITW3JXGntzdUmyUR1V812Hn8T1YVXhCu+wO3OpS4eU9l4YdD3qjyiKdV6mvV29zapkMeD390UVEf2lkUg==", + "dev": true, + "license": "MIT" + }, "node_modules/deep-is": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.4.tgz", @@ -2588,6 +2979,16 @@ "node": ">=0.4.0" } }, + "node_modules/dequal": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/dequal/-/dequal-2.0.3.tgz", + "integrity": "sha512-0je+qPKHEMohvfRTCEo3CrPG6cAzAYgmzKyxRiYSSDkS6eGJdyVJm7WaYA5ECaAD9wLB2T4EEeymA5aFVcYXCA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6" + } + }, "node_modules/detect-libc": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.1.2.tgz", @@ -2598,6 +2999,14 @@ "node": ">=8" } }, + "node_modules/dom-accessibility-api": { + "version": "0.5.16", + "resolved": "https://registry.npmjs.org/dom-accessibility-api/-/dom-accessibility-api-0.5.16.tgz", + "integrity": "sha512-X7BJ2yElsnOJ30pZF4uIIDfBEVgF4XEBxL9Bxhy6dnrm5hkzqmsWHGTiHqRiITNhMyFLyAiWndIJP7Z1NTteDg==", + "dev": true, + "license": "MIT", + "peer": true + }, "node_modules/dunder-proto": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", @@ -2633,6 +3042,19 @@ "node": ">=10.13.0" } }, + "node_modules/entities": { + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/entities/-/entities-9.0.0.tgz", + "integrity": "sha512-oJFNDJg3kTPwAD1cNn2+WmUq4wFoo09npc3Ydf1D7ED4smRiWrsKnaLxykrTWgyGEcusc87P5dxlAleol9kpkg==", + "dev": true, + "license": "BSD-2-Clause", + "engines": { + "node": ">=20.19.0" + }, + "funding": { + "url": "https://github.com/fb55/entities?sponsor=1" + } + }, "node_modules/es-define-property": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz", @@ -2651,6 +3073,13 @@ "node": ">= 0.4" } }, + "node_modules/es-module-lexer": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/es-module-lexer/-/es-module-lexer-2.3.2.tgz", + "integrity": "sha512-poHGpORABojJJucnV9KbOavETW8lBVnphkW77ER5/BQ5Fz7oXSoCNek7IH3vR5nRjdsEz926ibFYX8KtLQmdyw==", + "dev": true, + "license": "MIT" + }, "node_modules/es-object-atoms": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.2.tgz", @@ -2967,6 +3396,16 @@ "node": ">=4.0" } }, + "node_modules/estree-walker": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-3.0.3.tgz", + "integrity": "sha512-7RUKfXgSMMkzt6ZuXmqapOurLGPPfgj6l9uRZ7lRGolvk0y2yocc35LdcxKC5PQZdn2DMqioAQ2NoWcrTKmm6g==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/estree": "^1.0.0" + } + }, "node_modules/esutils": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz", @@ -2977,6 +3416,16 @@ "node": ">=0.10.0" } }, + "node_modules/expect-type": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/expect-type/-/expect-type-1.4.0.tgz", + "integrity": "sha512-KfYbmpRm0VbLjEvVa9yGwCi9GI34xvi7A/HXYWQO65CSD2u3MczUJSuwXKFIxlGsgBQizV9q5J9NHj4VG0n+pA==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": ">=12.0.0" + } + }, "node_modules/fast-deep-equal": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", @@ -3282,6 +3731,19 @@ "node": ">= 0.4" } }, + "node_modules/html-encoding-sniffer": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/html-encoding-sniffer/-/html-encoding-sniffer-7.0.0.tgz", + "integrity": "sha512-UikN5yr7xsCDAq87Or5or0PAlD3HJJOKVzM05az588WnpDJ4Ux7a2A53Qi6gofGg2/EtvF/H4hCi/TXfCW4Y6w==", + "dev": true, + "license": "MIT", + "dependencies": { + "@exodus/bytes": "^1.15.1" + }, + "engines": { + "node": "^22.13.0 || >=24.0.0" + } + }, "node_modules/https-proxy-agent": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.1.tgz", @@ -3332,6 +3794,53 @@ "node": ">=0.8.19" } }, + "node_modules/indent-string": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/indent-string/-/indent-string-4.0.0.tgz", + "integrity": "sha512-EdDDZu4A2OyIK7Lr/2zG+w5jmbuk1DVBnEwREQvBzspBJkCEbRa8GxU1lghYcaGJCnRWibjDXlq779X1/y5xwg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/is-alphabetical": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/is-alphabetical/-/is-alphabetical-2.0.1.tgz", + "integrity": "sha512-FWyyY60MeTNyeSRpkM2Iry0G9hpr7/9kD40mD/cGQEuilcZYS4okz8SN2Q6rLCJ8gbCt6fN+rC+6tMGS99LaxQ==", + "dev": true, + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } + }, + "node_modules/is-alphanumerical": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/is-alphanumerical/-/is-alphanumerical-2.0.1.tgz", + "integrity": "sha512-hmbYhX/9MUMF5uh7tOXyK/n0ZvWpad5caBA17GsC6vyuCqaWliRG5K1qS9inmUhEMaOBIW7/whAnSwveW/LtZw==", + "dev": true, + "license": "MIT", + "dependencies": { + "is-alphabetical": "^2.0.0", + "is-decimal": "^2.0.0" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } + }, + "node_modules/is-decimal": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/is-decimal/-/is-decimal-2.0.1.tgz", + "integrity": "sha512-AAB9hiomQs5DXWcRB1rqsxGUstbRroFOPPVAomNk/3XHR5JyEZChOyTWe2oayKnsSsr/kcGqF+z6yuH6HHpN0A==", + "dev": true, + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } + }, "node_modules/is-extglob": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", @@ -3355,6 +3864,13 @@ "node": ">=0.10.0" } }, + "node_modules/is-potential-custom-element-name": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/is-potential-custom-element-name/-/is-potential-custom-element-name-1.0.1.tgz", + "integrity": "sha512-bCYeRA2rVibKZd+s2625gGnGF/t7DSqDs4dP7CrLA1m7jKWz6pps0LpYLJN8Q64HtmPKJ1hrN3nzPNKFEKOUiQ==", + "dev": true, + "license": "MIT" + }, "node_modules/isexe": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", @@ -3402,6 +3918,54 @@ "js-yaml": "bin/js-yaml.js" } }, + "node_modules/jsdom": { + "version": "31.0.1", + "resolved": "https://registry.npmjs.org/jsdom/-/jsdom-31.0.1.tgz", + "integrity": "sha512-CbhJL8ZQg3eKswxSZth4QO9tW0jPIhmR0vtSXQSbKSfWbwIT6hoRc17wdHIVTQ43KI0mdV5iTJr3281IDgVZ5g==", + "dev": true, + "license": "MIT", + "dependencies": { + "@exodus/bytes": "^1.16.0", + "bcp-47": "^2.1.2", + "bcp-47-match": "^2.0.3", + "data-urls": "^8.0.0", + "decimal.js": "^10.6.0", + "html-encoding-sniffer": "^7.0.0", + "is-potential-custom-element-name": "^1.0.1", + "lru-cache": "^11.5.3", + "parse5": "^8.1.0", + "parse5-parser-stream": "^8.1.0", + "saxes": "^6.0.0", + "tough-cookie": "^6.0.2", + "undici": "^8.12.3", + "w3c-xmlserializer": "^6.0.0", + "webidl-conversions": "^8.0.1", + "whatwg-mimetype": "^5.0.0", + "whatwg-url": "^17.3.0", + "xml-name-validator": "^5.0.0" + }, + "engines": { + "node": "^22.22.2 || ^24.15.0 || >=26.0.0" + }, + "peerDependencies": { + "@napi-rs/canvas": "^1.0.13" + }, + "peerDependenciesMeta": { + "@napi-rs/canvas": { + "optional": true + } + } + }, + "node_modules/jsdom/node_modules/lru-cache": { + "version": "11.5.3", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-11.5.3.tgz", + "integrity": "sha512-U4N8FgzmWxc8k1VH8Kr6lQg18U7Fjvby6wXHVRX/ZZ7IwWbRMgrRbP0Wrb5q5NVinryp4SQampHKdvtecItxUg==", + "dev": true, + "license": "BlueOak-1.0.0", + "engines": { + "node": "20 || >=22" + } + }, "node_modules/jsesc": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-3.1.0.tgz", @@ -3782,6 +4346,17 @@ "react": "^16.5.1 || ^17.0.0 || ^18.0.0 || ^19.0.0-rc" } }, + "node_modules/lz-string": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/lz-string/-/lz-string-1.5.0.tgz", + "integrity": "sha512-h5bgJWpxJNswbU7qCrV0tIKQCaS3blPDrqKWx+QxzuzL1zGUzij9XCWLrSLsJPu5t+eWA/ycetzYAO5IOMcWAQ==", + "dev": true, + "license": "MIT", + "peer": true, + "bin": { + "lz-string": "bin/bin.js" + } + }, "node_modules/magic-string": { "version": "0.30.21", "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.21.tgz", @@ -3792,6 +4367,18 @@ "@jridgewell/sourcemap-codec": "^1.5.5" } }, + "node_modules/magicast": { + "version": "0.5.5", + "resolved": "https://registry.npmjs.org/magicast/-/magicast-0.5.5.tgz", + "integrity": "sha512-UicdXN8zQ3JHlxVq+28afMXPr1z7WNY6+7EJnzTdQWkTAlMLF5fNCCKxJHBQwGaNGR11581EiQmQzx73+MvszA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/parser": "^7.29.7", + "@babel/types": "^7.29.7", + "source-map-js": "^1.2.1" + } + }, "node_modules/math-intrinsics": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz", @@ -3822,6 +4409,16 @@ "node": ">= 0.6" } }, + "node_modules/min-indent": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/min-indent/-/min-indent-1.0.1.tgz", + "integrity": "sha512-I9jwMn07Sy/IwOj3zVkVik2JTvgpaykDZEigL6Rx6N9LbMywwUSMtxET+7lVoDLLd3O3IXwJwvuuns8UB/HeAg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=4" + } + }, "node_modules/minimatch": { "version": "10.2.5", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.2.5.tgz", @@ -3880,6 +4477,20 @@ "node": ">=18" } }, + "node_modules/obug": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/obug/-/obug-3.0.0.tgz", + "integrity": "sha512-5vvB5+W7ePv+p3uqxi+RcW1XAzLW0/hxt3/4X4Lc4qHudzOhmBiBwOY6DRob4WnanAEGvNcLjF+KNOufrUoEQw==", + "dev": true, + "funding": [ + "https://github.com/sponsors/sxzz", + "https://opencollective.com/debug" + ], + "license": "MIT", + "engines": { + "node": ">=12.20.0" + } + }, "node_modules/optionator": { "version": "0.9.4", "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.4.tgz", @@ -3943,6 +4554,32 @@ "node": ">=6" } }, + "node_modules/parse5": { + "version": "8.1.1", + "resolved": "https://registry.npmjs.org/parse5/-/parse5-8.1.1.tgz", + "integrity": "sha512-EcR/6WDcU7b2N3vQSxKALCk9lXGtUMQxXio008OEMBE0kavu/7JLfBEeFPzi43nMqVDSbEn3QCK+BMCc9zO//w==", + "dev": true, + "license": "MIT", + "dependencies": { + "entities": "^9.0.0" + }, + "funding": { + "url": "https://github.com/inikulin/parse5?sponsor=1" + } + }, + "node_modules/parse5-parser-stream": { + "version": "8.1.1", + "resolved": "https://registry.npmjs.org/parse5-parser-stream/-/parse5-parser-stream-8.1.1.tgz", + "integrity": "sha512-hMcVbbUJcQmP8rURWUdYrT1flRiBiBVjq/RYGguJpDUgIXSqdYKlE0CxthmdMWoSlBAuL5bUBa73g0pttSy7Hw==", + "dev": true, + "license": "MIT", + "dependencies": { + "parse5": "^8.1.1" + }, + "funding": { + "url": "https://github.com/inikulin/parse5?sponsor=1" + } + }, "node_modules/path-exists": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", @@ -3971,9 +4608,9 @@ "license": "ISC" }, "node_modules/picomatch": { - "version": "4.0.4", - "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.4.tgz", - "integrity": "sha512-QP88BAKvMam/3NxH6vj2o21R6MjxZUAd6nlwAS/pnGvN9IVLocLHxGYIzFhg6fUQ+5th6P4dv4eW9jX3DSIj7A==", + "version": "4.0.7", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.7.tgz", + "integrity": "sha512-qcJu88Q2IWqJsDD529JKMdwGm/dvInW4HvQnRwiH9JtihJvzGOscDtHE3x1pBKeUOTysQ8kVmLnJ2kJu7yhcGA==", "dev": true, "license": "MIT", "engines": { @@ -4058,6 +4695,36 @@ "node": ">= 0.8.0" } }, + "node_modules/pretty-format": { + "version": "27.5.1", + "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-27.5.1.tgz", + "integrity": "sha512-Qb1gy5OrP5+zDf2Bvnzdl3jsTf1qXVMazbvCoKhtKqVs4/YK4ozX4gKQJJVyNe+cajNPn0KoC0MC3FUmaHWEmQ==", + "dev": true, + "license": "MIT", + "peer": true, + "dependencies": { + "ansi-regex": "^5.0.1", + "ansi-styles": "^5.0.0", + "react-is": "^17.0.1" + }, + "engines": { + "node": "^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0" + } + }, + "node_modules/pretty-format/node_modules/ansi-styles": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-5.2.0.tgz", + "integrity": "sha512-Cxwpt2SfTzTtXcfOlzGEee8O+c+MmUgGrNiBcXnuWxuFJHe6a5Hz7qwhwe5OgaSYI0IJvkLqWX1ASG+cJOkEiA==", + "dev": true, + "license": "MIT", + "peer": true, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, "node_modules/proxy-from-env": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-2.1.0.tgz", @@ -4098,6 +4765,14 @@ "react": "^19.2.6" } }, + "node_modules/react-is": { + "version": "17.0.2", + "resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz", + "integrity": "sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==", + "dev": true, + "license": "MIT", + "peer": true + }, "node_modules/react-refresh": { "version": "0.17.0", "resolved": "https://registry.npmjs.org/react-refresh/-/react-refresh-0.17.0.tgz", @@ -4108,6 +4783,20 @@ "node": ">=0.10.0" } }, + "node_modules/redent": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/redent/-/redent-3.0.0.tgz", + "integrity": "sha512-6tDA8g98We0zd0GvVeMT9arEOnTw9qM03L9cJXaCjrip1OO764RDBLBfrB4cwzNGDj5OA5ioymC9GkizgWJDUg==", + "dev": true, + "license": "MIT", + "dependencies": { + "indent-string": "^4.0.0", + "strip-indent": "^3.0.0" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/resolve-from": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz", @@ -4164,6 +4853,19 @@ "fsevents": "~2.3.2" } }, + "node_modules/saxes": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/saxes/-/saxes-6.0.0.tgz", + "integrity": "sha512-xAg7SOnEhrm5zI3puOOKyy1OMcMlIJZYNJY7xLBwSze0UjhPLnWfj2GF2EpT0jmzaJKIWKHLsaSSajf35bcYnA==", + "dev": true, + "license": "ISC", + "dependencies": { + "xmlchars": "^2.2.0" + }, + "engines": { + "node": ">=v12.22.7" + } + }, "node_modules/scheduler": { "version": "0.27.0", "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.27.0.tgz", @@ -4213,6 +4915,26 @@ "node": ">=0.10.0" } }, + "node_modules/std-env": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/std-env/-/std-env-4.3.0.tgz", + "integrity": "sha512-OtU/EgQ1kIm5KwqQpBC6ZEMXrZRui11w8zgfTWp8cdO9B8OaPsbA8bTHO2P+HNo1VlUTGMVBwPhydu6poeXiag==", + "dev": true, + "license": "MIT" + }, + "node_modules/strip-indent": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/strip-indent/-/strip-indent-3.0.0.tgz", + "integrity": "sha512-laJTa3Jb+VQpaC6DseHhF7dXVqHTfJPCRDaEbid/drOhgitgYku/letMUqOXFoWV0zIIUbjpdH2t+tYj4bQMRQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "min-indent": "^1.0.0" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/strip-json-comments": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", @@ -4260,6 +4982,26 @@ "url": "https://opencollective.com/webpack" } }, + "node_modules/tinybench": { + "version": "6.2.5", + "resolved": "https://registry.npmjs.org/tinybench/-/tinybench-6.2.5.tgz", + "integrity": "sha512-b/8GRMdnY4cqkfCLyaFpTGIv1qwfi3oT0mWaepwT++6Z/ZrYehNfZZ2JDKVLKGhNoEkS3IIB1ELtCT0XS5DtOA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=20.0.0" + } + }, + "node_modules/tinyexec": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/tinyexec/-/tinyexec-1.4.0.tgz", + "integrity": "sha512-PV6lIcJQh57aFeJDwx16JNHmgFRh5xguzallrDW1qe8nAghYgr5MKz2K5k7wEyV/ygZhdnIAP8+HZSarHPBCsg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + } + }, "node_modules/tinyglobby": { "version": "0.2.17", "resolved": "https://registry.npmjs.org/tinyglobby/-/tinyglobby-0.2.17.tgz", @@ -4277,6 +5019,62 @@ "url": "https://github.com/sponsors/SuperchupuDev" } }, + "node_modules/tinyrainbow": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/tinyrainbow/-/tinyrainbow-3.2.0.tgz", + "integrity": "sha512-LgO3D9yZJjApUiuUfl9iFAwrtaX4+lok3wJIqttGoKCHlWUqHqbQpnxCf82L8FjgKsh4iGo78hqJwgL8F6To2A==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/tldts": { + "version": "7.6.1", + "resolved": "https://registry.npmjs.org/tldts/-/tldts-7.6.1.tgz", + "integrity": "sha512-+q5zzJwjNwBPQV30jnqIaQMeZ/nQfc790uMq1vDj3kCGKNfokh+HYfwtd1d80OdSPNVS+mHV8vMd+yDtlK/+mQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "tldts-core": "^7.6.1" + }, + "bin": { + "tldts": "bin/cli.js" + } + }, + "node_modules/tldts-core": { + "version": "7.6.1", + "resolved": "https://registry.npmjs.org/tldts-core/-/tldts-core-7.6.1.tgz", + "integrity": "sha512-FzTCzmZVba1BJVZQJTGVfaRUV5dxPNV4nQZZuFrSitnsXS3k81XyDBhOUzB9/41cyVKdt2TW3YfIv9KKCBMMXg==", + "dev": true, + "license": "MIT" + }, + "node_modules/tough-cookie": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-6.1.0.tgz", + "integrity": "sha512-FTxc8u8Kl2tz0Lat1u8ksvcy8bwHRyEMawwTWybo51JqaC6O7SvfuhAKg+Ld6VqyIe2QRJBzY9HA7y2WyFRT2w==", + "dev": true, + "license": "BSD-3-Clause", + "dependencies": { + "tldts": "^7.0.5" + }, + "engines": { + "node": ">=16" + } + }, + "node_modules/tr46": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-7.0.0.tgz", + "integrity": "sha512-BcDSDW+SIGWVOns1Zm6Yg91q9AEj7eaID0QDY9oIqJD1A8dscNwMcl9Sms2DeuWCNov1X0/oXanHGYQBSLwZsg==", + "dev": true, + "license": "MIT", + "dependencies": { + "punycode": "^2.3.1" + }, + "engines": { + "node": "^22.14.0 || >=24.0.0" + } + }, "node_modules/ts-api-utils": { "version": "2.5.0", "resolved": "https://registry.npmjs.org/ts-api-utils/-/ts-api-utils-2.5.0.tgz", @@ -4349,6 +5147,16 @@ "typescript": ">=4.8.4 <6.1.0" } }, + "node_modules/undici": { + "version": "8.13.1", + "resolved": "https://registry.npmjs.org/undici/-/undici-8.13.1.tgz", + "integrity": "sha512-Kt7EaPjh0s93lJH/PmW3d5rhkcpUa6fS3jqZ7+YGxNd9L7Xy/i827xe4C2uhhq+pJebM4tQOl5AgHmW11G5Skg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=22.19.0" + } + }, "node_modules/undici-types": { "version": "6.21.0", "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.21.0.tgz", @@ -4472,6 +5280,147 @@ } } }, + "node_modules/vitest": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/vitest/-/vitest-5.1.2.tgz", + "integrity": "sha512-VIa2wXV208WraXUbzH+dQUrGcFpPuaiRA8HlhXS8R6/sy9cynw6OMqGj8fmAlH1hot7huTCtWUE14+FdXU3eLw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/chai": "^5.2.2", + "@vitest/mocker": "5.1.2", + "chai": "^6.3.0", + "es-module-lexer": "^2.3.2", + "expect-type": "^1.4.0", + "magic-string": "^1.4.5", + "obug": "^3.0.0", + "picomatch": "^4.0.7", + "std-env": "^4.3.0", + "tinybench": "^6.2.3", + "tinyexec": "^1.3.1", + "tinyglobby": "^0.2.17", + "why-is-node-running": "3.2.1" + }, + "bin": { + "vitest": "vitest.mjs" + }, + "engines": { + "node": "^22.12.0 || ^24.0.0 || >=26.0.0" + }, + "funding": { + "url": "https://opencollective.com/vitest" + }, + "peerDependencies": { + "@edge-runtime/vm": "*", + "@opentelemetry/api": "^1.9.0", + "@types/node": "^22.0.0 || >=24.0.0", + "@vitest/browser-playwright": "5.1.2", + "@vitest/browser-preview": "5.1.2", + "@vitest/browser-webdriverio": "^5.0.0-beta.5 || >=5.0.0", + "@vitest/coverage-istanbul": "5.1.2", + "@vitest/coverage-v8": "5.1.2", + "@vitest/ui": "5.1.2", + "happy-dom": "*", + "jsdom": "*", + "vite": "^6.4.0 || ^7.0.0 || ^8.0.0" + }, + "peerDependenciesMeta": { + "@edge-runtime/vm": { + "optional": true + }, + "@opentelemetry/api": { + "optional": true + }, + "@types/node": { + "optional": true + }, + "@vitest/browser-playwright": { + "optional": true + }, + "@vitest/browser-preview": { + "optional": true + }, + "@vitest/browser-webdriverio": { + "optional": true + }, + "@vitest/coverage-istanbul": { + "optional": true + }, + "@vitest/coverage-v8": { + "optional": true + }, + "@vitest/ui": { + "optional": true + }, + "happy-dom": { + "optional": true + }, + "jsdom": { + "optional": true + }, + "vite": { + "optional": false + } + } + }, + "node_modules/vitest/node_modules/magic-string": { + "version": "1.4.5", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-1.4.5.tgz", + "integrity": "sha512-oLLC2+YvQUfAa+vxoufE/yc1icb87M9iXIRqAoR/2EhE/8cb3SF/+Gi0c2By1B+5Vz2e2vQtUvHiu1+63Znh+w==", + "dev": true, + "license": "MIT", + "dependencies": { + "@jridgewell/sourcemap-codec": "^1.6.0" + } + }, + "node_modules/w3c-xmlserializer": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/w3c-xmlserializer/-/w3c-xmlserializer-6.0.0.tgz", + "integrity": "sha512-4Nsy8K5Tr6SPDH9jhKJOHf7ChDrc1zufZTVSF7x72hwuEXBqxqk9G6cK+K2NRUtB3iELRJqjXb4JPDMBjMTl2Q==", + "dev": true, + "license": "MIT", + "dependencies": { + "xml-name-validator": "^5.0.0" + }, + "engines": { + "node": "^22.22.2 || ^24.15.0 || >=26.0.0" + } + }, + "node_modules/webidl-conversions": { + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-8.0.1.tgz", + "integrity": "sha512-BMhLD/Sw+GbJC21C/UgyaZX41nPt8bUTg+jWyDeg7e7YN4xOM05YPSIXceACnXVtqyEw/LMClUQMtMZ+PGGpqQ==", + "dev": true, + "license": "BSD-2-Clause", + "engines": { + "node": ">=20" + } + }, + "node_modules/whatwg-mimetype": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/whatwg-mimetype/-/whatwg-mimetype-5.0.0.tgz", + "integrity": "sha512-sXcNcHOC51uPGF0P/D4NVtrkjSU2fNsm9iog4ZvZJsL3rjoDAzXZhkm2MWt1y+PUdggKAYVoMAIYcs78wJ51Cw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=20" + } + }, + "node_modules/whatwg-url": { + "version": "17.3.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-17.3.0.tgz", + "integrity": "sha512-KwOAJrpf+GTgBvcBQJcP38sMF0DsQKdwtG+TxM2pW44P6E5k0hDbWrDmyuJDIF0Uef0aQq0ZoJs+5oI+k8ddhg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@exodus/bytes": "^1.16.0", + "tr46": "^7.0.0", + "webidl-conversions": "^8.0.1" + }, + "engines": { + "node": "^22.14.0 || >=24.0.0" + } + }, "node_modules/which": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", @@ -4488,6 +5437,19 @@ "node": ">= 8" } }, + "node_modules/why-is-node-running": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/why-is-node-running/-/why-is-node-running-3.2.1.tgz", + "integrity": "sha512-Tb2FUhB4vUsGQlfSquQLYkApkuPAFQXGFzxWKHHumVz2dK+X1RUm/HnID4+TfIGYJ1kTcwOaCk/buYCEJr6YjQ==", + "dev": true, + "license": "MIT", + "bin": { + "why-is-node-running": "cli.js" + }, + "engines": { + "node": ">=20.11" + } + }, "node_modules/word-wrap": { "version": "1.2.5", "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.5.tgz", @@ -4498,6 +5460,23 @@ "node": ">=0.10.0" } }, + "node_modules/xml-name-validator": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/xml-name-validator/-/xml-name-validator-5.0.0.tgz", + "integrity": "sha512-EvGK8EJ3DhaHfbRlETOWAS5pO9MZITeauHKJyb8wyajUfQUenkIg2MvLDTZ4T/TgIcm3HU0TFBgWWboAZ30UHg==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": ">=18" + } + }, + "node_modules/xmlchars": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/xmlchars/-/xmlchars-2.2.0.tgz", + "integrity": "sha512-JZnDKK8B0RCDw84FNdDAIpZK+JuJw+s7Lz8nksI7SIuU3UXJJslUthsi+uWBUYOwPFwW7W7PRLRfUKpxjtjFCw==", + "dev": true, + "license": "MIT" + }, "node_modules/yallist": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/yallist/-/yallist-3.1.1.tgz", diff --git a/package.json b/package.json index 41602e8..27f3aec 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,9 @@ "build": "tsc -b && vite build", "lint": "eslint .", "preview": "vite preview", + "test": "vitest run", + "test:watch": "vitest", + "test:coverage": "vitest run --coverage", "test:e2e": "playwright test", "test:e2e:ui": "playwright test --ui", "test:e2e:headed": "playwright test --headed", @@ -24,19 +27,25 @@ "@eslint/js": "^9.0.0", "@playwright/test": "^1.65.1", "@tailwindcss/postcss": "^4.0.0", + "@testing-library/jest-dom": "^8.0.0", + "@testing-library/react": "^16.3.3", + "@testing-library/user-event": "^14.6.13", "@types/node": "^22.0.0", "@types/react": "^19.0.0", "@types/react-dom": "^19.0.0", "@vitejs/plugin-react": "^4.3.0", + "@vitest/coverage-v8": "^5.1.2", "autoprefixer": "^10.4.0", "eslint": "^9.0.0", "eslint-plugin-react-hooks": "^5.0.0", "eslint-plugin-react-refresh": "^0.4.0", "globals": "^15.0.0", + "jsdom": "^31.0.1", "postcss": "^8.4.0", "tailwindcss": "^4.0.0", "typescript": "^5.8.0", "typescript-eslint": "^8.0.0", - "vite": "^6.0.0" + "vite": "^6.0.0", + "vitest": "^5.1.2" } } diff --git a/tests/unit/components/CountrySelect.test.tsx b/tests/unit/components/CountrySelect.test.tsx new file mode 100644 index 0000000..aa242f3 --- /dev/null +++ b/tests/unit/components/CountrySelect.test.tsx @@ -0,0 +1,68 @@ +import { describe, expect, it, vi } from 'vitest'; +import { fireEvent, render, screen } from '@testing-library/react'; +import userEvent from '@testing-library/user-event'; +import { CountrySelect } from '../../../src/components/common/CountrySelect'; + +describe('CountrySelect', () => { + it('opens dropdown, filters by country/dial code/currency, and selects a country', async () => { + const user = userEvent.setup(); + const onChange = vi.fn(); + + render( + + ); + + const trigger = screen.getByRole('button'); + expect(trigger).toHaveTextContent('India'); + expect(trigger).toHaveTextContent('+91'); + + await user.click(trigger); + const searchInput = screen.getByPlaceholderText('Search country name or code...'); + await user.type(searchInput, 'Germany'); + + expect(screen.getByText('Germany')).toBeInTheDocument(); + await user.click(screen.getByText('Germany')); + expect(onChange).toHaveBeenCalledWith('Germany'); + }); + + it('shows empty state when no country matches and closes on Escape / outside click / clear', async () => { + const user = userEvent.setup(); + render( +
+
Outside
+ +
+ ); + + await user.click(screen.getByRole('button')); + const searchInput = screen.getByPlaceholderText('Search country name or code...'); + await user.type(searchInput, 'ZzzUnknown'); + expect(screen.getByText(/No countries found matching/)).toBeInTheDocument(); + + // Clear search button + const buttons = screen.getAllByRole('button'); + const clearBtn = buttons.find((b) => b.querySelector('svg') && b !== buttons[0]); + if (clearBtn) await user.click(clearBtn); + expect(searchInput).toHaveValue(''); + + // Escape closes + fireEvent.keyDown(document, { key: 'Escape' }); + expect(screen.queryByPlaceholderText('Search country name or code...')).not.toBeInTheDocument(); + + // Reopen and click outside closes + await user.click(screen.getByRole('button')); + expect(screen.getByPlaceholderText('Search country name or code...')).toBeInTheDocument(); + fireEvent.mouseDown(screen.getByTestId('outside')); + expect(screen.queryByPlaceholderText('Search country name or code...')).not.toBeInTheDocument(); + }); + + it('does not open when disabled and supports showDialCode=false', async () => { + const user = userEvent.setup(); + const { rerender } = render(); + await user.click(screen.getByRole('button')); + expect(screen.queryByPlaceholderText('Search country name or code...')).not.toBeInTheDocument(); + + rerender(); + expect(screen.getByRole('button')).not.toHaveTextContent('+91'); + }); +}); diff --git a/tests/unit/components/Pagination.test.tsx b/tests/unit/components/Pagination.test.tsx new file mode 100644 index 0000000..a949c98 --- /dev/null +++ b/tests/unit/components/Pagination.test.tsx @@ -0,0 +1,57 @@ +import { describe, expect, it, vi } from 'vitest'; +import { render, screen } from '@testing-library/react'; +import userEvent from '@testing-library/user-event'; +import { Pagination } from '../../../src/components/common/Pagination'; + +describe('Pagination', () => { + it('returns null when totalItems <= 0', () => { + const { container } = render( + + ); + expect(container.firstChild).toBeNull(); + }); + + it('renders pages and handles Prev, Next, page click, and itemsPerPage change', async () => { + const user = userEvent.setup(); + const onPageChange = vi.fn(); + const onItemsPerPageChange = vi.fn(); + + const { container } = render( + + ); + + expect(container.textContent).toContain('Showing 7 to 12 of 30 items'); + + await user.click(screen.getByRole('button', { name: 'Prev' })); + expect(onPageChange).toHaveBeenCalledWith(1); + + await user.click(screen.getByRole('button', { name: 'Next' })); + expect(onPageChange).toHaveBeenCalledWith(3); + + await user.click(screen.getByRole('button', { name: '5' })); + expect(onPageChange).toHaveBeenCalledWith(5); + + await user.selectOptions(screen.getByRole('combobox'), '12'); + expect(onItemsPerPageChange).toHaveBeenCalledWith(12); + expect(onPageChange).toHaveBeenCalledWith(1); + }); + + it('renders ellipsis branches for large page counts (start, middle, end)', () => { + const { rerender } = render( + + ); + expect(screen.getAllByText('...')).toHaveLength(1); + + rerender(); + expect(screen.getAllByText('...')).toHaveLength(2); + + rerender(); + expect(screen.getAllByText('...')).toHaveLength(1); + }); +}); diff --git a/tests/unit/components/PhoneInput.test.tsx b/tests/unit/components/PhoneInput.test.tsx new file mode 100644 index 0000000..a12966b --- /dev/null +++ b/tests/unit/components/PhoneInput.test.tsx @@ -0,0 +1,161 @@ +import { describe, expect, it, vi } from 'vitest'; +import { fireEvent, render, screen } from '@testing-library/react'; +import userEvent from '@testing-library/user-event'; +import { PhoneInput } from '../../../src/components/common/PhoneInput'; + +describe('PhoneInput', () => { + it('cleans input digits on change and displays error/helper text', async () => { + const user = userEvent.setup(); + const onPhoneChange = vi.fn(); + + const { rerender } = render( + + ); + + const input = screen.getByRole('textbox'); + await user.type(input, '98765'); + expect(onPhoneChange).toHaveBeenCalled(); + expect(input).toHaveAttribute('placeholder', '10-digit mobile number'); + + rerender( + + ); + expect(screen.getByText('Invalid phone')).toBeInTheDocument(); + }); + + it('opens dial code dropdown, searches, clears phone when clearOnDialCodeChange=true, and closes on Escape', async () => { + const user = userEvent.setup(); + const onDialCodeChange = vi.fn(); + const onPhoneChange = vi.fn(); + + render( +
+
Outside
+ +
+ ); + + const dialBtn = screen.getByRole('button'); + await user.click(dialBtn); + + const searchInput = screen.getByPlaceholderText('Search country or code...'); + await user.type(searchInput, '49'); + await user.click(screen.getByText('Germany')); + + expect(onDialCodeChange).toHaveBeenCalledWith('+49', 'Germany'); + expect(onPhoneChange).toHaveBeenCalledWith(''); + + // Reopen and test Escape + outside click + await user.click(dialBtn); + fireEvent.keyDown(document, { key: 'Escape' }); + expect(screen.queryByPlaceholderText('Search country or code...')).not.toBeInTheDocument(); + + await user.click(dialBtn); + fireEvent.mouseDown(screen.getByTestId('outside')); + expect(screen.queryByPlaceholderText('Search country or code...')).not.toBeInTheDocument(); + }); + + it('handles light theme, empty search, clear search button, clamping without clearing, and disabled state', async () => { + const user = userEvent.setup(); + const onDialCodeChange = vi.fn(); + const onPhoneChange = vi.fn(); + + const { rerender } = render( + + ); + + await user.click(screen.getByRole('button')); + const searchInput = screen.getByPlaceholderText('Search country or code...'); + await user.type(searchInput, 'NoSuchCountry'); + expect(screen.getByText(/No country codes found matching/)).toBeInTheDocument(); + + // Clear search button inside dropdown + const buttons = screen.getAllByRole('button'); + const clearBtn = buttons.find((b) => b !== buttons[0]); + if (clearBtn) await user.click(clearBtn); + expect(searchInput).toHaveValue(''); + + // Select Singapore (+65, maxLength 8) -> clamps 10 digits to 8 + await user.type(searchInput, 'Singapore'); + await user.click(screen.getByText('Singapore')); + expect(onDialCodeChange).toHaveBeenCalledWith('+65', 'Singapore'); + expect(onPhoneChange).toHaveBeenCalledWith('98765432'); + + // Disabled state does not open dropdown + rerender( + + ); + await user.click(screen.getByRole('button')); + expect(screen.queryByPlaceholderText('Search country or code...')).not.toBeInTheDocument(); + }); + + it('handles international paste (+91 / 91 prefix) and keydown filtering', () => { + const onDialCodeChange = vi.fn(); + const onPhoneChange = vi.fn(); + + render( + + ); + + const input = screen.getByRole('textbox'); + + // Pasting full international number starting with + + fireEvent.change(input, { target: { value: '+447123456789' } }); + expect(onDialCodeChange).toHaveBeenCalledWith('+44', 'United Kingdom'); + expect(onPhoneChange).toHaveBeenCalledWith('7123456789'); + + // Pasting number starting with dial code digits without '+' + fireEvent.change(input, { target: { value: '919876543210' } }); + expect(onPhoneChange).toHaveBeenCalledWith('9876543210'); + + // Keydown: allows Backspace, Ctrl+V, '+' at position 0, and blocks letters + const allowBackspace = fireEvent.keyDown(input, { key: 'Backspace' }); + expect(allowBackspace).toBe(true); + + const allowCtrl = fireEvent.keyDown(input, { key: 'v', ctrlKey: true }); + expect(allowCtrl).toBe(true); + + const allowPlus = fireEvent.keyDown(input, { key: '+' }); + expect(allowPlus).toBe(true); + + const blockAlpha = fireEvent.keyDown(input, { key: 'a' }); + expect(blockAlpha).toBe(false); + }); +}); diff --git a/tests/unit/constants/countries.test.ts b/tests/unit/constants/countries.test.ts new file mode 100644 index 0000000..b55901c --- /dev/null +++ b/tests/unit/constants/countries.test.ts @@ -0,0 +1,52 @@ +import { describe, expect, it } from 'vitest'; +import { + COUNTRY_CODES, + DEFAULT_COUNTRY, + SORTED_COUNTRY_CODES, + getCountryRuleByDialCode, + getCountryRuleByIso, + getCountryRuleByName, +} from '../../../src/constants/countries'; + +describe('countries constants & helpers', () => { + it('exports sorted country codes and India as default', () => { + expect(DEFAULT_COUNTRY.country).toBe('India'); + expect(DEFAULT_COUNTRY.code).toBe('+91'); + expect(SORTED_COUNTRY_CODES.length).toBe(COUNTRY_CODES.length); + }); + + it('resolves country rule by ISO2 code with default fallback', () => { + expect(getCountryRuleByIso(null)).toEqual(DEFAULT_COUNTRY); + expect(getCountryRuleByIso(' de ')).toMatchObject({ country: 'Germany', code: '+49' }); + expect(getCountryRuleByIso('ZZ')).toEqual(DEFAULT_COUNTRY); + }); + + it('resolves country rule by name, ISO, partial match, or custom fallback', () => { + expect(getCountryRuleByName('')).toEqual(DEFAULT_COUNTRY); + expect(getCountryRuleByName('Germany')).toMatchObject({ iso2: 'DE', code: '+49' }); + expect(getCountryRuleByName('gb')).toMatchObject({ country: 'United Kingdom' }); + expect(getCountryRuleByName('Republic of Singapore')).toMatchObject({ country: 'Singapore' }); + + const unknown = getCountryRuleByName('Atlantis'); + expect(unknown).toMatchObject({ + country: 'Atlantis', + currency: 'USD', + minLength: 7, + maxLength: 15, + }); + }); + + it('resolves country rule by dial code with country hint and fallback', () => { + expect(getCountryRuleByDialCode(null)).toEqual(DEFAULT_COUNTRY); + expect(getCountryRuleByDialCode('+1', 'Canada')).toMatchObject({ country: 'Canada', iso2: 'CA' }); + expect(getCountryRuleByDialCode('+44')).toMatchObject({ country: 'United Kingdom' }); + expect(getCountryRuleByDialCode('+999', 'CustomLand')).toMatchObject({ + code: '+999', + country: 'CustomLand', + }); + expect(getCountryRuleByDialCode('+999')).toMatchObject({ + code: '+999', + country: 'Other', + }); + }); +}); diff --git a/tests/unit/constants/modules.test.ts b/tests/unit/constants/modules.test.ts new file mode 100644 index 0000000..485045e --- /dev/null +++ b/tests/unit/constants/modules.test.ts @@ -0,0 +1,18 @@ +import { describe, expect, it } from 'vitest'; +import { CURRICULUM_MODULES } from '../../../src/constants/modules'; + +describe('CURRICULUM_MODULES', () => { + it('contains all core categories, complete packs, and lifetime pass with valid prices', () => { + expect(CURRICULUM_MODULES.length).toBeGreaterThanOrEqual(15); + const categories = new Set(CURRICULUM_MODULES.map((m) => m.category)); + expect(categories).toEqual(new Set(['Points', 'Pattern', 'Nutrition', 'Therapeutics', 'Lifetime'])); + + for (const mod of CURRICULUM_MODULES) { + expect(mod.code).toBeTruthy(); + expect(mod.name).toBeTruthy(); + expect(mod.priceInr).toBeGreaterThan(0); + expect(mod.priceUsd).toBeGreaterThan(0); + expect(mod.priceEur).toBeGreaterThan(0); + } + }); +}); diff --git a/tests/unit/services/services.test.ts b/tests/unit/services/services.test.ts new file mode 100644 index 0000000..c20b401 --- /dev/null +++ b/tests/unit/services/services.test.ts @@ -0,0 +1,46 @@ +import { afterEach, describe, expect, it } from 'vitest'; +import { api, API_BASE } from '../../../src/services/api'; +import { loadRazorpayScript } from '../../../src/services/razorpay'; + +describe('services', () => { + afterEach(() => { + delete (window as any).Razorpay; + document.body.innerHTML = ''; + }); + + describe('api service', () => { + it('configures axios instance and attaches Bearer token from localStorage', async () => { + expect(typeof API_BASE).toBe('string'); + localStorage.setItem('access_token', 'jwt-123'); + const handlers = (api.interceptors.request as any).handlers; + const fulfilled = handlers[0].fulfilled; + const cfg = await fulfilled({ headers: {} }); + expect(cfg.headers.Authorization).toBe('Bearer jwt-123'); + + localStorage.removeItem('access_token'); + const cfgNoToken = await fulfilled({ headers: {} }); + expect(cfgNoToken.headers.Authorization).toBeUndefined(); + }); + }); + + describe('razorpay service', () => { + it('resolves true immediately if window.Razorpay already exists', async () => { + (window as any).Razorpay = function () {}; + await expect(loadRazorpayScript()).resolves.toBe(true); + }); + + it('appends script and resolves true on load and false on error', async () => { + const p1 = loadRazorpayScript(); + const script1 = document.body.querySelector('script')!; + expect(script1.src).toContain('checkout.razorpay.com/v1/checkout.js'); + script1.onload?.(new Event('load')); + await expect(p1).resolves.toBe(true); + + document.body.innerHTML = ''; + const p2 = loadRazorpayScript(); + const script2 = document.body.querySelector('script')!; + script2.onerror?.(new Event('error')); + await expect(p2).resolves.toBe(false); + }); + }); +}); diff --git a/tests/unit/setup.ts b/tests/unit/setup.ts new file mode 100644 index 0000000..0d74b73 --- /dev/null +++ b/tests/unit/setup.ts @@ -0,0 +1,7 @@ +import '@testing-library/jest-dom/vitest'; +import { cleanup } from '@testing-library/react'; +import { afterEach } from 'vitest'; + +afterEach(() => { + cleanup(); +}); diff --git a/tests/unit/utils/navigation.test.ts b/tests/unit/utils/navigation.test.ts new file mode 100644 index 0000000..19e6c95 --- /dev/null +++ b/tests/unit/utils/navigation.test.ts @@ -0,0 +1,49 @@ +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; +import { + DEFAULT_APP_SCHEMES, + DEFAULT_RETURN_ROUTE, + formatDeepLinkRoute, + getAppDeepLinkUrls, + openMobileApp, +} from '../../../src/utils/navigation'; + +describe('navigation utils', () => { + const originalLocation = window.location; + + beforeEach(() => { + vi.useFakeTimers(); + Object.defineProperty(window, 'location', { + configurable: true, + value: { href: 'http://localhost:3000/store/' }, + }); + }); + + afterEach(() => { + vi.useRealTimers(); + Object.defineProperty(window, 'location', { + configurable: true, + value: originalLocation, + }); + }); + + it('formats deep link routes cleanly', () => { + expect(formatDeepLinkRoute()).toBe(DEFAULT_RETURN_ROUTE); + expect(formatDeepLinkRoute('///')).toBe(DEFAULT_RETURN_ROUTE); + expect(formatDeepLinkRoute('/subscriptions/')).toBe('subscriptions/'); + }); + + it('generates deep link URLs for default and custom schemes', () => { + expect(getAppDeepLinkUrls()).toEqual(DEFAULT_APP_SCHEMES.map((s) => `${s}://${DEFAULT_RETURN_ROUTE}`)); + expect(getAppDeepLinkUrls({ route: '/profile', schemes: ['customapp'] })).toEqual([ + 'customapp://profile', + ]); + }); + + it('opens mobile app primary URL and schedules fallback URLs', () => { + openMobileApp({ route: '/modules', schemes: ['acupedia', 'myapp'], delayBetweenFallbacks: 300 }); + expect(window.location.href).toBe('acupedia://modules'); + + vi.advanceTimersByTime(300); + expect(window.location.href).toBe('myapp://modules'); + }); +}); diff --git a/tests/unit/utils/validation.test.ts b/tests/unit/utils/validation.test.ts new file mode 100644 index 0000000..b67440b --- /dev/null +++ b/tests/unit/utils/validation.test.ts @@ -0,0 +1,164 @@ +import { describe, expect, it } from 'vitest'; +import { + EMAIL_REGEX, + SPECIAL_CHAR_REGEX, + cleanPhoneInput, + formatE164Phone, + formatPrefixList, + isValidEmail, + isValidPhoneNumber, + parsePhoneNumber, + updatePhoneDialCode, + validateEmail, + validatePassword, + validatePhoneNumber, +} from '../../../src/utils/validation'; + +describe('validation utils', () => { + describe('formatPrefixList', () => { + it('handles empty, single, two, and multiple prefixes', () => { + expect(formatPrefixList([])).toBe(''); + expect(formatPrefixList(['3'])).toBe('3'); + expect(formatPrefixList(['6', '7'])).toBe('6 or 7'); + expect(formatPrefixList(['6', '7', '8', '9'])).toBe('6, 7, 8, or 9'); + }); + }); + + describe('cleanPhoneInput', () => { + it('strips non-numeric chars, respects allowPlus and maxLength', () => { + expect(cleanPhoneInput(' +91 987-654-3210 ', 12, true)).toBe('+919876543210'); + expect(cleanPhoneInput('+91 9876543210', 10, false)).toBe('9198765432'); + expect(cleanPhoneInput('abc12345def', 0, true)).toBe('12345'); + }); + }); + + describe('validatePhoneNumber & isValidPhoneNumber', () => { + it('returns null for empty/whitespace values', () => { + expect(validatePhoneNumber('')).toBeNull(); + expect(validatePhoneNumber(' ')).toBeNull(); + expect(validatePhoneNumber(null)).toBeNull(); + expect(isValidPhoneNumber(undefined)).toBe(true); + }); + + it('rejects alphabetic characters, hyphens, and non-digit symbols', () => { + expect(validatePhoneNumber('98765abc10', '+91', 'India')).toContain('alphabetic'); + expect(validatePhoneNumber('789--98--809', '+91', 'India')).toContain('hyphens'); + expect(validatePhoneNumber('98765@3210', '+91', 'India')).toContain('only numeric digits'); + expect(validatePhoneNumber('+ ', '+91', 'India')).toContain('numeric digits'); + }); + + it('enforces exact and variable length rules', () => { + expect(validatePhoneNumber('98765', '+91', 'India')).toContain('exactly 10 digits'); + expect(validatePhoneNumber('12345', '+49', 'Germany')).toContain('too short'); + expect(validatePhoneNumber('1512345678901234', '+49', 'Germany')).toContain('cannot exceed'); + }); + + it('enforces valid mobile prefixes and rejects landlines', () => { + expect(validatePhoneNumber('5123456789', '+91', 'India')).toContain('must start with'); + // Valid Indian mobile + expect(validatePhoneNumber('9876543210', '+91', 'India')).toBeNull(); + expect(isValidPhoneNumber('+919876543210', '+91', 'India')).toBe(true); + // Trunk 0 stripping for UK + expect(validatePhoneNumber('07123456789', '+44', 'United Kingdom')).toBeNull(); + // Dial code prefix without '+' when longer than maxLength + expect(validatePhoneNumber('919876543210', '+91', 'India')).toBeNull(); + // Fallback when country is not provided -> resolves by dialCode + expect(validatePhoneNumber('9876543210', '+91')).toBeNull(); + // Fallback when neither country nor dialCode provided -> DEFAULT_COUNTRY + expect(validatePhoneNumber('9876543210')).toBeNull(); + // Fixed line rejection (e.g. US/UK or invalid mobile) + expect(validatePhoneNumber('15123456789', '+49', 'Germany')).toBeNull(); + expect(validatePhoneNumber('2025550173', '+1', 'United States')).toBeNull(); // US numbers are FIXED_LINE_OR_MOBILE + // Invalid UK landline 020... + const ukLandline = validatePhoneNumber('7123456789', '+44', 'United Kingdom'); + expect(ukLandline).toBeNull(); + // Invalid number with valid prefix but rejected by libphonenumber-js + expect(validatePhoneNumber('0000000000', '+91', 'India')).toContain('must start with'); + expect(validatePhoneNumber('07700900123', '+44', 'United Kingdom')).toContain('Please enter a valid mobile number'); + }); + }); + + describe('parsePhoneNumber', () => { + it('parses empty, valid E.164, and fallback numbers', () => { + expect(parsePhoneNumber('', 'India')).toEqual({ + country: 'India', + dialCode: '+91', + localDigits: '', + iso2: 'IN', + }); + + const parsedIn = parsePhoneNumber('+919876543210', 'India'); + expect(parsedIn).toEqual({ + country: 'India', + dialCode: '+91', + localDigits: '9876543210', + iso2: 'IN', + }); + + const parsedDe = parsePhoneNumber('+491512345678', 'India'); + expect(parsedDe.country).toBe('Germany'); + expect(parsedDe.dialCode).toBe('+49'); + + // Fallback when unparseable by libphonenumber-js + const fallbackSame = parsePhoneNumber('+91 123', 'India'); + expect(fallbackSame.dialCode).toBe('+91'); + + const fallbackOther = parsePhoneNumber('+49', 'India'); + expect(fallbackOther.dialCode).toBe('+49'); + expect(fallbackOther.country).toBe('Germany'); + + const rawOnly = parsePhoneNumber('9876', 'India'); + expect(rawOnly.localDigits).toBe('9876'); + + const unknownCode = parsePhoneNumber('+999123', 'India'); + expect(unknownCode.localDigits).toBe('999123'); + }); + }); + + describe('formatE164Phone', () => { + it('formats valid and fallback E.164 strings', () => { + expect(formatE164Phone('+91', '')).toBe(''); + expect(formatE164Phone('+91', 'abc')).toBe(''); + expect(formatE164Phone('+91', '9876543210', 'India')).toBe('+919876543210'); + expect(formatE164Phone('44', '07123456789', 'United Kingdom')).toBe('+447123456789'); + // Fallback trunk 0 removal when invalid + expect(formatE164Phone('+91', '0123', 'India')).toBe('+91123'); + // Italy keeps trunk 0 in fallback + expect(formatE164Phone('+39', '0123', 'Italy')).toBe('+390123'); + }); + }); + + describe('updatePhoneDialCode', () => { + it('updates dial code and clamps to new country maxLength', () => { + expect(updatePhoneDialCode('', 'India', 'Germany')).toBe(''); + expect(updatePhoneDialCode('+91 9876543210', 'India', 'Singapore')).toBe('+65 98765432'); + expect(updatePhoneDialCode('+91', 'India', 'Germany')).toBe('+49 '); + }); + }); + + describe('validatePassword', () => { + it('enforces all password complexity rules', () => { + expect(SPECIAL_CHAR_REGEX.test('!')).toBe(true); + expect(validatePassword('')).toBe('Password is required.'); + expect(validatePassword('Ab1!')).toContain('at least 8 characters'); + expect(validatePassword('Abcd 1234!')).toContain('must not contain spaces'); + expect(validatePassword('abcd1234!')).toContain('uppercase'); + expect(validatePassword('Abcdefgh!')).toContain('number'); + expect(validatePassword('Abcd1234😀!')).toContain('emojis'); + expect(validatePassword('Abcd12345')).toContain('special character'); + expect(validatePassword('ValidPass1!')).toBeNull(); + }); + }); + + describe('validateEmail & isValidEmail', () => { + it('validates RFC-compliant emails', () => { + expect(EMAIL_REGEX.test('user@example.com')).toBe(true); + expect(validateEmail('')).toBe('Email address is required.'); + expect(validateEmail(' ')).toBe('Email address is required.'); + expect(validateEmail('invalid-email')).toBe('Please enter a valid email address.'); + expect(validateEmail('user@example.com')).toBeNull(); + expect(isValidEmail('user.name+1@sub.example.co.in')).toBe(true); + expect(isValidEmail('bad@')).toBe(false); + }); + }); +}); diff --git a/vitest.config.ts b/vitest.config.ts new file mode 100644 index 0000000..819250d --- /dev/null +++ b/vitest.config.ts @@ -0,0 +1,29 @@ +import { defineConfig } from 'vitest/config'; +import react from '@vitejs/plugin-react'; + +export default defineConfig({ + plugins: [react()], + test: { + environment: 'jsdom', + globals: true, + setupFiles: ['./tests/unit/setup.ts'], + include: ['tests/unit/**/*.test.{ts,tsx}'], + coverage: { + provider: 'v8', + reporter: ['text', 'html', 'lcov'], + reportsDirectory: './coverage', + include: [ + 'src/utils/**/*.{ts,tsx}', + 'src/services/**/*.{ts,tsx}', + 'src/constants/**/*.{ts,tsx}', + 'src/components/common/**/*.{ts,tsx}', + ], + thresholds: { + lines: 95, + functions: 95, + branches: 90, + statements: 95, + }, + }, + }, +});