1a2b.spec.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Minimal unit test for 1a2b mini-game scoring flow (first-guess immediate win)
  2. // This is a skeleton to illustrate how to validate the first-guess high score path.
  3. // The actual test-runner and Vue test-utils setup may vary in your repo.
  4. import Vue from 'vue'
  5. import { mount, createLocalVue } from '@vue/test-utils'
  6. import Game1a2b from '../../../cfc-frontend/pages/games/1a2b.vue'
  7. // Mock API module
  8. jest.mock('../../../cfc-frontend/utils/api.js', () => ({
  9. completeMiniGame: jest.fn(() => Promise.resolve({ code: 200, data: { pointsEarned: 10, newBalance: 110 } })),
  10. getChildren: jest.fn(() => Promise.resolve({ data: [{ id: 'child1' }] }))
  11. }))
  12. describe('1a2b.vue - first-guess immediate win', () => {
  13. const localVue = createLocalVue()
  14. it('awards 100 points on immediate win and submits score', async () => {
  15. const wrapper = mount(Game1a2b, {
  16. localVue,
  17. mocks: {
  18. $t: () => {} // if i18n is used
  19. }
  20. })
  21. // Force deterministic answer by overriding generateAnswer
  22. wrapper.vm.generateAnswer = () => '1234'
  23. // Prepare child id
  24. await wrapper.vm.loadChildId()
  25. // Set user guess equal to answer to trigger immediate win on start
  26. wrapper.setData({ userGuess: '1234' })
  27. // Start the game
  28. await wrapper.vm.startGame()
  29. // Assertions for first-guess instant win
  30. expect(wrapper.vm.gameOver).toBe(true)
  31. expect(wrapper.vm.isWin).toBe(true)
  32. expect(wrapper.vm.score).toBe(100)
  33. // Ensure submitScore was invoked (mocked API should be called)
  34. const api = require('../../../cfc-frontend/utils/api.js')
  35. expect(api.completeMiniGame).toHaveBeenCalled()
  36. })
  37. })