Simple Tests for Gamesystem Adding and Removing

This commit is contained in:
Sebastian Böckelmann 2024-01-26 23:42:34 +01:00
parent e43567f2ca
commit 796f1e3a05
5 changed files with 97 additions and 0 deletions

View File

@ -0,0 +1,23 @@
import { BrowserContext, ElectronApplication, Page, _electron as electron } from 'playwright';
import { test, expect } from '@playwright/test';
import * as PATH from 'path';
import {GameModel} from "../../src/app/game-model/GameModel";
import {Gamesystem} from "../../src/app/game-model/gamesystems/Gamesystem";
test.describe('Adding Gamesystems', () => {
test("Test simple adding of Gamesystems", async () => {
const gameModel = new GameModel("GameModel");
const gamesystem = new Gamesystem("Gamesystem");
gameModel.addGamesystem(gamesystem);
expect(gameModel.gamesystems.includes(gamesystem)).toBeTruthy();
})
test("Test duplicates when adding Gamesystems", async () => {
const gameModel = new GameModel("GameModel");
const gamesystem = new Gamesystem("Gamesystem");
gameModel.addGamesystem(gamesystem);
gameModel.addGamesystem(gamesystem)
expect(gameModel.gamesystems.length).toEqual(1);
})
});

View File

@ -0,0 +1,25 @@
import { BrowserContext, ElectronApplication, Page, _electron as electron } from 'playwright';
import { test, expect } from '@playwright/test';
import * as PATH from 'path';
import {GameModel} from "../../src/app/game-model/GameModel";
import {Gamesystem} from "../../src/app/game-model/gamesystems/Gamesystem";
test.describe('Removing Gamesystems', () => {
test("Test simple removing of Gamesystems", async () => {
const gameModel = new GameModel("GameModel");
const gamesystem = new Gamesystem("Gamesystem");
gameModel.addGamesystem(gamesystem);
gameModel.removeGamesystem(gamesystem);
expect(gameModel.gamesystems.length).toEqual(0);
})
test("Test removing of empty gamesystems", async () => {
const gameModel = new GameModel("GameModel");
const gamesystem = new Gamesystem("Gamesystem");
gameModel.removeGamesystem(gamesystem);
expect(gameModel.gamesystems.length).toEqual(0);
})
});

View File

@ -0,0 +1,29 @@
import {Gamesystem} from "./gamesystems/Gamesystem";
export class GameModel {
private readonly _gameModelName: string
private _gamesystems: Gamesystem[] = [];
constructor(gameModelName: string) {
this._gameModelName = gameModelName;
}
get gameModelName(): string {
return this._gameModelName;
}
get gamesystems(): Gamesystem[] {
return this._gamesystems;
}
addGamesystem(gamesystem: Gamesystem) {
if(!this.gamesystems.includes(gamesystem)) {
this._gamesystems.push(gamesystem);
}
}
removeGamesystem(gamesystem : Gamesystem) {
this._gamesystems = this._gamesystems.filter(g => g !== gamesystem);
}
}

View File

@ -0,0 +1,12 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
@NgModule({
declarations: [],
imports: [
CommonModule
]
})
export class GameModelModule { }

View File

@ -0,0 +1,8 @@
export class Gamesystem {
gamesystemName: string
constructor(gamesystemName: string) {
this.gamesystemName = gamesystemName;
}
}