issue-2-scriptAccounts #4
@ -1,6 +1,6 @@
|
|||||||
<mat-action-list>
|
<mat-action-list>
|
||||||
<mat-list-item class="scriptAccount-item" *ngFor="let scriptAccount of gameModel!.scriptAccounts"
|
<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-icon class="scriptAccount-icon">inventory_2</mat-icon>{{scriptAccount.componentName}}
|
||||||
</mat-list-item>
|
</mat-list-item>
|
||||||
</mat-action-list>
|
</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 component: ScriptAccountOverviewComponent;
|
||||||
let fixture: ComponentFixture<ScriptAccountOverviewComponent>;
|
let fixture: ComponentFixture<ScriptAccountOverviewComponent>;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(waitForAsync(() => {
|
||||||
await TestBed.configureTestingModule({
|
void TestBed.configureTestingModule({
|
||||||
imports: [ScriptAccountOverviewComponent]
|
declarations: [ScriptAccountOverviewComponent],
|
||||||
})
|
imports: [TranslateModule.forRoot(), RouterTestingModule]
|
||||||
.compileComponents();
|
}).compileComponents();
|
||||||
|
|
||||||
fixture = TestBed.createComponent(ScriptAccountOverviewComponent);
|
fixture = TestBed.createComponent(ScriptAccountOverviewComponent);
|
||||||
component = fixture.componentInstance;
|
component = fixture.componentInstance;
|
||||||
|
component.gameModel = new GameModel("GameModel")
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
});
|
}));
|
||||||
|
|
||||||
it('should create', () => {
|
it('should create', () => {
|
||||||
expect(component).toBeTruthy();
|
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 {GameModel} from "../../game-model/GameModel";
|
||||||
import {ScriptAccount} from "../../game-model/scriptAccounts/ScriptAccount";
|
import {ScriptAccount} from "../../game-model/scriptAccounts/ScriptAccount";
|
||||||
import {ElectronService} from "../../core/services";
|
import {ElectronService} from "../../core/services";
|
||||||
@ -12,7 +12,17 @@ export class ScriptAccountOverviewComponent {
|
|||||||
@Input("gameModel") gameModel: GameModel | undefined
|
@Input("gameModel") gameModel: GameModel | undefined
|
||||||
@Output("onOpenScriptAccount") openScriptAccountEmitter: EventEmitter<ScriptAccount> = new EventEmitter<ScriptAccount>();
|
@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) {
|
onOpenScriptAccount(scriptAccount: ScriptAccount) {
|
||||||
@ -22,16 +32,7 @@ export class ScriptAccountOverviewComponent {
|
|||||||
|
|
||||||
onCreateNewScriptAccount() {
|
onCreateNewScriptAccount() {
|
||||||
const scriptAccount = new ScriptAccount("New ScriptAccount", "");
|
const scriptAccount = new ScriptAccount("New ScriptAccount", "");
|
||||||
this.gameModel?.addScriptAccount(scriptAccount);
|
this.gameModel!.addScriptAccount(scriptAccount);
|
||||||
return scriptAccount;
|
this.openScriptAccountEmitter.emit(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")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user