diff --git a/api/numberGame/Player.js b/api/numberGame/Player.js index 05a14dc..d6cd8a5 100644 --- a/api/numberGame/Player.js +++ b/api/numberGame/Player.js @@ -7,6 +7,7 @@ class Player { this.totalScore = 0 this.nextRound = false this.avatar = avatar; + this.host = false } guess(num) { diff --git a/api/tests/numberGame/Player.test.js b/api/tests/numberGame/Player.test.js index 81c7bb6..1d63bb5 100644 --- a/api/tests/numberGame/Player.test.js +++ b/api/tests/numberGame/Player.test.js @@ -20,14 +20,26 @@ describe('player', () => { const player = new Player('17326746', 'Bob') expect(player.getTotalScore()).toBe(0) }) + test('wonRound adds 1 to total score', () => { const player = new Player('17326746', 'Bob') player.wonRound() expect(player.totalScore).toEqual(1) }) - test('setIsHost makes player isHost true', () => { + + test('setIsHost', () => { const player = new Player('17326746', 'Bob') player.setIsHost() expect(player.isHost).toEqual(true) + + test('voteNextRound', () => { + const player = new Player('17326746', 'Bob') + player.voteNextRound() + expect(player.nextRound).toEqual(true) + }) + test('setAvatar', () => { + const player = new Player('17326746', 'Bob') + player.setAvatar("avatar") + expect(player.avatar).toEqual("avatar") }) }) \ No newline at end of file diff --git a/api/tests/numberGame/game.test.js b/api/tests/numberGame/game.test.js index 82d9c7a..d310488 100644 --- a/api/tests/numberGame/game.test.js +++ b/api/tests/numberGame/game.test.js @@ -192,4 +192,9 @@ describe("Game", () => { fetchMock.resetMocks(); }); }); + describe("checkNextRound", () => { + test("given all players next round equals false", () => { + expect(game.checkNextRound()).toEqual(true) + }) + }) }); diff --git a/frontend/package-lock.json b/frontend/package-lock.json index db3e7b7..7ed9ff0 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -21,6 +21,7 @@ "@types/react-dom": "^18.3.0", "@vitejs/plugin-react": "^4.3.2", "@vitejs/plugin-react-swc": "^3.3.2", + "@vitest/coverage-v8": "^2.1.3", "@vitest/ui": "^2.1.3", "autoprefixer": "^10.4.20", "eslint": "^9.11.1", @@ -468,6 +469,13 @@ "node": ">=6.9.0" } }, + "node_modules/@bcoe/v8-coverage": { + "version": "0.2.3", + "resolved": "https://registry.npmjs.org/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz", + "integrity": "sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==", + "dev": true, + "license": "MIT" + }, "node_modules/@esbuild/aix-ppc64": { "version": "0.21.5", "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.21.5.tgz", @@ -1115,6 +1123,16 @@ "node": ">=12" } }, + "node_modules/@istanbuljs/schema": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/@istanbuljs/schema/-/schema-0.1.3.tgz", + "integrity": "sha512-ZXRY4jNvVgSVQ8DL3LTcakaAtXwTVUxE81hslsyD2AtoXW/wVob10HkOJ1X/pAlcI7D+2YoZKg5do8G/w6RYgA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, "node_modules/@jridgewell/gen-mapping": { "version": "0.3.5", "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.5.tgz", @@ -2129,6 +2147,39 @@ "vite": "^4 || ^5" } }, + "node_modules/@vitest/coverage-v8": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/@vitest/coverage-v8/-/coverage-v8-2.1.3.tgz", + "integrity": "sha512-2OJ3c7UPoFSmBZwqD2VEkUw6A/tzPF0LmW0ZZhhB8PFxuc+9IBG/FaSM+RLEenc7ljzFvGN+G0nGQoZnh7sy2A==", + "dev": true, + "license": "MIT", + "dependencies": { + "@ampproject/remapping": "^2.3.0", + "@bcoe/v8-coverage": "^0.2.3", + "debug": "^4.3.6", + "istanbul-lib-coverage": "^3.2.2", + "istanbul-lib-report": "^3.0.1", + "istanbul-lib-source-maps": "^5.0.6", + "istanbul-reports": "^3.1.7", + "magic-string": "^0.30.11", + "magicast": "^0.3.4", + "std-env": "^3.7.0", + "test-exclude": "^7.0.1", + "tinyrainbow": "^1.2.0" + }, + "funding": { + "url": "https://opencollective.com/vitest" + }, + "peerDependencies": { + "@vitest/browser": "2.1.3", + "vitest": "2.1.3" + }, + "peerDependenciesMeta": { + "@vitest/browser": { + "optional": true + } + } + }, "node_modules/@vitest/expect": { "version": "2.1.3", "resolved": "https://registry.npmjs.org/@vitest/expect/-/expect-2.1.3.tgz", @@ -4372,6 +4423,13 @@ "node": ">=12" } }, + "node_modules/html-escaper": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/html-escaper/-/html-escaper-2.0.2.tgz", + "integrity": "sha512-H2iMtd0I4Mt5eYiapRdIDjp+XzelXQ0tFE4JS7YFwFevXXMmOp9myNrUvCg0D6ws8iqkRPBfKHgbwig1SmlLfg==", + "dev": true, + "license": "MIT" + }, "node_modules/http-proxy-agent": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/http-proxy-agent/-/http-proxy-agent-5.0.0.tgz", @@ -4891,6 +4949,60 @@ "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", "license": "ISC" }, + "node_modules/istanbul-lib-coverage": { + "version": "3.2.2", + "resolved": "https://registry.npmjs.org/istanbul-lib-coverage/-/istanbul-lib-coverage-3.2.2.tgz", + "integrity": "sha512-O8dpsF+r0WV/8MNRKfnmrtCWhuKjxrq2w+jpzBL5UZKTi2LeVWnWOmWRxFlesJONmc+wLAGvKQZEOanko0LFTg==", + "dev": true, + "license": "BSD-3-Clause", + "engines": { + "node": ">=8" + } + }, + "node_modules/istanbul-lib-report": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/istanbul-lib-report/-/istanbul-lib-report-3.0.1.tgz", + "integrity": "sha512-GCfE1mtsHGOELCU8e/Z7YWzpmybrx/+dSTfLrvY8qRmaY6zXTKWn6WQIjaAFw069icm6GVMNkgu0NzI4iPZUNw==", + "dev": true, + "license": "BSD-3-Clause", + "dependencies": { + "istanbul-lib-coverage": "^3.0.0", + "make-dir": "^4.0.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/istanbul-lib-source-maps": { + "version": "5.0.6", + "resolved": "https://registry.npmjs.org/istanbul-lib-source-maps/-/istanbul-lib-source-maps-5.0.6.tgz", + "integrity": "sha512-yg2d+Em4KizZC5niWhQaIomgf5WlL4vOOjZ5xGCmF8SnPE/mDWWXgvRExdcpCgh9lLRRa1/fSYp2ymmbJ1pI+A==", + "dev": true, + "license": "BSD-3-Clause", + "dependencies": { + "@jridgewell/trace-mapping": "^0.3.23", + "debug": "^4.1.1", + "istanbul-lib-coverage": "^3.0.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/istanbul-reports": { + "version": "3.1.7", + "resolved": "https://registry.npmjs.org/istanbul-reports/-/istanbul-reports-3.1.7.tgz", + "integrity": "sha512-BewmUXImeuRk2YY0PVbxgKAysvhRPUQE0h5QRM++nVWyubKGV0l8qQ5op8+B2DOmwSe63Jivj0BjkPQVf8fP5g==", + "dev": true, + "license": "BSD-3-Clause", + "dependencies": { + "html-escaper": "^2.0.0", + "istanbul-lib-report": "^3.0.0" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/iterator.prototype": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/iterator.prototype/-/iterator.prototype-1.1.3.tgz", @@ -5168,6 +5280,47 @@ "@jridgewell/sourcemap-codec": "^1.5.0" } }, + "node_modules/magicast": { + "version": "0.3.5", + "resolved": "https://registry.npmjs.org/magicast/-/magicast-0.3.5.tgz", + "integrity": "sha512-L0WhttDl+2BOsybvEOLK7fW3UA0OQ0IQ2d6Zl2x/a6vVRs3bAY0ECOSHHeL5jD+SbOpOCUEi0y1DgHEn9Qn1AQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/parser": "^7.25.4", + "@babel/types": "^7.25.4", + "source-map-js": "^1.2.0" + } + }, + "node_modules/make-dir": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-4.0.0.tgz", + "integrity": "sha512-hXdUTZYIVOt1Ex//jAQi+wTZZpUpwBj/0QsOzqegb3rGMMeJiSEu5xLHnYfBrRV4RH2+OCSOO95Is/7x1WJ4bw==", + "dev": true, + "license": "MIT", + "dependencies": { + "semver": "^7.5.3" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/make-dir/node_modules/semver": { + "version": "7.6.3", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.3.tgz", + "integrity": "sha512-oVekP1cKtI+CTDvHWYFUcMtsK/00wmAEfyqKfNdARm8u1wNVhSgaX7A8d4UuIlUI5e84iEwOhs7ZPYRmzU9U6A==", + "dev": true, + "license": "ISC", + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/merge2": { "version": "1.4.1", "resolved": "https://registry.npmjs.org/merge2/-/merge2-1.4.1.tgz", @@ -6830,6 +6983,47 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/test-exclude": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/test-exclude/-/test-exclude-7.0.1.tgz", + "integrity": "sha512-pFYqmTw68LXVjeWJMST4+borgQP2AyMNbg1BpZh9LbyhUeNkeaPF9gzfPGUAnSMV3qPYdWUwDIjjCLiSDOl7vg==", + "dev": true, + "license": "ISC", + "dependencies": { + "@istanbuljs/schema": "^0.1.2", + "glob": "^10.4.1", + "minimatch": "^9.0.4" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/test-exclude/node_modules/brace-expansion": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", + "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", + "dev": true, + "license": "MIT", + "dependencies": { + "balanced-match": "^1.0.0" + } + }, + "node_modules/test-exclude/node_modules/minimatch": { + "version": "9.0.5", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.5.tgz", + "integrity": "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow==", + "dev": true, + "license": "ISC", + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=16 || 14 >=14.17" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, "node_modules/text-table": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz", diff --git a/frontend/package.json b/frontend/package.json index 35a086d..f7fe9ed 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -26,6 +26,7 @@ "@types/react-dom": "^18.3.0", "@vitejs/plugin-react": "^4.3.2", "@vitejs/plugin-react-swc": "^3.3.2", + "@vitest/coverage-v8": "^2.1.3", "@vitest/ui": "^2.1.3", "autoprefixer": "^10.4.20", "eslint": "^9.11.1", diff --git a/frontend/src/components/AvatarSelector.jsx b/frontend/src/components/AvatarDropdown.jsx similarity index 96% rename from frontend/src/components/AvatarSelector.jsx rename to frontend/src/components/AvatarDropdown.jsx index c30eaeb..93ce869 100644 --- a/frontend/src/components/AvatarSelector.jsx +++ b/frontend/src/components/AvatarDropdown.jsx @@ -4,6 +4,7 @@ import { socket } from "../socket"; const avatars = import.meta.glob("/src/assets/*.png", { eager: true }); export function AvatarDropdown({ setAvatar, isOpen, setAvatarOpen}) { + //console.log("Avatar dropdown - avatars", avatars) const [avatarOptions, setAvatarOptions] = useState([]); useEffect(() => { @@ -21,6 +22,7 @@ export function AvatarDropdown({ setAvatar, isOpen, setAvatarOpen}) { <> {isOpen && (
- Pos. - | + {showMedals && ( ++ Pos. + | + )}Name | - {sortBy === "totalScore" ? "Score" : "Guess"} + {sortBy === "totalScore" ? "Score" : "Guess"} | {position(index)} | + {showMedals &&{position(index)} | }
{" "}
@@ -49,8 +50,12 @@ export function Table({ players, sortBy }) {
{player.name}
|
-
- {sortBy === "totalScore" ? player.totalScore : player.currentGuess} | + ++ {sortBy === "totalScore" + ? player.totalScore + : player.currentGuess} + | ))} diff --git a/frontend/src/components/TableCarousel.jsx b/frontend/src/components/TableCarousel.jsx index 0c1ce81..3b1f2fd 100644 --- a/frontend/src/components/TableCarousel.jsx +++ b/frontend/src/components/TableCarousel.jsx @@ -28,7 +28,7 @@ const carouselTheme = { icon: "h-5 w-5 text-gray-600 sm:h-3 sm:w-3", }, scrollContainer: { - base: "flex snap-mandatory overflow-y-hidden overflow-x-scroll scroll-smooth rounded-lg", + base: "flex snap-mandatory overflow-y-hidden overflow-x-hidden scroll-smooth rounded-lg", snap: "snap-x", }, }; @@ -41,14 +41,14 @@ export function TableCarousel({ players, weight }) { const playersByGuess = players && [...players].sort((a, b) => Math.abs(weight - a.currentGuess) - Math.abs(weight - b.currentGuess)) return (
---|