issue-2-scriptAccounts #4
@ -1,6 +1,6 @@
 | 
			
		||||
<mat-action-list>
 | 
			
		||||
  <mat-list-item class="scriptAccount-item" *ngFor="let scriptAccount of gameModel!.scriptAccounts"
 | 
			
		||||
                 (dblclick)="onOpenScriptAccount(scriptAccount)" (contextmenu)="onContextMenu($event)">
 | 
			
		||||
                 (dblclick)="onOpenScriptAccount(scriptAccount)">
 | 
			
		||||
    <mat-icon class="scriptAccount-icon">inventory_2</mat-icon>{{scriptAccount.componentName}}
 | 
			
		||||
  </mat-list-item>
 | 
			
		||||
</mat-action-list>
 | 
			
		||||
 | 
			
		||||
@ -1,23 +1,43 @@
 | 
			
		||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
 | 
			
		||||
import {ComponentFixture, TestBed, waitForAsync} from '@angular/core/testing';
 | 
			
		||||
 | 
			
		||||
import { ScriptAccountOverviewComponent } from './script-account-overview.component';
 | 
			
		||||
import {TranslateModule} from "@ngx-translate/core";
 | 
			
		||||
import {RouterTestingModule} from "@angular/router/testing";
 | 
			
		||||
import {ScriptAccountOverviewComponent} from "./script-account-overview.component";
 | 
			
		||||
import exp from "node:constants";
 | 
			
		||||
import {GameModel} from "../../game-model/GameModel";
 | 
			
		||||
 | 
			
		||||
describe('ScriptAccountOverviewComponent', () => {
 | 
			
		||||
describe('ScriptAccountOverview', () => {
 | 
			
		||||
  let component: ScriptAccountOverviewComponent;
 | 
			
		||||
  let fixture: ComponentFixture<ScriptAccountOverviewComponent>;
 | 
			
		||||
 | 
			
		||||
  beforeEach(async () => {
 | 
			
		||||
    await TestBed.configureTestingModule({
 | 
			
		||||
      imports: [ScriptAccountOverviewComponent]
 | 
			
		||||
    })
 | 
			
		||||
    .compileComponents();
 | 
			
		||||
    
 | 
			
		||||
  beforeEach(waitForAsync(() => {
 | 
			
		||||
    void TestBed.configureTestingModule({
 | 
			
		||||
      declarations: [ScriptAccountOverviewComponent],
 | 
			
		||||
      imports: [TranslateModule.forRoot(), RouterTestingModule]
 | 
			
		||||
    }).compileComponents();
 | 
			
		||||
 | 
			
		||||
    fixture = TestBed.createComponent(ScriptAccountOverviewComponent);
 | 
			
		||||
    component = fixture.componentInstance;
 | 
			
		||||
    component.gameModel = new GameModel("GameModel")
 | 
			
		||||
    fixture.detectChanges();
 | 
			
		||||
  });
 | 
			
		||||
  }));
 | 
			
		||||
 | 
			
		||||
  it('should create', () => {
 | 
			
		||||
    expect(component).toBeTruthy();
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  it("Test ScriptAccount Creation", waitForAsync(() => {
 | 
			
		||||
    component.onCreateNewScriptAccount();
 | 
			
		||||
    expect(component.gameModel!.scriptAccounts.length).toEqual(1)
 | 
			
		||||
    component.gameModel!.removeScriptAccount(component.gameModel!.scriptAccounts[0]);
 | 
			
		||||
 | 
			
		||||
    jest.spyOn(component.openScriptAccountEmitter, 'emit');
 | 
			
		||||
    component.onCreateNewScriptAccount();
 | 
			
		||||
    fixture.detectChanges();
 | 
			
		||||
 | 
			
		||||
    expect(component.openScriptAccountEmitter.emit).toHaveBeenCalledWith(component.gameModel!.scriptAccounts[0]);
 | 
			
		||||
 | 
			
		||||
  }))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
@ -1,4 +1,4 @@
 | 
			
		||||
import {Component, EventEmitter, Input, Output} from '@angular/core';
 | 
			
		||||
import {Component, EventEmitter, Input, NgZone, Output} from '@angular/core';
 | 
			
		||||
import {GameModel} from "../../game-model/GameModel";
 | 
			
		||||
import {ScriptAccount} from "../../game-model/scriptAccounts/ScriptAccount";
 | 
			
		||||
import {ElectronService} from "../../core/services";
 | 
			
		||||
@ -12,7 +12,17 @@ export class ScriptAccountOverviewComponent {
 | 
			
		||||
  @Input("gameModel") gameModel: GameModel | undefined
 | 
			
		||||
  @Output("onOpenScriptAccount") openScriptAccountEmitter: EventEmitter<ScriptAccount> = new EventEmitter<ScriptAccount>();
 | 
			
		||||
 | 
			
		||||
  constructor(private electronService: ElectronService) {
 | 
			
		||||
  constructor(private electronService: ElectronService,
 | 
			
		||||
              private zone: NgZone) {
 | 
			
		||||
    if(electronService.isElectron) {
 | 
			
		||||
      this.electronService.ipcRenderer.on('context-menu', (event: any, message: string) => {
 | 
			
		||||
        this.zone.run(() => {
 | 
			
		||||
          if(message == "new-scriptaccount") {
 | 
			
		||||
            this.onCreateNewScriptAccount()
 | 
			
		||||
          }
 | 
			
		||||
        })
 | 
			
		||||
      })
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  onOpenScriptAccount(scriptAccount: ScriptAccount) {
 | 
			
		||||
@ -22,16 +32,7 @@ export class ScriptAccountOverviewComponent {
 | 
			
		||||
 | 
			
		||||
  onCreateNewScriptAccount() {
 | 
			
		||||
    const scriptAccount = new ScriptAccount("New ScriptAccount", "");
 | 
			
		||||
    this.gameModel?.addScriptAccount(scriptAccount);
 | 
			
		||||
    return scriptAccount;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  onContextMenu(event: MouseEvent) {
 | 
			
		||||
    if(this.electronService.isElectron) {
 | 
			
		||||
      console.log("[DEBUG] [ScriptAccountOverviewComponent] App is executed in electron")
 | 
			
		||||
 | 
			
		||||
    } else {
 | 
			
		||||
      console.log("[DEBUG] [ScriptAccountOverviewComponent] App is not executed in electron")
 | 
			
		||||
    }
 | 
			
		||||
    this.gameModel!.addScriptAccount(scriptAccount);
 | 
			
		||||
    this.openScriptAccountEmitter.emit(scriptAccount);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user