diff --git a/package.json b/package.json index 83fe63b1..340aa360 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "prepare": "vp config", "api": "node server/index.ts", "data:build": "node scripts/build-data-index.ts", - "test": "node --test \"server/**/*.test.ts\" \"electron/**/*.test.ts\" \"src/**/*.test.ts\"", + "test": "node --disable-warning=DEP0205 --import ./test/setup/register.ts --test \"server/**/*.test.ts\" \"electron/**/*.test.ts\" \"src/**/*.test.ts\" \"src/**/*.test.tsx\"", "desktop:bundle": "node scripts/build-electron.ts", "desktop:start": "vp build && pnpm desktop:bundle && electron .", "desktop:dist": "vp build && pnpm desktop:bundle && electron-builder --publish never" @@ -37,6 +37,9 @@ "@tanstack/react-router": "^1.170.44", "@tanstack/react-virtual": "^3.14.21", "@tanstack/router-plugin": "^1.168.46", + "@testing-library/dom": "^10.4.2", + "@testing-library/react": "^16.3.3", + "@testing-library/user-event": "^14.6.13", "@types/node": "^26.6.5", "@types/qrcode": "^1.5.6", "@types/react": "^19.2.18", @@ -47,6 +50,7 @@ "electron": "^45.0.0", "electron-builder": "^26.18.0", "esbuild": "^0.28.2", + "happy-dom": "^21.0.4", "lucide-react": "^1.58.0", "react": "^19.2.8", "react-dom": "^19.2.8", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f95e62a4..cf595a7a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -215,6 +215,15 @@ importers: '@tanstack/router-plugin': specifier: ^1.168.46 version: 1.168.46(@tanstack/react-router@1.170.44(react-dom@19.3.1(react@19.3.1))(react@19.3.1))(@voidzero-dev/vite-plus-core@1.3.0(@types/node@26.6.5)(esbuild@0.28.2)(jiti@2.7.0)(typescript@7.0.2))(esbuild@0.28.2)(supports-color@7.2.0) + '@testing-library/dom': + specifier: ^10.4.2 + version: 10.4.2 + '@testing-library/react': + specifier: ^16.3.3 + version: 16.3.3(@testing-library/dom@10.4.2)(@types/react-dom@19.3.0(@types/react@19.3.0))(@types/react@19.3.0)(react-dom@19.3.1(react@19.3.1))(react@19.3.1) + '@testing-library/user-event': + specifier: ^14.6.13 + version: 14.6.13(@testing-library/dom@10.4.2) '@types/node': specifier: ^26.6.5 version: 26.6.5 @@ -245,6 +254,9 @@ importers: esbuild: specifier: ^0.28.2 version: 0.28.2 + happy-dom: + specifier: ^21.0.4 + version: 21.0.4 lucide-react: specifier: ^1.58.0 version: 1.58.0(@types/react@19.3.0)(react@19.3.1) @@ -268,7 +280,7 @@ importers: version: '@voidzero-dev/vite-plus-core@1.3.0(@types/node@26.6.5)(esbuild@0.28.2)(jiti@2.7.0)(typescript@7.0.2)' vite-plus: specifier: 'catalog:' - version: 1.3.0(@types/node@26.6.5)(@vitest/ui@5.0.5)(esbuild@0.28.2)(jiti@2.7.0)(typescript@7.0.2) + version: 1.3.0(@types/node@26.6.5)(@vitest/ui@5.0.5)(esbuild@0.28.2)(happy-dom@21.0.4)(jiti@2.7.0)(typescript@7.0.2) zustand: specifier: ^5.0.15 version: 5.0.15(@types/react@19.3.0)(react@19.3.1)(use-sync-external-store@1.7.0(react@19.3.1)) @@ -1109,8 +1121,23 @@ packages: resolution: {integrity: sha512-yzr2S9HyAIdhz2/6qHgbs665Q7PKVcDF05vsOlHPxG1mo36gKVesdYVeDLnXgfjJ03CrKRk08knc6+E/9m8v2Q==} engines: {node: '>=18'} - '@testing-library/user-event@14.6.8': - resolution: {integrity: sha512-vgSSqnANMnkcYR/vUNDbwS7aM3OErRLNUG8vCVVlj4oc6cKffUrccX7UAS5AmJQQNZTSibi9z5GvvRZ0aYgUCQ==} + '@testing-library/react@16.3.3': + resolution: {integrity: sha512-Uo193NgQbPMz6lrrhtRQQFcMC6Re/ELLFbbuVL30WDlZxlpZf9/lMHTAVxPRLw1q1iu9OJmR1c2BLiENRstdBg==} + 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 + + '@testing-library/user-event@14.6.13': + resolution: {integrity: sha512-2LVZGptuB5un1Cu/u31o9adkCwbsUTMp4B4p04xupI7uobvTIpgKidSdShqZiReo/mQmvR9xjgdgTgge4oAbYA==} engines: {node: '>=12', npm: '>=6'} peerDependencies: '@testing-library/dom': '>=7.21.4' @@ -1180,6 +1207,12 @@ packages: '@types/steamid@2.0.4': resolution: {integrity: sha512-LC0oaiNq3gqMI18MV935CnlyHmDooKRszK56jHv0+b7EbJwf5k++YsD52zWeJUD8nuYqP9LpIgpXGiYBOxpcYQ==} + '@types/whatwg-mimetype@3.0.2': + resolution: {integrity: sha512-c2AKvDT8ToxLIOUlN51gTiHXflsfIFisS4pO7pDPoKouJCESkhZnEy623gwP9laCy5lnLDAw1vAzu2vM2YLOrA==} + + '@types/ws@8.18.2': + resolution: {integrity: sha512-67MQl+fpWKVTT1NYdnmo3U4sc/xPo/zQBncVnI74qmQa0z/b+1g6iYqNmGCPbxO+zz2aklb08a0oHfegiVd0/w==} + '@typescript/typescript-aix-ppc64@7.0.2': resolution: {integrity: sha512-MTKKkWB7p/0E9xi1d1tHtZ5PiLkGEMIq88pK2CubZjOsLtYTLqhgIgi6zepFa+9GHZ6h05NMCkQxGKiPXMxXtQ==} engines: {node: '>=16.20.0'} @@ -1675,6 +1708,10 @@ packages: buffer-from@1.1.2: resolution: {integrity: sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==} + buffer-image-size@0.6.4: + resolution: {integrity: sha512-nEh+kZOPY1w+gcCMobZ6ETUp9WfibndnosbpwB1iJk/8Gt5ZF2bhS6+B6bPYz424KtwsR6Rflc3tCz1/ghX2dQ==} + engines: {node: '>=4.0'} + builder-util-runtime@9.7.0: resolution: {integrity: sha512-g/kR520giAFYkSXTzcmF3kqQq7wi8F6N6SzeDgZrqTBN+VHdmgWOyTdD1yD7AATDId/yXLvuP34CxW46/BwCdw==} engines: {node: '>=12.0.0'} @@ -1939,6 +1976,10 @@ packages: resolution: {integrity: sha512-V0hjH4dGPh9Ao5p0MoRY6BVqtwCjhz6vI5LT8AJ55H+4g9/4vbHx1I54fS0XuclLhDHArPQCiMjDxjaL8fPxhw==} engines: {node: '>=0.12'} + entities@7.0.1: + resolution: {integrity: sha512-TWrgLOFUQTH994YUyl1yT4uyavY5nNB5muff+RtWaqNVCAK408b5ZnnbNAUEWLTCpum9w6arT70i1XdQ4UeOPA==} + engines: {node: '>=0.12'} + entities@8.1.0: resolution: {integrity: sha512-kxL7msIffSuh9aaFAMD7rxAIuTRMAHMeBtgHW2yUdWw732ZNh4MehkF2gdjvtdmikkaIP9bFDDJOPlsvm7avrA==} engines: {node: '>=20.19.0'} @@ -2122,6 +2163,10 @@ packages: graceful-fs@4.2.11: resolution: {integrity: sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==} + happy-dom@21.0.4: + resolution: {integrity: sha512-tFm+GaLBgo6o0awHnvHaNoraVo27qJ+2tZEtZ+cIa08hXbeitrxAJajLI05hsUy/2/YTKcUjQYzHe5mCcraLBw==} + engines: {node: '>=20.0.0'} + has-flag@4.0.0: resolution: {integrity: sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==} engines: {node: '>=8'} @@ -3168,6 +3213,10 @@ packages: resolution: {integrity: sha512-7+hxkUVTKQlUDTzN2rJI7fJRBXCT6dvRXr1aZflxUZlpNJutHBkKiEIbZOCGs0A1s7vxAmcAXngsNUQMSUTiVQ==} engines: {node: '>=12.22.0'} + whatwg-mimetype@3.0.0: + resolution: {integrity: sha512-nt+N2dzIutVRxARx1nghPKGv1xHikU7HKdfafKkLNLindmPU/ch3U31NOCGGA/dmPcmb1VlofO0vnKAcsm0o/Q==} + engines: {node: '>=12'} + which-module@2.0.1: resolution: {integrity: sha512-iBdZ57RDvnOR9AGBhML2vFZf7h8vmBjhoaZqODJBFWHVtKkDmKuHai3cx5PgVMrX5YDNp27AofYbAwctSS+vhQ==} @@ -3977,7 +4026,17 @@ snapshots: picocolors: 1.1.1 pretty-format: 27.5.1 - '@testing-library/user-event@14.6.8(@testing-library/dom@10.4.2)': + '@testing-library/react@16.3.3(@testing-library/dom@10.4.2)(@types/react-dom@19.3.0(@types/react@19.3.0))(@types/react@19.3.0)(react-dom@19.3.1(react@19.3.1))(react@19.3.1)': + dependencies: + '@babel/runtime': 7.29.10 + '@testing-library/dom': 10.4.2 + react: 19.3.1 + react-dom: 19.3.1(react@19.3.1) + optionalDependencies: + '@types/react': 19.3.0 + '@types/react-dom': 19.3.0(@types/react@19.3.0) + + '@testing-library/user-event@14.6.13(@testing-library/dom@10.4.2)': dependencies: '@testing-library/dom': 10.4.2 @@ -4059,6 +4118,12 @@ snapshots: '@types/steamid@2.0.4': {} + '@types/whatwg-mimetype@3.0.2': {} + + '@types/ws@8.18.2': + dependencies: + '@types/node': 26.6.5 + '@typescript/typescript-aix-ppc64@7.0.2': optional: true @@ -4127,9 +4192,9 @@ snapshots: '@vitest/browser-preview@5.0.5(@voidzero-dev/vite-plus-core@1.3.0(@types/node@26.6.5)(esbuild@0.28.2)(jiti@2.7.0)(typescript@7.0.2))(vitest@5.0.5)': dependencies: '@testing-library/dom': 10.4.2 - '@testing-library/user-event': 14.6.8(@testing-library/dom@10.4.2) + '@testing-library/user-event': 14.6.13(@testing-library/dom@10.4.2) '@vitest/browser': 5.0.5(@voidzero-dev/vite-plus-core@1.3.0(@types/node@26.6.5)(esbuild@0.28.2)(jiti@2.7.0)(typescript@7.0.2))(vitest@5.0.5) - vitest: 5.0.5(@types/node@26.6.5)(@vitest/browser-preview@5.0.5)(@vitest/ui@5.0.5)(@voidzero-dev/vite-plus-core@1.3.0(@types/node@26.6.5)(esbuild@0.28.2)(jiti@2.7.0)(typescript@7.0.2)) + vitest: 5.0.5(@types/node@26.6.5)(@vitest/browser-preview@5.0.5)(@vitest/ui@5.0.5)(@voidzero-dev/vite-plus-core@1.3.0(@types/node@26.6.5)(esbuild@0.28.2)(jiti@2.7.0)(typescript@7.0.2))(happy-dom@21.0.4) transitivePeerDependencies: - bufferutil - msw @@ -4146,7 +4211,7 @@ snapshots: pngjs: 7.0.0 sirv: 3.0.2 tinyrainbow: 3.2.0 - vitest: 5.0.5(@types/node@26.6.5)(@vitest/browser-preview@5.0.5)(@vitest/ui@5.0.5)(@voidzero-dev/vite-plus-core@1.3.0(@types/node@26.6.5)(esbuild@0.28.2)(jiti@2.7.0)(typescript@7.0.2)) + vitest: 5.0.5(@types/node@26.6.5)(@vitest/browser-preview@5.0.5)(@vitest/ui@5.0.5)(@voidzero-dev/vite-plus-core@1.3.0(@types/node@26.6.5)(esbuild@0.28.2)(jiti@2.7.0)(typescript@7.0.2))(happy-dom@21.0.4) ws: 8.22.0 transitivePeerDependencies: - bufferutil @@ -4184,7 +4249,7 @@ snapshots: pathe: 2.0.3 sirv: 3.0.2 tinyrainbow: 3.2.0 - vitest: 5.0.5(@types/node@26.6.5)(@vitest/browser-preview@5.0.5)(@vitest/ui@5.0.5)(@voidzero-dev/vite-plus-core@1.3.0(@types/node@26.6.5)(esbuild@0.28.2)(jiti@2.7.0)(typescript@7.0.2)) + vitest: 5.0.5(@types/node@26.6.5)(@vitest/browser-preview@5.0.5)(@vitest/ui@5.0.5)(@voidzero-dev/vite-plus-core@1.3.0(@types/node@26.6.5)(esbuild@0.28.2)(jiti@2.7.0)(typescript@7.0.2))(happy-dom@21.0.4) '@vitest/utils@5.0.5': dependencies: @@ -4430,6 +4495,10 @@ snapshots: buffer-from@1.1.2: {} + buffer-image-size@0.6.4: + dependencies: + '@types/node': 26.6.5 + builder-util-runtime@9.7.0(supports-color@7.2.0): dependencies: debug: 4.4.3(supports-color@7.2.0) @@ -4751,6 +4820,8 @@ snapshots: entities@4.5.0: {} + entities@7.0.1: {} + entities@8.1.0: {} env-paths@2.2.1: {} @@ -4981,6 +5052,19 @@ snapshots: graceful-fs@4.2.11: {} + happy-dom@21.0.4: + dependencies: + '@types/node': 26.6.5 + '@types/whatwg-mimetype': 3.0.2 + '@types/ws': 8.18.2 + buffer-image-size: 0.6.4 + entities: 7.0.1 + whatwg-mimetype: 3.0.0 + ws: 8.22.0 + transitivePeerDependencies: + - bufferutil + - utf-8-validate + has-flag@4.0.0: {} has-property-descriptors@1.0.2: @@ -5332,7 +5416,7 @@ snapshots: dependencies: wrappy: 1.0.2 - oxfmt@0.73.0(vite-plus@1.3.0(@types/node@26.6.5)(@vitest/ui@5.0.5)(esbuild@0.28.2)(jiti@2.7.0)(typescript@7.0.2)): + oxfmt@0.73.0(vite-plus@1.3.0(@types/node@26.6.5)(@vitest/ui@5.0.5)(esbuild@0.28.2)(happy-dom@21.0.4)(jiti@2.7.0)(typescript@7.0.2)): dependencies: tinypool: 2.2.0 optionalDependencies: @@ -5355,7 +5439,7 @@ snapshots: '@oxfmt/binding-win32-arm64-msvc': 0.73.0 '@oxfmt/binding-win32-ia32-msvc': 0.73.0 '@oxfmt/binding-win32-x64-msvc': 0.73.0 - vite-plus: 1.3.0(@types/node@26.6.5)(@vitest/ui@5.0.5)(esbuild@0.28.2)(jiti@2.7.0)(typescript@7.0.2) + vite-plus: 1.3.0(@types/node@26.6.5)(@vitest/ui@5.0.5)(esbuild@0.28.2)(happy-dom@21.0.4)(jiti@2.7.0)(typescript@7.0.2) oxlint-tsgolint@7.0.2004: optionalDependencies: @@ -5366,7 +5450,7 @@ snapshots: '@oxlint-tsgolint/win32-arm64': 7.0.2004 '@oxlint-tsgolint/win32-x64': 7.0.2004 - oxlint@1.88.0(oxlint-tsgolint@7.0.2004)(vite-plus@1.3.0(@types/node@26.6.5)(@vitest/ui@5.0.5)(esbuild@0.28.2)(jiti@2.7.0)(typescript@7.0.2)): + oxlint@1.88.0(oxlint-tsgolint@7.0.2004)(vite-plus@1.3.0(@types/node@26.6.5)(@vitest/ui@5.0.5)(esbuild@0.28.2)(happy-dom@21.0.4)(jiti@2.7.0)(typescript@7.0.2)): optionalDependencies: '@oxlint/binding-android-arm-eabi': 1.88.0 '@oxlint/binding-android-arm64': 1.88.0 @@ -5388,7 +5472,7 @@ snapshots: '@oxlint/binding-win32-ia32-msvc': 1.88.0 '@oxlint/binding-win32-x64-msvc': 1.88.0 oxlint-tsgolint: 7.0.2004 - vite-plus: 1.3.0(@types/node@26.6.5)(@vitest/ui@5.0.5)(esbuild@0.28.2)(jiti@2.7.0)(typescript@7.0.2) + vite-plus: 1.3.0(@types/node@26.6.5)(@vitest/ui@5.0.5)(esbuild@0.28.2)(happy-dom@21.0.4)(jiti@2.7.0)(typescript@7.0.2) p-cancelable@2.1.1: {} @@ -5866,7 +5950,7 @@ snapshots: util-deprecate@1.0.2: {} - vite-plus@1.3.0(@types/node@26.6.5)(@vitest/ui@5.0.5)(esbuild@0.28.2)(jiti@2.7.0)(typescript@7.0.2): + vite-plus@1.3.0(@types/node@26.6.5)(@vitest/ui@5.0.5)(esbuild@0.28.2)(happy-dom@21.0.4)(jiti@2.7.0)(typescript@7.0.2): dependencies: '@oxc-project/types': 0.154.0 '@oxlint/plugins': 1.88.0 @@ -5877,11 +5961,11 @@ snapshots: '@vitest/snapshot': 5.0.5 '@vitest/spy': 5.0.5 '@vitest/utils': 5.0.5 - oxfmt: 0.73.0(vite-plus@1.3.0(@types/node@26.6.5)(@vitest/ui@5.0.5)(esbuild@0.28.2)(jiti@2.7.0)(typescript@7.0.2)) - oxlint: 1.88.0(oxlint-tsgolint@7.0.2004)(vite-plus@1.3.0(@types/node@26.6.5)(@vitest/ui@5.0.5)(esbuild@0.28.2)(jiti@2.7.0)(typescript@7.0.2)) + oxfmt: 0.73.0(vite-plus@1.3.0(@types/node@26.6.5)(@vitest/ui@5.0.5)(esbuild@0.28.2)(happy-dom@21.0.4)(jiti@2.7.0)(typescript@7.0.2)) + oxlint: 1.88.0(oxlint-tsgolint@7.0.2004)(vite-plus@1.3.0(@types/node@26.6.5)(@vitest/ui@5.0.5)(esbuild@0.28.2)(happy-dom@21.0.4)(jiti@2.7.0)(typescript@7.0.2)) oxlint-tsgolint: 7.0.2004 vite: '@voidzero-dev/vite-plus-core@1.3.0(@types/node@26.6.5)(esbuild@0.28.2)(jiti@2.7.0)(typescript@7.0.2)' - vitest: 5.0.5(@types/node@26.6.5)(@vitest/browser-preview@5.0.5)(@vitest/ui@5.0.5)(@voidzero-dev/vite-plus-core@1.3.0(@types/node@26.6.5)(esbuild@0.28.2)(jiti@2.7.0)(typescript@7.0.2)) + vitest: 5.0.5(@types/node@26.6.5)(@vitest/browser-preview@5.0.5)(@vitest/ui@5.0.5)(@voidzero-dev/vite-plus-core@1.3.0(@types/node@26.6.5)(esbuild@0.28.2)(jiti@2.7.0)(typescript@7.0.2))(happy-dom@21.0.4) optionalDependencies: '@voidzero-dev/vite-plus-darwin-arm64': 1.3.0 '@voidzero-dev/vite-plus-darwin-x64': 1.3.0 @@ -5926,7 +6010,7 @@ snapshots: - vue-tsc - yaml - vitest@5.0.5(@types/node@26.6.5)(@vitest/browser-preview@5.0.5)(@vitest/ui@5.0.5)(@voidzero-dev/vite-plus-core@1.3.0(@types/node@26.6.5)(esbuild@0.28.2)(jiti@2.7.0)(typescript@7.0.2)): + vitest@5.0.5(@types/node@26.6.5)(@vitest/browser-preview@5.0.5)(@vitest/ui@5.0.5)(@voidzero-dev/vite-plus-core@1.3.0(@types/node@26.6.5)(esbuild@0.28.2)(jiti@2.7.0)(typescript@7.0.2))(happy-dom@21.0.4): dependencies: '@types/chai': 5.2.3 '@vitest/mocker': 5.0.5(@voidzero-dev/vite-plus-core@1.3.0(@types/node@26.6.5)(esbuild@0.28.2)(jiti@2.7.0)(typescript@7.0.2)) @@ -5946,6 +6030,7 @@ snapshots: '@types/node': 26.6.5 '@vitest/browser-preview': 5.0.5(@voidzero-dev/vite-plus-core@1.3.0(@types/node@26.6.5)(esbuild@0.28.2)(jiti@2.7.0)(typescript@7.0.2))(vitest@5.0.5) '@vitest/ui': 5.0.5(vitest@5.0.5) + happy-dom: 21.0.4 transitivePeerDependencies: - msw @@ -5969,6 +6054,8 @@ snapshots: tiny-typed-emitter: 2.1.0 websocket-extensions: 0.1.4 + whatwg-mimetype@3.0.0: {} + which-module@2.0.1: {} which@2.0.2: diff --git a/site/plugins/app-source.config.ts b/site/plugins/app-source.config.ts index 70c53038..f5ddb144 100644 --- a/site/plugins/app-source.config.ts +++ b/site/plugins/app-source.config.ts @@ -85,36 +85,4 @@ export const APP_PATCHES: readonly AppPatch[] = [ file: "components/page-header/page-header.component.tsx", replacements: [{ from: "id={PAGE_HEADER.headingId} ", to: "" }], }, - // Contrast and hover feedback on already-active controls. - { - file: "components/pill/pill.component.tsx", - replacements: [ - { - from: '"border-foreground bg-foreground text-background"', - to: '"border-foreground bg-foreground text-background hover:bg-foreground/85"', - }, - ], - }, - { - file: "components/breakdown-panel/breakdown-panel.component.tsx", - replacements: [ - { - from: '"rounded px-2 py-1 text-xs text-muted-foreground transition-colors"', - to: '"rounded px-2 py-1 text-xs text-muted-foreground transition-colors hover:text-foreground"', - }, - { - from: 'active === tab.key && "bg-card font-medium text-foreground shadow-sm"', - to: 'active === tab.key && "bg-card font-medium text-foreground shadow-sm hover:bg-accent"', - }, - ], - }, - { - file: "components/unit-card/unit-card.component.tsx", - replacements: [ - { - from: 'className="absolute inset-0 rounded-lg"', - to: 'className="absolute inset-0 rounded-lg transition-colors hover:bg-foreground/5"', - }, - ], - }, ]; diff --git a/site/src/mock/demo/tradeup-demo-inline.tsx b/site/src/mock/demo/tradeup-demo-inline.tsx index 61ff6b3d..c9092789 100644 --- a/site/src/mock/demo/tradeup-demo-inline.tsx +++ b/site/src/mock/demo/tradeup-demo-inline.tsx @@ -1,5 +1,6 @@ import { Button } from "~/components/button/button.component"; import { ItemCell } from "~/components/item-cell/item-cell.component"; +import { ItemInspectButton } from "~/components/item-inspect/item-inspect.component"; import { Panel } from "~/components/panel/panel.component"; import { COPY } from "~/lib/copy/copy.config"; import { cn } from "~/utils/cn"; @@ -37,11 +38,16 @@ export function TradeUpInlineInputs({ const isSelected = selectedIds.has(item.id); const disabled = !isSelected && selected >= inputCount; return ( -
  • +
  • +
    + +
  • ); })} diff --git a/site/src/styles/index.css b/site/src/styles/index.css index 9ffec9b4..28423b62 100644 --- a/site/src/styles/index.css +++ b/site/src/styles/index.css @@ -2,6 +2,7 @@ @layer theme, base, site, utilities; @import "./tokens.css"; +@import "../../../src/components/item-thumb/item-thumb.css" layer(site); @import "./base.css" layer(site); /* One CSS file per section component; each is owned by exactly one component. */ @import "./sections/header.css" layer(site); @@ -24,6 +25,7 @@ @theme inline { --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif; --font-mono: ui-monospace, "SF Mono", "SFMono-Regular", Menlo, Consolas, monospace; + --font-display: ui-serif, "New York", "Iowan Old Style", Charter, Georgia, serif; --color-background: var(--background); --color-foreground: var(--foreground); --color-card: var(--card); @@ -37,9 +39,23 @@ --color-success: var(--success); --color-destructive: var(--destructive); --color-warning: var(--warning); - --radius-lg: 0.625rem; - --radius-md: 0.5rem; - --radius-sm: 0.375rem; + /* Tokens the app's spec-sheet components use; values sit on .oi-app below. */ + --color-accent-foreground: var(--accent-foreground); + --color-accent-ink: var(--accent-ink); + --color-accent-edge: var(--accent-edge); + --color-primary-edge: var(--primary-edge); + --color-border-strong: var(--border-strong); + --color-control: var(--control-border); + --color-fill-1: var(--fill-1); + --color-fill-2: var(--fill-2); + --color-fill-3: var(--fill-3); + --color-fill-4: var(--fill-4); + --color-fill-5: var(--fill-5); + --color-slot-empty: var(--slot-empty); + --radius-xl: 0.5rem; + --radius-lg: 0.5rem; + --radius-md: 0.375rem; + --radius-sm: 0.25rem; } /* The vendored app: tokens scoped to its frame, plus a small reset (Tailwind's preflight stays off). */ @@ -48,6 +64,9 @@ --background: #0a0a0a; --foreground: #f5f5f5; --card: color-mix(in srgb, #0a0a0a 97%, white); + --thumb-base-tint: 18%; + --thumb-dot-tint: 100%; + --thumb-art-tone: contrast(0.82) brightness(1.13); --muted: rgb(255 255 255 / 0.03); --muted-foreground: #8d8d8d; --border: rgb(255 255 255 / 0.08); @@ -60,6 +79,32 @@ --warning: #fbbf24; --skeleton: rgb(255 255 255 / 0.06); --skeleton-highlight: rgb(255 255 255 / 0.1); + --accent-foreground: var(--foreground); + --accent-ink: var(--primary); + --accent-edge: transparent; + --primary-edge: transparent; + --border-strong: rgb(255 255 255 / 0.12); + --control-border: #636363; + --fill-1: #f5f5f5; + --fill-2: #9a9a9a; + --fill-3: #5c5c5c; + --fill-4: #3a3a3a; + --fill-5: #262626; + --slot-empty: rgb(255 255 255 / 0.1); + /* Data-visualisation palette, dark values from the app's src/index.css. */ + --chart-1: #87bafd; + --chart-2: #c97409; + --chart-3: #2bd2c2; + --chart-4: #d8559b; + --chart-5: #b385fb; + --chart-6: #f3c935; + --chart-7: #0f99c9; + --chart-8: #fd968f; + --wear-1: #b5e2fd; + --wear-2: #74ccfe; + --wear-3: #33b4f2; + --wear-4: #109bd5; + --wear-5: #0481b3; } /* The landing's global `button { border: 0 }` (layer site) resets border colour to currentColor and outranks the app reset below; restore the app's token. */ @@ -133,6 +178,34 @@ .oi-app .tabular { font-variant-numeric: tabular-nums; } + /* Spec-sheet helpers from the app's src/index.css. */ + .oi-app .figure { + font-family: ui-serif, "New York", "Iowan Old Style", Charter, Georgia, serif; + font-variant-numeric: lining-nums tabular-nums; + font-weight: 400; + letter-spacing: -0.03em; + } + .oi-app .kicker { + font-size: 11px; + font-weight: 500; + letter-spacing: 0.08em; + text-transform: uppercase; + color: var(--muted-foreground); + } + .oi-app .live-dot { + display: inline-block; + width: 7px; + height: 7px; + flex: none; + border-radius: 50%; + background: var(--primary); + } + .oi-app .belt-tile { + left: calc(50% - 1.25rem); + } + .oi-app .focus-inset:focus-visible { + outline-offset: -2px; + } .oi-app :focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; diff --git a/src/components/account-actions/account-actions.test.tsx b/src/components/account-actions/account-actions.test.tsx new file mode 100644 index 00000000..97abe02f --- /dev/null +++ b/src/components/account-actions/account-actions.test.tsx @@ -0,0 +1,70 @@ +/* oxlint-disable typescript/no-floating-promises -- node:test registers suites synchronously */ +import assert from "node:assert/strict"; +import { afterEach, beforeEach, describe, test } from "node:test"; +import { COPY } from "~/lib/copy/copy.config"; +import { useAddAccountDialog } from "~/lib/accounts/add-account-dialog.store"; +import { STORAGE_API } from "~/lib/storage/storage.config"; +import { installFakeApi, STEAM_ID_A, type FakeApi } from "~test/fake-api"; +import { render, screen, setupUser, waitFor } from "~test/ui"; +import { AccountActions } from "./account-actions.component"; + +const copy = COPY.accounts; + +describe("AccountActions", () => { + let api: FakeApi; + beforeEach(() => { + api = installFakeApi(); + useAddAccountDialog.setState({ open: false, target: undefined }); + }); + afterEach(() => api.restore()); + + test("Reconnect posts the account id", async () => { + render(); + await setupUser().click(screen.getByRole("button", { name: copy.reconnect })); + await waitFor(() => assert.equal(api.calls.length, 1)); + assert.deepEqual(api.calls[0], { + path: STORAGE_API.accountReconnect, + method: "POST", + body: { accountId: STEAM_ID_A }, + }); + }); + + test("a failed reconnect shows the server message as an alert", async () => { + api.respond(STORAGE_API.accountReconnect, () => ({ status: 500, body: { error: "boom" } })); + render(); + await setupUser().click(screen.getByRole("button", { name: copy.reconnect })); + assert.equal((await screen.findByRole("alert")).textContent, "boom"); + }); + + test("Sign in again opens the re-auth dialog for the account", async () => { + render(); + await setupUser().click(screen.getByRole("button", { name: copy.signInAgain })); + const state = useAddAccountDialog.getState(); + assert.equal(state.open, true); + assert.equal(state.target, STEAM_ID_A); + }); + + test("a second click while reconnecting sends nothing more", async () => { + let release: () => void = () => {}; + const gate = new Promise((resolve) => (release = resolve)); + const realFetch = globalThis.fetch; + let requests = 0; + globalThis.fetch = (async () => { + requests += 1; + await gate; + return new Response("{}"); + }) as typeof fetch; + try { + render(); + const user = setupUser(); + await user.click(screen.getByRole("button", { name: copy.reconnect })); + const busy = await screen.findByRole("button", { name: copy.reconnecting }); + await user.click(busy); + assert.equal(requests, 1); + release(); + await screen.findByRole("button", { name: copy.reconnect }); + } finally { + globalThis.fetch = realFetch; + } + }); +}); diff --git a/src/components/account-gate/account-gate.test.tsx b/src/components/account-gate/account-gate.test.tsx new file mode 100644 index 00000000..3b3d20b4 --- /dev/null +++ b/src/components/account-gate/account-gate.test.tsx @@ -0,0 +1,117 @@ +/* oxlint-disable typescript/no-floating-promises -- node:test registers suites synchronously */ +import assert from "node:assert/strict"; +import { afterEach, beforeEach, describe, test } from "node:test"; +import { useAccountSelection } from "~/lib/accounts/account-scope.store"; +import { ALL_ACCOUNTS } from "~/lib/accounts/accounts.config"; +import { COPY } from "~/lib/copy/copy.config"; +import { AUTH_STATUS, STORAGE_API } from "~/lib/storage/storage.config"; +import { + accountState, + appSnapshot, + installFakeApi, + STEAM_ID_A, + STEAM_ID_B, + storageSnapshot, + type FakeApi, +} from "~test/fake-api"; +import { renderWithRouter } from "~test/router"; +import { screen, setupUser, waitFor } from "~test/ui"; +import { AccountGate } from "./account-gate.component"; + +const copy = COPY.accounts; +const READY = accountState(STEAM_ID_A, { displayName: "Alpha" }); +const READY_B = accountState(STEAM_ID_B, { displayName: "Bravo" }); +const BROKEN_B = accountState(STEAM_ID_B, { + displayName: "Bravo", + snapshot: storageSnapshot({ auth: { status: AUTH_STATUS.error, message: "Login failed" } }), +}); + +describe("AccountGate", () => { + let api: FakeApi; + beforeEach(() => { + api = installFakeApi(); + useAccountSelection.setState({ selected: undefined }); + }); + afterEach(() => api.restore()); + + function mount(pathname: string) { + return renderWithRouter( + +

    page

    +
    , + ); + } + + test("a connected account sees the page, with no notice", async () => { + await mount("/storage"); + await api.push(appSnapshot([READY])); + assert.ok(screen.getByText("page")); + assert.equal(screen.getByRole("status").textContent, ""); + }); + + test("in the all view, a one-account page asks which account", async () => { + useAccountSelection.setState({ selected: ALL_ACCOUNTS }); + await mount("/storage"); + await api.push(appSnapshot([READY, READY_B])); + assert.ok(screen.getByRole("heading", { name: copy.chooseOneTitle })); + assert.ok(screen.getByText(copy.chooseOneBody["/storage"] ?? "")); + assert.ok(screen.queryByText("page") === null); + }); + + test("choosing an account in that prompt selects it and shows the page", async () => { + useAccountSelection.setState({ selected: ALL_ACCOUNTS }); + await mount("/storage"); + await api.push(appSnapshot([READY, READY_B])); + await setupUser().click(screen.getByRole("button", { name: /Bravo/ })); + assert.equal(useAccountSelection.getState().selected, STEAM_ID_B); + assert.ok(await screen.findByText("page")); + }); + + test("pages that can show every account skip the prompt", async () => { + useAccountSelection.setState({ selected: ALL_ACCOUNTS }); + await mount("/items"); + await api.push(appSnapshot([READY, READY_B])); + assert.ok(screen.getByText("page")); + }); + + test("settings is never gated, even for a broken account", async () => { + useAccountSelection.setState({ selected: STEAM_ID_B }); + await mount("/settings"); + await api.push(appSnapshot([READY, BROKEN_B])); + assert.ok(screen.getByText("page")); + }); + + test("a broken account shows its status instead of the page", async () => { + useAccountSelection.setState({ selected: STEAM_ID_B }); + await mount("/storage"); + await api.push(appSnapshot([READY, BROKEN_B])); + assert.ok(screen.queryByText("page") === null); + assert.equal(screen.getByRole("alert").textContent, "Login failed"); + }); + + test("in the all view a broken account leaves a notice but keeps the page", async () => { + useAccountSelection.setState({ selected: ALL_ACCOUNTS }); + await mount("/items"); + await api.push(appSnapshot([READY, BROKEN_B])); + assert.ok(screen.getByText("page")); + assert.equal(screen.getAllByRole("status")[0]?.textContent, copy.partialNotice(["Bravo"])); + assert.ok(screen.getByRole("link", { name: copy.partialSettings })); + assert.ok(screen.getByRole("button", { name: copy.reconnect })); + }); + + test("an idle account is asked to connect once", async () => { + const idle = accountState(STEAM_ID_A, { + snapshot: storageSnapshot({ auth: { status: AUTH_STATUS.idle } }), + }); + await mount("/storage"); + await api.push(appSnapshot([idle])); + await waitFor(() => assert.equal(api.calls.length, 1)); + assert.deepEqual(api.calls[0], { + path: STORAGE_API.accountConnect, + method: "POST", + body: { accountId: STEAM_ID_A }, + }); + await api.push({ ...appSnapshot([idle]), revision: 2 }); + assert.equal(api.calls.length, 1); + }); +}); diff --git a/src/components/account-name/account-name.test.tsx b/src/components/account-name/account-name.test.tsx new file mode 100644 index 00000000..9799a30e --- /dev/null +++ b/src/components/account-name/account-name.test.tsx @@ -0,0 +1,11 @@ +/* oxlint-disable typescript/no-floating-promises -- node:test registers suites synchronously */ +import assert from "node:assert/strict"; +import { test } from "node:test"; +import { render, screen } from "~test/ui"; +import { AccountName } from "./account-name.component"; + +test("AccountName shows the name and keeps a passed className", () => { + render(); + const node = screen.getByText("Alpha"); + assert.ok(node.classList.contains("extra")); +}); diff --git a/src/components/account-row/account-row.test.tsx b/src/components/account-row/account-row.test.tsx new file mode 100644 index 00000000..e0a26809 --- /dev/null +++ b/src/components/account-row/account-row.test.tsx @@ -0,0 +1,103 @@ +/* oxlint-disable typescript/no-floating-promises -- node:test registers suites synchronously */ +import assert from "node:assert/strict"; +import { afterEach, beforeEach, describe, test } from "node:test"; +import { authStatusText } from "~/lib/accounts/account-status"; +import { COPY } from "~/lib/copy/copy.config"; +import { AUTH_STATUS, STORAGE_API } from "~/lib/storage/storage.config"; +import { + accountState, + installFakeApi, + STEAM_ID_A, + storageSnapshot, + type FakeApi, +} from "~test/fake-api"; +import { render, screen, setupUser, waitFor } from "~test/ui"; +import { AccountRow } from "./account-row.component"; + +const copy = COPY.accounts; + +describe("AccountRow", () => { + let api: FakeApi; + beforeEach(() => { + api = installFakeApi(); + }); + afterEach(() => api.restore()); + + test("shows the account name and its connection status", () => { + render( {}} />); + assert.ok(screen.getByText("Alpha")); + assert.ok(screen.getByText(authStatusText(AUTH_STATUS.ready))); + }); + + test("choosing a label saves it for the account", async () => { + render( {}} />); + const user = setupUser(); + await user.click(screen.getByRole("combobox", { name: copy.labelAria("Alpha") })); + await user.click(screen.getByRole("option", { name: copy.labels.trade })); + await waitFor(() => assert.equal(api.calls.length, 1)); + assert.deepEqual(api.calls[0], { + path: STORAGE_API.accountLabel, + method: "POST", + body: { accountId: STEAM_ID_A, label: "trade" }, + }); + }); + + test("choosing No label clears it", async () => { + render( + {}} />, + ); + const user = setupUser(); + await user.click(screen.getByRole("combobox", { name: copy.labelAria("Alpha") })); + await user.click(screen.getByRole("option", { name: copy.unlabelled })); + await waitFor(() => assert.equal(api.calls.length, 1)); + assert.deepEqual(api.calls[0]?.body, { accountId: STEAM_ID_A, label: null }); + }); + + test("a failed label save is announced as an alert", async () => { + api.respond(STORAGE_API.accountLabel, () => ({ status: 400, body: { error: "bad label" } })); + render( {}} />); + const user = setupUser(); + await user.click(screen.getByRole("combobox", { name: copy.labelAria("Alpha") })); + await user.click(screen.getByRole("option", { name: copy.labels.alt })); + assert.equal((await screen.findByRole("alert")).textContent, "bad label"); + }); + + test("an errored account shows its message and recovery actions", () => { + const account = accountState(STEAM_ID_A, { + snapshot: storageSnapshot({ auth: { status: AUTH_STATUS.error, message: "Login failed" } }), + }); + render( {}} />); + assert.ok(screen.getByText("Login failed")); + assert.ok(screen.getByRole("button", { name: copy.reconnect })); + }); + + test("a healthy account has no recovery actions", () => { + render( {}} />); + assert.ok(screen.queryByRole("button", { name: copy.reconnect }) === null); + }); + + test("Remove asks for confirmation, then posts and reports onRemoved", async () => { + let removed = 0; + render( void (removed += 1)} />); + const user = setupUser(); + await user.click(screen.getByRole("button", { name: copy.removeAria("Alpha") })); + assert.ok(screen.getByRole("dialog", { name: copy.removeTitle("Alpha") })); + assert.equal(api.calls.length, 0); + await user.click(screen.getByRole("checkbox", { name: copy.removeCheckbox })); + await user.click(screen.getByRole("button", { name: copy.removeConfirm })); + await waitFor(() => assert.equal(removed, 1)); + assert.deepEqual(api.calls[0], { + path: STORAGE_API.accountRemove, + method: "POST", + body: { accountId: STEAM_ID_A }, + }); + }); + + test("cancelling the removal sends nothing", async () => { + render( {}} />); + const user = setupUser(); + await user.click(screen.getByRole("button", { name: copy.removeAria("Alpha") })); + await user.click(screen.getByRole("button", { name: copy.cancel })); + assert.equal(api.calls.length, 0); + }); +}); diff --git a/src/components/account-status-dot/account-status-dot.test.tsx b/src/components/account-status-dot/account-status-dot.test.tsx new file mode 100644 index 00000000..26f27a46 --- /dev/null +++ b/src/components/account-status-dot/account-status-dot.test.tsx @@ -0,0 +1,33 @@ +/* oxlint-disable typescript/no-floating-promises -- node:test registers suites synchronously */ +import assert from "node:assert/strict"; +import { describe, test } from "node:test"; +import { authStatusText } from "~/lib/accounts/account-status"; +import { AUTH_STATUS } from "~/lib/storage/storage.config"; +import { render, screen } from "~test/ui"; +import { AccountStatusDot } from "./account-status-dot.component"; + +describe("AccountStatusDot", () => { + test("pairs the dot with the status as text", () => { + render(); + assert.ok(screen.getByText(authStatusText(AUTH_STATUS.error))); + }); + + test("custom text replaces the default status text", () => { + render(); + assert.ok(screen.getByText("3 accounts")); + assert.ok(screen.queryByText(authStatusText(AUTH_STATUS.ready)) === null); + }); + + test("decorative drops the text entirely", () => { + const { container } = render(); + assert.equal(container.textContent, ""); + }); + + test("each status reads its own text", () => { + for (const status of Object.values(AUTH_STATUS)) { + const { unmount } = render(); + assert.ok(screen.getByText(authStatusText(status))); + unmount(); + } + }); +}); diff --git a/src/components/account-status/account-status.test.tsx b/src/components/account-status/account-status.test.tsx new file mode 100644 index 00000000..ba287f2d --- /dev/null +++ b/src/components/account-status/account-status.test.tsx @@ -0,0 +1,48 @@ +/* oxlint-disable typescript/no-floating-promises -- node:test registers suites synchronously */ +import assert from "node:assert/strict"; +import { describe, test } from "node:test"; +import { COPY } from "~/lib/copy/copy.config"; +import { AUTH_STATUS } from "~/lib/storage/storage.config"; +import { accountState, STEAM_ID_A, storageSnapshot } from "~test/fake-api"; +import { render, screen } from "~test/ui"; +import { AccountStatus } from "./account-status.component"; + +const copy = COPY.accounts; + +describe("AccountStatus", () => { + test("an errored account shows the message as an alert with recovery actions", () => { + const account = accountState(STEAM_ID_A, { + snapshot: storageSnapshot({ auth: { status: AUTH_STATUS.error, message: "Bad login" } }), + }); + render(); + assert.equal(screen.getByRole("alert").textContent, "Bad login"); + assert.ok(screen.getByRole("button", { name: copy.reconnect })); + assert.ok(screen.getByRole("button", { name: copy.signInAgain })); + }); + + test("a connecting account shows the connection detail", () => { + const account = accountState(STEAM_ID_A, { + snapshot: storageSnapshot({ auth: { status: AUTH_STATUS.connecting, detail: "Logging on" } }), + }); + render(); + assert.equal(screen.getByRole("status").textContent, "Logging on"); + assert.ok(screen.queryByRole("alert") === null); + }); + + test("an idle account shows the generic connecting line", () => { + const account = accountState(STEAM_ID_A, { + snapshot: storageSnapshot({ auth: { status: AUTH_STATUS.idle } }), + }); + render(); + assert.equal(screen.getByRole("status").textContent, copy.connecting); + }); + + test("the region is named after the account", () => { + const account = accountState(STEAM_ID_A, { + displayName: "Alpha", + snapshot: storageSnapshot({ auth: { status: AUTH_STATUS.idle } }), + }); + render(); + assert.ok(screen.getByRole("region", { name: copy.notReadyTitle("Alpha") })); + }); +}); diff --git a/src/components/account-switcher/account-switcher.test.tsx b/src/components/account-switcher/account-switcher.test.tsx new file mode 100644 index 00000000..f0070a59 --- /dev/null +++ b/src/components/account-switcher/account-switcher.test.tsx @@ -0,0 +1,100 @@ +/* oxlint-disable typescript/no-floating-promises -- node:test registers suites synchronously */ +import assert from "node:assert/strict"; +import { afterEach, beforeEach, describe, test } from "node:test"; +import { ALL_ACCOUNTS } from "~/lib/accounts/accounts.config"; +import { useAccountSelection } from "~/lib/accounts/account-scope.store"; +import { useAddAccountDialog } from "~/lib/accounts/add-account-dialog.store"; +import { COPY } from "~/lib/copy/copy.config"; +import { + accountState, + appSnapshot, + installFakeApi, + STEAM_ID_A, + STEAM_ID_B, + type FakeApi, +} from "~test/fake-api"; +import { render, screen, setupUser } from "~test/ui"; +import { AccountSwitcher } from "./account-switcher.component"; + +const copy = COPY.accounts; + +describe("AccountSwitcher", () => { + let api: FakeApi; + beforeEach(() => { + api = installFakeApi(); + useAccountSelection.setState({ selected: undefined }); + useAddAccountDialog.setState({ open: false, target: undefined }); + }); + afterEach(() => api.restore()); + + test("renders nothing before any account exists", async () => { + const { container } = render(); + await api.push(appSnapshot([])); + assert.equal(container.textContent, ""); + }); + + test("with one account it offers only an Add account button", async () => { + render(); + await api.push(appSnapshot([accountState(STEAM_ID_A)])); + assert.ok(screen.getByText("Alpha")); + assert.ok(screen.queryByRole("combobox") === null); + await setupUser().click(screen.getByRole("button", { name: copy.add })); + assert.equal(useAddAccountDialog.getState().open, true); + }); + + test("with several accounts it lists All, each account and Add", async () => { + render(); + await api.push( + appSnapshot([ + accountState(STEAM_ID_A, { displayName: "Alpha" }), + accountState(STEAM_ID_B, { displayName: "Bravo" }), + ]), + ); + const user = setupUser(); + await user.click(screen.getByRole("combobox", { name: copy.switcherLabel })); + const names = screen.getAllByRole("option").map((option) => option.textContent ?? ""); + assert.ok(names.some((text) => text.includes(copy.all))); + assert.ok(names.some((text) => text.includes("Alpha"))); + assert.ok(names.some((text) => text.includes("Bravo"))); + assert.ok(names.some((text) => text.includes(copy.add))); + }); + + test("picking an account selects it", async () => { + render(); + await api.push( + appSnapshot([ + accountState(STEAM_ID_A, { displayName: "Alpha" }), + accountState(STEAM_ID_B, { displayName: "Bravo" }), + ]), + ); + const user = setupUser(); + await user.click(screen.getByRole("combobox", { name: copy.switcherLabel })); + await user.click(screen.getByRole("option", { name: /Bravo/ })); + assert.equal(useAccountSelection.getState().selected, STEAM_ID_B); + }); + + test("picking All selects every account", async () => { + useAccountSelection.setState({ selected: STEAM_ID_A }); + render(); + await api.push( + appSnapshot([accountState(STEAM_ID_A), accountState(STEAM_ID_B, { displayName: "Bravo" })]), + ); + const user = setupUser(); + await user.click(screen.getByRole("combobox", { name: copy.switcherLabel })); + await user.click(screen.getByRole("option", { name: new RegExp(copy.all) })); + assert.equal(useAccountSelection.getState().selected, ALL_ACCOUNTS); + }); + + test("the Add account entry opens the dialog and keeps the selection", async () => { + useAccountSelection.setState({ selected: STEAM_ID_A }); + render(); + await api.push( + appSnapshot([accountState(STEAM_ID_A), accountState(STEAM_ID_B, { displayName: "Bravo" })]), + ); + const user = setupUser(); + await user.click(screen.getByRole("combobox", { name: copy.switcherLabel })); + await user.click(screen.getByRole("option", { name: new RegExp(copy.add) })); + assert.equal(useAddAccountDialog.getState().open, true); + assert.equal(useAccountSelection.getState().selected, STEAM_ID_A); + }); +}); diff --git a/src/components/accounts-panel/accounts-panel.test.tsx b/src/components/accounts-panel/accounts-panel.test.tsx new file mode 100644 index 00000000..fbf5cfa0 --- /dev/null +++ b/src/components/accounts-panel/accounts-panel.test.tsx @@ -0,0 +1,47 @@ +/* oxlint-disable typescript/no-floating-promises -- node:test registers suites synchronously */ +import assert from "node:assert/strict"; +import { afterEach, beforeEach, describe, test } from "node:test"; +import { useAddAccountDialog } from "~/lib/accounts/add-account-dialog.store"; +import { COPY } from "~/lib/copy/copy.config"; +import { + accountState, + appSnapshot, + installFakeApi, + STEAM_ID_A, + STEAM_ID_B, + type FakeApi, +} from "~test/fake-api"; +import { render, screen, setupUser } from "~test/ui"; +import { AccountsPanel } from "./accounts-panel.component"; + +const copy = COPY.accounts; + +describe("AccountsPanel", () => { + let api: FakeApi; + beforeEach(() => { + api = installFakeApi(); + useAddAccountDialog.setState({ open: false }); + }); + afterEach(() => api.restore()); + + test("lists every tracked account", async () => { + render(); + await api.push( + appSnapshot([ + accountState(STEAM_ID_A, { displayName: "Alpha" }), + accountState(STEAM_ID_B, { displayName: "Bravo" }), + ]), + ); + assert.ok(screen.getByRole("heading", { name: copy.settingsTitle })); + assert.equal(screen.getAllByRole("listitem").length, 2); + assert.ok(screen.getByRole("button", { name: copy.removeAria("Alpha") })); + assert.ok(screen.getByRole("button", { name: copy.removeAria("Bravo") })); + }); + + test("Add account opens the sign-in dialog", async () => { + render(); + await api.push(appSnapshot([accountState(STEAM_ID_A)])); + await setupUser().click(screen.getByRole("button", { name: copy.add })); + assert.equal(useAddAccountDialog.getState().open, true); + }); +}); diff --git a/src/components/add-account-dialog/add-account-dialog.config.ts b/src/components/add-account-dialog/add-account-dialog.config.ts index ce256e4c..75e30968 100644 --- a/src/components/add-account-dialog/add-account-dialog.config.ts +++ b/src/components/add-account-dialog/add-account-dialog.config.ts @@ -1,6 +1,6 @@ export const ADD_ACCOUNT_DIALOG = { dialogClass: - "m-auto w-[min(92vw,26rem)] rounded-xl border bg-card p-0 text-foreground shadow-lg backdrop:bg-black/50", + "m-auto w-[min(92vw,26rem)] rounded-lg border border-border-strong bg-card p-0 text-foreground backdrop:bg-black/60", bodyClass: "flex flex-col gap-4 p-6", cancelClass: "self-end", } as const; diff --git a/src/components/add-account-dialog/add-account-dialog.test.tsx b/src/components/add-account-dialog/add-account-dialog.test.tsx new file mode 100644 index 00000000..ac2d0860 --- /dev/null +++ b/src/components/add-account-dialog/add-account-dialog.test.tsx @@ -0,0 +1,90 @@ +/* oxlint-disable typescript/no-floating-promises -- node:test registers suites synchronously */ +import assert from "node:assert/strict"; +import { afterEach, beforeEach, describe, test } from "node:test"; +import { useAddAccountDialog } from "~/lib/accounts/add-account-dialog.store"; +import { COPY } from "~/lib/copy/copy.config"; +import { AUTH_STATUS, STORAGE_API } from "~/lib/storage/storage.config"; +import type { AppSnapshot } from "~/lib/storage/storage.types"; +import { + accountState, + appSnapshot, + installFakeApi, + STEAM_ID_A, + STEAM_ID_B, + type FakeApi, +} from "~test/fake-api"; +import { act, render, screen, setupUser, waitFor } from "~test/ui"; +import { AddAccountDialog } from "./add-account-dialog.component"; + +const copy = COPY.accounts; + +function withLogin(snapshot: AppSnapshot, patch: Partial): AppSnapshot { + return { ...snapshot, ...patch }; +} + +describe("AddAccountDialog", () => { + let api: FakeApi; + beforeEach(() => { + api = installFakeApi(); + useAddAccountDialog.setState({ open: false, target: undefined, outcome: undefined }); + }); + afterEach(() => api.restore()); + + test("stays closed until opened", async () => { + render(); + await api.push(appSnapshot([accountState(STEAM_ID_A)])); + assert.ok(screen.queryByRole("dialog") === null); + }); + + test("opening for a new account shows the add title and a way to start", async () => { + render(); + await api.push(appSnapshot([accountState(STEAM_ID_A)])); + await act(async () => useAddAccountDialog.getState().openAdd()); + assert.ok(screen.getByRole("dialog", { name: copy.addTitle })); + assert.ok(screen.getByRole("button", { name: COPY.signIn.button })); + }); + + test("re-auth names the account being signed in again", async () => { + render(); + await api.push(appSnapshot([accountState(STEAM_ID_A, { displayName: "Alpha" })])); + await act(async () => useAddAccountDialog.getState().openReauth(STEAM_ID_A)); + assert.ok(screen.getByRole("dialog", { name: copy.reauthTitle("Alpha") })); + }); + + test("Cancel closes the dialog", async () => { + render(); + await api.push(appSnapshot([accountState(STEAM_ID_A)])); + await act(async () => useAddAccountDialog.getState().openAdd()); + await setupUser().click(screen.getByRole("button", { name: copy.cancel })); + await waitFor(() => assert.equal(useAddAccountDialog.getState().open, false)); + }); + + test("cancelling mid sign-in also abandons the login on the server", async () => { + render(); + const base = appSnapshot([accountState(STEAM_ID_A)]); + await api.push( + withLogin(base, { login: { status: AUTH_STATUS.qrPending, qrSvg: "" } }), + ); + await act(async () => useAddAccountDialog.getState().openAdd()); + await setupUser().click(screen.getByRole("button", { name: copy.cancel })); + await waitFor(() => + assert.ok(api.calls.some((call) => call.path === STORAGE_API.accountLoginCancel)), + ); + }); + + test("a finished sign-in closes the dialog and records the outcome", async () => { + render(); + const base = appSnapshot([accountState(STEAM_ID_A)]); + await api.push(base); + await act(async () => useAddAccountDialog.getState().openAdd()); + await api.push( + withLogin(base, { + accounts: [accountState(STEAM_ID_A), accountState(STEAM_ID_B)], + lastLogin: { sequence: 1, steamId: STEAM_ID_B, added: true }, + }), + ); + const state = useAddAccountDialog.getState(); + assert.equal(state.open, false); + assert.deepEqual(state.outcome, { steamId: STEAM_ID_B, added: true, target: undefined }); + }); +}); diff --git a/src/components/app-shell-skeleton/app-shell-skeleton.test.tsx b/src/components/app-shell-skeleton/app-shell-skeleton.test.tsx new file mode 100644 index 00000000..5ee6ce88 --- /dev/null +++ b/src/components/app-shell-skeleton/app-shell-skeleton.test.tsx @@ -0,0 +1,10 @@ +/* oxlint-disable typescript/no-floating-promises -- node:test registers suites synchronously */ +import assert from "node:assert/strict"; +import { test } from "node:test"; +import { render } from "~test/ui"; +import { AppShellSkeleton } from "./app-shell-skeleton.component"; + +test("AppShellSkeleton renders a non-empty placeholder", () => { + const { container } = render(); + assert.ok(container.firstElementChild); +}); diff --git a/src/components/app-shell/app-shell.component.tsx b/src/components/app-shell/app-shell.component.tsx index 136b18ab..2bcbd3ce 100644 --- a/src/components/app-shell/app-shell.component.tsx +++ b/src/components/app-shell/app-shell.component.tsx @@ -56,11 +56,11 @@ export function AppShell() { {APP_SHELL.skipLink}
    -
    -