Create New ScriptAccount
All checks were successful
E2E Testing / test (push) Successful in 1m21s

This commit is contained in:
Sebastian Böckelmann 2024-01-27 13:00:32 +01:00
parent 35a323e97a
commit a6711cc2ba
3 changed files with 45 additions and 24 deletions

View File

@ -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>

View File

@ -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]);
}))
}); });

View File

@ -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")
}
} }
} }