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 () => {
const gameModel: GameModel = new GameModel("GameModel");
const scriptAccount = new ScriptAccount("ScriptAccount", "Description");
gameModel.addScriptAccount(scriptAccount);
let scriptAccount =gameModel.addScriptAccount("ScriptAccount");
expect(scriptAccount).toBeDefined();
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);
const scriptAccount2 = gameModel.addScriptAccount("ScriptAccount")
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.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");
let scriptAccount = new ScriptAccount("test", "")
gameModel.removeScriptAccount(scriptAccount);
expect(gameModel.scriptAccounts.length).toEqual(0);
gameModel.addScriptAccount(scriptAccount);
scriptAccount = gameModel.addScriptAccount("ScriptAccount");
gameModel.removeScriptAccount(scriptAccount);
expect(gameModel.scriptAccounts.length).toEqual(0);
@ -62,8 +60,8 @@ test.describe('Test ScriptAccounts', () => {
gameModel.removeScriptAccount(null);
expect(gameModel.scriptAccounts.length).toEqual(0);
gameModel.addScriptAccount(scriptAccount);
gameModel.addScriptAccount(scriptAccount2);
scriptAccount = gameModel.addScriptAccount(scriptAccount);
let scriptAccount2 = gameModel.addScriptAccount("ScriptAccount 2");
gameModel.removeScriptAccount(scriptAccount);
expect(gameModel.scriptAccounts.length).toEqual(1);

View File

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

View File

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

View File

@ -37,6 +37,11 @@ describe('ScriptAccountOverview', () => {
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() {
const scriptAccount = new ScriptAccount("New ScriptAccount", "");
this.gameModel!.addScriptAccount(scriptAccount);
this.openScriptAccountEmitter.emit(scriptAccount);
const scriptAccount = this.gameModel!.addScriptAccount("New ScriptAccount");
if(scriptAccount != undefined) {
this.openScriptAccountEmitter.emit(scriptAccount);
}
}
}