Skip to content

Commit

Permalink
1) Added new Scoreboard component for tallying scores of a different
Browse files Browse the repository at this point in the history
   game.
2) Added assets for same.
3) Added test coverage for same.
  • Loading branch information
RobSpectre committed Feb 2, 2023
1 parent 5bbad4f commit a0435c4
Show file tree
Hide file tree
Showing 3 changed files with 169 additions and 0 deletions.
Binary file added public/images/scoreboard.avif
Binary file not shown.
82 changes: 82 additions & 0 deletions src/components/Scoreboard/Scoreboard.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<template lang="pug">
GameContentWithSidebar(:players='players')
template(v-slot:content)
ChooseItemModal(
:items='playerItems'
:fragmentItemReveal='fragmentItemReveal'
:question='question'
:headerImage='headerImage'
@guess='pickWinner'
:selectedPlayer='null'
)
</template>

<script>
import { mapActions, mapGetters, mapState } from 'pinia'
import { useGameStore } from '@/store'
import GameContentWithSidebar from '@/components/base/GameContentWithSidebar.vue'
import ChooseItemModal from '@/components/base/ChooseItemModal.vue'
export default {
name: 'Scoreboard',
components: {
GameContentWithSidebar,
ChooseItemModal
},
props: {
question: String,
prize: {
default: 1,
type: Number
},
headerImage: {
default: '/images/scoreboard.avif',
type: String
},
fragmentItemReveal: {
default: false,
type: Boolean
}
},
computed: {
players () {
const players = []
this.getPlayersByScore.forEach((player) => {
players.push({
name: player.name,
value: player.score
})
})
return players
},
playerItems () {
const players = []
this.game.players.forEach((player) => {
players.push({
name: player.name,
value: player.name,
emoji: ''
})
})
return players
},
...mapState(useGameStore, ['game']),
...mapGetters(useGameStore, ['getPlayersByScore'])
},
methods: {
pickWinner (guess) {
this.increasePlayerScore(this.playerItems[guess.value].name, this.prize)
const audio = new Audio('/sounds/sonic_ring.mp3')
audio.volume = 0.2
audio.play()
},
...mapActions(useGameStore, ['increasePlayerScore'])
}
}
</script>
87 changes: 87 additions & 0 deletions tests/unit/Scoreboard/Scoreboard.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import { mount } from '@vue/test-utils'

import { createTestingPinia } from '@pinia/testing'

import Scoreboard from '@/components/Scoreboard/Scoreboard.vue'

describe('Scoreboard Empty', () => {
let wrapper

beforeEach(() => {
wrapper = mount(Scoreboard, {
props: {
question: 'Which player answered correctly?'
},
global: {
plugins: [createTestingPinia()]
}
})
})

it('renders with no players', async () => {
expect(wrapper.vm.game.players.length).toBe(0)
})
})

describe('Scoreboard', () => {
let wrapper

beforeEach(() => {
wrapper = mount(Scoreboard, {
props: {
question: 'Which player answered correctly?'
},
global: {
plugins: [createTestingPinia({
stubActions: false,
initialState: {
'hack.party game board': {
game: {
players: [
{
index: 0,
name: 'Morty',
score: 0,
team: undefined
},
{
index: 1,
name: 'noob noob',
score: 0,
team: undefined
},
{
index: 2,
name: 'Rick',
score: 0,
team: undefined
}
]
}
}
}
})]
}
})
})

it('renders with players', async () => {
expect(wrapper.vm.game.players.length).toBe(3)
})

it('awards a point to the first player', async () => {
const button = await wrapper.find('button')
await button.trigger('click')

debugger

expect(wrapper.vm.game.players[0].score).toBe(1)
})

it('awards a point to the third player', async () => {
const buttons = await wrapper.findAll('button')
await buttons[2].trigger('click')

expect(wrapper.vm.game.players[2].score).toBe(1)
})
})

0 comments on commit a0435c4

Please sign in to comment.