From 5f256e1983fdd4c668c0959a2a1de34bc874c94f Mon Sep 17 00:00:00 2001 From: Patrick Mueller Date: Fri, 16 Sep 2022 16:43:37 +0200 Subject: [PATCH] Adding first unit test for score calculation --- .../add-game/add-game.component.spec.ts | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/app/components/add-game/add-game.component.spec.ts b/src/app/components/add-game/add-game.component.spec.ts index 4362d2b..f889c49 100644 --- a/src/app/components/add-game/add-game.component.spec.ts +++ b/src/app/components/add-game/add-game.component.spec.ts @@ -1,6 +1,7 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import { AddGameComponent } from './add-game.component'; +import {Team} from '../../models/doppelkopf/enums/team'; describe('AddGameComponent', () => { let component: AddGameComponent; @@ -20,4 +21,49 @@ describe('AddGameComponent', () => { it('should create', () => { expect(component).toBeTruthy(); }); + + it('should have the correct score for a normal game', () => { + // Set up testing data + component.actualPlayers = [ + { + firebonkId: 1, + uuid: 'abc-def-ghi-j', + firstName: 'Patrick', + team: Team.RE, + gamePoints: 0, + finalCardScore: 123, + }, + { + firebonkId: 1, + uuid: 'abc-def-ghi-k', + firstName: 'Julian', + team: Team.RE, + gamePoints: 17, + finalCardScore: 0, + }, + { + firebonkId: 1, + uuid: 'abc-def-ghi-l', + firstName: 'Yanick', + team: Team.CONTRA, + gamePoints: 50, + finalCardScore: 0, + }, + { + firebonkId: 1, + uuid: 'abc-def-ghi-m', + firstName: 'Janina', + team: Team.CONTRA, + gamePoints: 50, + finalCardScore: 0, + }, + ] + + component.calculateCurrentScores(); + + expect(component.actualPlayers[0].gamePoints).toEqual(1); + expect(component.actualPlayers[1].gamePoints).toEqual(1); + expect(component.actualPlayers[2].gamePoints).toEqual(-1); + expect(component.actualPlayers[3].gamePoints).toEqual(-1); + }) });