issue-2-scriptAccounts #4

Merged
sebastian merged 15 commits from issue-2-scriptAccounts into main 2024-02-05 18:16:10 +01:00
5 changed files with 35 additions and 28 deletions
Showing only changes of commit 288b6ed220 - Show all commits

View File

@ -21,38 +21,36 @@ test.describe('Test ScriptAccounts', () => {
test("Test Adding ScriptAccounts", async () => { test("Test Adding ScriptAccounts", async () => {
const gameModel: GameModel = new GameModel("GameModel"); const gameModel: GameModel = new GameModel("GameModel");
const scriptAccount = new ScriptAccount("ScriptAccount", "Description"); let scriptAccount =gameModel.addScriptAccount("ScriptAccount");
gameModel.addScriptAccount(scriptAccount); expect(scriptAccount).toBeDefined();
expect(gameModel.scriptAccounts.length).toEqual(1); expect(gameModel.scriptAccounts.length).toEqual(1);
expect(gameModel.scriptAccounts.includes(scriptAccount)).toBeTruthy(); 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 //Test adding scriptAccount with already existing name
const scriptAccount2 = new ScriptAccount("ScriptAccount", ""); const scriptAccount2 = gameModel.addScriptAccount("ScriptAccount")
gameModel.addScriptAccount(scriptAccount2); expect(scriptAccount2).toBeUndefined();
expect(gameModel.scriptAccounts.length).toEqual(1);
//Test for adding invalid names as scriptaccount names (null/undefined/empty)
let result = gameModel.addScriptAccount(null);
expect(result).toBeUndefined();
expect(gameModel.scriptAccounts.length).toEqual(1);
result = gameModel.addScriptAccount(undefined);
expect(result).toBeUndefined();
expect(gameModel.scriptAccounts.length).toEqual(1);
result = gameModel.addScriptAccount("");
expect(result).toBeUndefined();
expect(gameModel.scriptAccounts.length).toEqual(1); expect(gameModel.scriptAccounts.length).toEqual(1);
expect(gameModel.scriptAccounts.includes(scriptAccount2)).toBeFalsy();
}) })
test("test Removing ScriptAccounts", async () => { test("test Removing ScriptAccounts", async () => {
const gameModel: GameModel = new GameModel("GameModel"); const gameModel: GameModel = new GameModel("GameModel");
const scriptAccount = new ScriptAccount("ScriptAccount", "Description"); let scriptAccount = new ScriptAccount("test", "")
const scriptAccount2 = new ScriptAccount("ScriptAccount 2", "Description");
gameModel.removeScriptAccount(scriptAccount); gameModel.removeScriptAccount(scriptAccount);
expect(gameModel.scriptAccounts.length).toEqual(0); expect(gameModel.scriptAccounts.length).toEqual(0);
gameModel.addScriptAccount(scriptAccount); scriptAccount = gameModel.addScriptAccount("ScriptAccount");
gameModel.removeScriptAccount(scriptAccount); gameModel.removeScriptAccount(scriptAccount);
expect(gameModel.scriptAccounts.length).toEqual(0); expect(gameModel.scriptAccounts.length).toEqual(0);
@ -62,8 +60,8 @@ test.describe('Test ScriptAccounts', () => {
gameModel.removeScriptAccount(null); gameModel.removeScriptAccount(null);
expect(gameModel.scriptAccounts.length).toEqual(0); expect(gameModel.scriptAccounts.length).toEqual(0);
gameModel.addScriptAccount(scriptAccount); scriptAccount = gameModel.addScriptAccount(scriptAccount);
gameModel.addScriptAccount(scriptAccount2); let scriptAccount2 = gameModel.addScriptAccount("ScriptAccount 2");
gameModel.removeScriptAccount(scriptAccount); gameModel.removeScriptAccount(scriptAccount);
expect(gameModel.scriptAccounts.length).toEqual(1); expect(gameModel.scriptAccounts.length).toEqual(1);

View File

@ -39,8 +39,8 @@ export class AppComponent implements OnInit{
ngOnInit() { ngOnInit() {
this.gameModel = new GameModel("No More"); this.gameModel = new GameModel("No More");
this.gameModel.addScriptAccount(new ScriptAccount("Temperature", "")); this.gameModel.addScriptAccount("Temperature");
this.gameModel.addScriptAccount(new ScriptAccount("Luftfeuchtigkeit", "")); this.gameModel.addScriptAccount("Luftfeuchtigkeit");
} }
openScriptAccountsOverview() { openScriptAccountsOverview() {

View File

@ -32,13 +32,16 @@ export class GameModel {
this._gamesystems = this._gamesystems.filter(g => g !== gamesystem); this._gamesystems = this._gamesystems.filter(g => g !== gamesystem);
} }
addScriptAccount(scriptAccount: ScriptAccount) { addScriptAccount(scriptAccountName: string) {
if(scriptAccount != undefined && !this.scriptAccounts.includes(scriptAccount)) { if(scriptAccountName != undefined && scriptAccountName.length > 0) {
const scriptAccount = new ScriptAccount(scriptAccountName, "");
const searchedScriptAccount = this.scriptAccounts.find(s => s.componentName === scriptAccount.componentName); const searchedScriptAccount = this.scriptAccounts.find(s => s.componentName === scriptAccount.componentName);
if(searchedScriptAccount == undefined) { if(searchedScriptAccount == undefined) {
this.scriptAccounts.push(scriptAccount); this.scriptAccounts.push(scriptAccount);
return scriptAccount;
} }
} }
return undefined;
} }
removeScriptAccount(scriptAccount: ScriptAccount) { removeScriptAccount(scriptAccount: ScriptAccount) {

View File

@ -37,6 +37,11 @@ describe('ScriptAccountOverview', () => {
expect(component.openScriptAccountEmitter.emit).toHaveBeenCalledWith(component.gameModel!.scriptAccounts[0]); expect(component.openScriptAccountEmitter.emit).toHaveBeenCalledWith(component.gameModel!.scriptAccounts[0]);
component.onCreateNewScriptAccount();
fixture.detectChanges()
expect(component.openScriptAccountEmitter.emit).toBeCalledTimes(1);
})) }))

View File

@ -31,8 +31,9 @@ export class ScriptAccountOverviewComponent {
} }
onCreateNewScriptAccount() { onCreateNewScriptAccount() {
const scriptAccount = new ScriptAccount("New ScriptAccount", ""); const scriptAccount = this.gameModel!.addScriptAccount("New ScriptAccount");
this.gameModel!.addScriptAccount(scriptAccount); if(scriptAccount != undefined) {
this.openScriptAccountEmitter.emit(scriptAccount); this.openScriptAccountEmitter.emit(scriptAccount);
}
} }
} }