diff --git a/e2e/game-model/scriptAccounts/ScriptAccountTest.spec.ts b/e2e/game-model/scriptAccounts/ScriptAccountTest.spec.ts new file mode 100644 index 0000000..a9048e3 --- /dev/null +++ b/e2e/game-model/scriptAccounts/ScriptAccountTest.spec.ts @@ -0,0 +1,73 @@ +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"; +import {ScriptAccount} from "../../../src/app/game-model/scriptAccounts/ScriptAccount"; +import {ModelComponentType} from "../../../src/app/game-model/ModelComponentType"; + +test.describe('Test ScriptAccounts', () => { + + test("Test ScriptAccount Creation", async () => { + const scriptAccunt = new ScriptAccount("ScriptAccount", "Description"); + + expect(scriptAccunt.componentName).toEqual("ScriptAccount"); + expect(scriptAccunt.componentDescription).toEqual("Description"); + expect(scriptAccunt.type).toEqual(ModelComponentType.SCRIPTACCOUNT); + expect(scriptAccunt.minValue).toEqual(0); + expect(scriptAccunt.maxValue).toEqual(100); + }) + + test("Test Adding ScriptAccounts", async () => { + const gameModel: GameModel = new GameModel("GameModel"); + + const scriptAccount = new ScriptAccount("ScriptAccount", "Description"); + gameModel.addScriptAccount(scriptAccount); + + expect(gameModel.scriptAccounts.length).toEqual(1); + expect(gameModel.scriptAccounts.includes(scriptAccount)).toBeTruthy(); + + //Test for duplicates + gameModel.addScriptAccount(scriptAccount); + expect(gameModel.scriptAccounts.length).toEqual(1); + + //Test for adding null value + gameModel.addScriptAccount(null); + expect(gameModel.scriptAccounts.length).toEqual(1); + gameModel.addScriptAccount(undefined); + expect(gameModel.scriptAccounts.length).toEqual(1); + + //Test adding scriptAccount with already existing name + const scriptAccount2 = new ScriptAccount("ScriptAccount", ""); + gameModel.addScriptAccount(scriptAccount2); + expect(gameModel.scriptAccounts.length).toEqual(1); + expect(gameModel.scriptAccounts.includes(scriptAccount2)).toBeFalsy(); + }) + + test("test Removing ScriptAccounts", async () => { + const gameModel: GameModel = new GameModel("GameModel"); + const scriptAccount = new ScriptAccount("ScriptAccount", "Description"); + const scriptAccount2 = new ScriptAccount("ScriptAccount 2", "Description"); + + gameModel.removeScriptAccount(scriptAccount); + expect(gameModel.scriptAccounts.length).toEqual(0); + + gameModel.addScriptAccount(scriptAccount); + gameModel.removeScriptAccount(scriptAccount); + expect(gameModel.scriptAccounts.length).toEqual(0); + + gameModel.removeScriptAccount(undefined); + expect(gameModel.scriptAccounts.length).toEqual(0); + + gameModel.removeScriptAccount(null); + expect(gameModel.scriptAccounts.length).toEqual(0); + + gameModel.addScriptAccount(scriptAccount); + gameModel.addScriptAccount(scriptAccount2); + + gameModel.removeScriptAccount(scriptAccount); + expect(gameModel.scriptAccounts.length).toEqual(1); + expect(gameModel.scriptAccounts.includes(scriptAccount2)).toBeTruthy(); + }) + +}); diff --git a/src/app/game-model/GameModel.ts b/src/app/game-model/GameModel.ts index 8bc7dbf..b27a223 100644 --- a/src/app/game-model/GameModel.ts +++ b/src/app/game-model/GameModel.ts @@ -1,9 +1,11 @@ import {Gamesystem} from "./gamesystems/Gamesystem"; +import {ScriptAccount} from "./scriptAccounts/ScriptAccount"; export class GameModel { private readonly _gameModelName: string private _gamesystems: Gamesystem[] = []; + private _scriptAccounts: ScriptAccount[] = []; constructor(gameModelName: string) { this._gameModelName = gameModelName; @@ -16,6 +18,9 @@ export class GameModel { get gamesystems(): Gamesystem[] { return this._gamesystems; } + get scriptAccounts(): ScriptAccount[] { + return this._scriptAccounts; + } addGamesystem(gamesystem: Gamesystem) { if(!this.gamesystems.includes(gamesystem)) { @@ -26,4 +31,20 @@ export class GameModel { removeGamesystem(gamesystem : Gamesystem) { this._gamesystems = this._gamesystems.filter(g => g !== gamesystem); } + + addScriptAccount(scriptAccount: ScriptAccount) { + if(scriptAccount != undefined && !this.scriptAccounts.includes(scriptAccount)) { + const searchedScriptAccount = this.scriptAccounts.find(s => s.componentName === scriptAccount.componentName); + if(searchedScriptAccount == undefined) { + this.scriptAccounts.push(scriptAccount); + } + } + } + + removeScriptAccount(scriptAccount: ScriptAccount) { + if(scriptAccount != undefined) { + this._scriptAccounts = this.scriptAccounts.filter(s => s != scriptAccount); + } + } + } diff --git a/src/app/game-model/ModelComponent.ts b/src/app/game-model/ModelComponent.ts new file mode 100644 index 0000000..5052ad3 --- /dev/null +++ b/src/app/game-model/ModelComponent.ts @@ -0,0 +1,14 @@ +import {ModelComponentType} from "./ModelComponentType"; + +export abstract class ModelComponent { + componentName: string + componentDescription: string + type: ModelComponentType + constructor(componentName: string, componentDescription: string, type: ModelComponentType) { + this.componentName = componentName; + this.componentDescription = componentDescription; + this.type = type; + } + + +} diff --git a/src/app/game-model/ModelComponentType.ts b/src/app/game-model/ModelComponentType.ts new file mode 100644 index 0000000..a3ceab2 --- /dev/null +++ b/src/app/game-model/ModelComponentType.ts @@ -0,0 +1,3 @@ +export enum ModelComponentType { + SCRIPTACCOUNT +} diff --git a/src/app/game-model/scriptAccounts/ScriptAccount.ts b/src/app/game-model/scriptAccounts/ScriptAccount.ts new file mode 100644 index 0000000..6de4790 --- /dev/null +++ b/src/app/game-model/scriptAccounts/ScriptAccount.ts @@ -0,0 +1,10 @@ +import {ModelComponent} from "../ModelComponent"; +import {ModelComponentType} from "../ModelComponentType"; + +export class ScriptAccount extends ModelComponent{ + minValue: number = 0; + maxValue: number = 100; + constructor(componentName: string, componentDescription: string) { + super(componentName, componentDescription, ModelComponentType.SCRIPTACCOUNT); + } +}