issue-2-scriptAccounts #4
@ -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);
 | 
			
		||||
 | 
			
		||||
@ -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() {
 | 
			
		||||
 | 
			
		||||
@ -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) {
 | 
			
		||||
 | 
			
		||||
@ -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);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
  }))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -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);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user