Implement ProductStateCreation
Some checks failed
E2E Testing / test (push) Failing after 1m25s

This commit is contained in:
Sebastian Böckelmann 2024-02-10 17:07:24 +01:00
parent 1cde7f2939
commit aada044e08
19 changed files with 314 additions and 17 deletions

View File

@ -0,0 +1,48 @@
import { BrowserContext, ElectronApplication, Page, _electron as electron } from 'playwright';
import { test, expect } from '@playwright/test';
import * as PATH from 'path';
import {GameModel} from "../../../src/app/game-model/GameModel";
import {Gamesystem} from "../../src/app/game-model/gamesystems/Gamesystem";
import {ScriptAccount} from "../../../src/app/game-model/scriptAccounts/ScriptAccount";
import {ModelComponentType} from "../../../src/app/game-model/ModelComponentType";
import {SimpleGamesystem} from "../../../src/app/game-model/gamesystems/SimpleGamesystem";
import exp = require("node:constants");
import {end} from "electron-debug";
import {GamesystemTrainer} from "./GamesystemTrainer";
import {ProductGamesystem} from "../../../src/app/game-model/gamesystems/ProductGamesystem";
import {ProductStateTrainer} from "./ProductStateTrainer";
import {SimpleState} from "../../../../src/app/game-model/gamesystems/SimpleState";
test.describe('Test Create ProductStates', () => {
test("Adding already existent ProductState", async () => {
const gamesystem = ProductStateTrainer.givenFullProductGamesystemWithTwoStates();
const result = gamesystem.createState(gamesystem.states[0].innerStates);
expect(result).toBeUndefined();
expect(gamesystem.states.length).toEqual(4);
})
test("Test empty inputs for ProductState Creation", async ()=> {
const gamesystem = ProductStateTrainer.givenFullProductGamesystemWithTwoStates();
expect(gamesystem.createState([])).toBeUndefined();
expect(gamesystem.states.length).toEqual(4);
})
test("Test invalid inputs for ProductState Creation", async () => {
const gamesystem = ProductStateTrainer.givenFullProductGamesystemWithTwoStates();
expect(gamesystem.createState([ProductStateTrainer.givenUnusedInnerStates(gamesystem)[0]])).toBeUndefined();
expect(gamesystem.states.length).toEqual(4);
})
test("Test ProductState Creation with foreign State", async () => {
const gamesystem = ProductStateTrainer.givenFullProductGamesystemWithTwoStates();
const simpleState = new SimpleState(ProductStateTrainer.INNERSTATE_LETTER_3);
expect(gamesystem.createState([simpleState])).toBeUndefined();
expect(gamesystem.states.length).toEqual(4);
})
test("Test valid ProductStateCreation", async () => {
const gamesystem = ProductStateTrainer.givenFullProductGamesystemWithTwoStates();
expect(gamesystem.createState(ProductStateTrainer.givenUnusedInnerStates(gamesystem))).toBeDefined();
expect(gamesystem.states.length).toEqual(5);
})
});

View File

@ -0,0 +1,37 @@
import { BrowserContext, ElectronApplication, Page, _electron as electron } from 'playwright';
import { test, expect } from '@playwright/test';
import * as PATH from 'path';
import {GameModel} from "../../../src/app/game-model/GameModel";
import {Gamesystem} from "../../src/app/game-model/gamesystems/Gamesystem";
import {ScriptAccount} from "../../../src/app/game-model/scriptAccounts/ScriptAccount";
import {ModelComponentType} from "../../../src/app/game-model/ModelComponentType";
import {SimpleGamesystem} from "../../../src/app/game-model/gamesystems/SimpleGamesystem";
import exp = require("node:constants");
import {end} from "electron-debug";
import {GamesystemTrainer} from "./GamesystemTrainer";
import {ProductGamesystem} from "../../../src/app/game-model/gamesystems/ProductGamesystem";
import {ProductStateTrainer} from "./ProductStateTrainer";
import {SimpleState} from "../../../../src/app/game-model/gamesystems/SimpleState";
test.describe('Test Check Equal of Innerstates', () => {
test("Test invalid input for equal checking", async()=> {
const gamesystem = ProductStateTrainer.givenFullProductGamesystemWithTwoStates();
expect(gamesystem.states[0].equalInnerStates(null)).toBeFalsy();
expect(gamesystem.states[0].equalInnerStates(undefined)).toBeFalsy();
})
test("Test empty input for equal checking", async ()=> {
const gamesystem = ProductStateTrainer.givenFullProductGamesystemWithTwoStates();
expect(gamesystem.states[0].equalInnerStates([])).toBeFalsy();
})
test("Test identical inner states for equal", async ()=> {
const gamesystem = ProductStateTrainer.givenFullProductGamesystemWithTwoStates();
expect(gamesystem.states[0].equalInnerStates(gamesystem.states[0].innerStates)).toBeTruthy();
})
test("Test slightly derivating inner states for Equal", async ()=> {
const gamesystem = ProductStateTrainer.givenFullProductGamesystemWithTwoStates();
expect(gamesystem.states[0].equalInnerStates(gamesystem.states[1].innerStates)).toBeFalsy();
})
});

View File

@ -0,0 +1,48 @@
import {ProductGamesystem} from "../../../../src/app/game-model/gamesystems/ProductGamesystem";
import {SimpleGamesystem} from "../../../../src/app/game-model/gamesystems/SimpleGamesystem";
import {ProductState} from "../../../../src/app/game-model/gamesystems/ProductState";
export class ProductStateTrainer {
static INNERSTATE_LETTER_1 = "A";
static INNERSTATE_LETTER_2 = "B";
static INNERSTATE_LETTER_3 = "C";
static INNERSTATE_NUMBER_1 = "1";
static INNERSTATE_NUMBER_2 = "2";
static INNERSTATE_NUMBER_3 = "3";
static LETTERS_GAMESYSTEM_NAME = "Letters";
static NUMBERS_GAMESYSTEM_NAME = "Numbers";
static PRODUCT_GAMESYSTEM_NAME = "Product Gamesystem";
static givenFullProductGamesystemWithTwoStates() {
const letter_Gamesystem = new SimpleGamesystem(this.LETTERS_GAMESYSTEM_NAME);
const letter_1 = letter_Gamesystem.createState(this.INNERSTATE_LETTER_1, "")!;
const letter_2 = letter_Gamesystem.createState(this.INNERSTATE_LETTER_2, "")!;
const number_gamesystem = new SimpleGamesystem(this.NUMBERS_GAMESYSTEM_NAME);
const number_1 = number_gamesystem.createState(this.INNERSTATE_NUMBER_1, "")!;
const number_2 = number_gamesystem.createState(this.INNERSTATE_NUMBER_2, "")!;
const productGamesystem = new ProductGamesystem(this.PRODUCT_GAMESYSTEM_NAME);
productGamesystem.states.push(new ProductState( [letter_1, number_1]));
productGamesystem.states.push(new ProductState( [letter_1, number_2]));
productGamesystem.states.push(new ProductState( [letter_2, number_1]));
productGamesystem.states.push(new ProductState( [letter_2, number_2]));
productGamesystem.innerGamesystems.push(letter_Gamesystem);
productGamesystem.innerGamesystems.push(number_gamesystem);
return productGamesystem;
}
static givenUnusedInnerStates(productGamesystem: ProductGamesystem) {
const letterGamesystem = productGamesystem.findChildSystemByName(ProductStateTrainer.LETTERS_GAMESYSTEM_NAME) as SimpleGamesystem;
const numberGamesystem = productGamesystem.findChildSystemByName(ProductStateTrainer.NUMBERS_GAMESYSTEM_NAME) as SimpleGamesystem;
const letterGamesystemState = letterGamesystem.createState(ProductStateTrainer.INNERSTATE_LETTER_3)!;
const numberGamesystemState = numberGamesystem.createState(ProductStateTrainer.INNERSTATE_NUMBER_3)!;
return [letterGamesystemState, numberGamesystemState];
}
}

View File

@ -15,6 +15,8 @@ import {DeleteConfirmationDialogComponent} from "./delete-confirmation-dialog/de
import {ScriptAccount} from "./game-model/scriptAccounts/ScriptAccount"; import {ScriptAccount} from "./game-model/scriptAccounts/ScriptAccount";
import {GamescriptOverviewComponent} from "./side-overviews/gamescript-overview/gamescript-overview.component"; import {GamescriptOverviewComponent} from "./side-overviews/gamescript-overview/gamescript-overview.component";
import {SimpleGamesystem} from "./game-model/gamesystems/SimpleGamesystem"; import {SimpleGamesystem} from "./game-model/gamesystems/SimpleGamesystem";
import {ProductGamesystem} from "./game-model/gamesystems/ProductGamesystem";
import {ProductState} from "./game-model/gamesystems/ProductState";
@Component({ @Component({
selector: 'app-root', selector: 'app-root',
@ -150,10 +152,19 @@ export class AppComponent implements OnInit{
const springState = season.createState("Spring", "Spring, also known as springtime, is one of the four temperate seasons, succeeding winter and preceding summer."); const springState = season.createState("Spring", "Spring, also known as springtime, is one of the four temperate seasons, succeeding winter and preceding summer.");
const summerState = season.createState("Summer", "Summer is the hottest and brightest of the four temperate seasons, occurring after spring and before autumn. "); const summerState = season.createState("Summer", "Summer is the hottest and brightest of the four temperate seasons, occurring after spring and before autumn. ");
season.createTransition(springState!, summerState!); const sunnyState = weather.createState("Sunny", "The sun is shining. No clouds, no rain, no storm.");
const rainingState = weather.createState("Raining", "It rains")
this.gameModel.addGamesystem(weather) season.createTransition(springState!, summerState!);
this.gameModel.addGamesystem(season); weather.createTransition(sunnyState!, rainingState!);
const weather_season = new ProductGamesystem("Weather-Season");
weather_season.addChildGamesystem(weather);
weather_season.addChildGamesystem(season);
weather_season.createState(ProductState.computeProductStateLabel([springState!, sunnyState!]), "", [springState!, sunnyState!]);
this.gameModel.addGamesystem(weather_season);
} }
openScriptAccountsOverview() { openScriptAccountsOverview() {

View File

@ -51,6 +51,9 @@ import {
SimpleTransitionEditorComponent SimpleTransitionEditorComponent
} from "./editor/gamesystem-editor/transition-editor/simple-transition-editor/simple-transition-editor.component"; } from "./editor/gamesystem-editor/transition-editor/simple-transition-editor/simple-transition-editor.component";
import {MatOption, MatSelect} from "@angular/material/select"; import {MatOption, MatSelect} from "@angular/material/select";
import {
ProductGamesystemEditorComponent
} from "./editor/gamesystem-editor/product-gamesystem-editor/product-gamesystem-editor.component";
// AoT requires an exported function for factories // AoT requires an exported function for factories
const httpLoaderFactory = (http: HttpClient): TranslateHttpLoader => new TranslateHttpLoader(http, './assets/i18n/', '.json'); const httpLoaderFactory = (http: HttpClient): TranslateHttpLoader => new TranslateHttpLoader(http, './assets/i18n/', '.json');
@ -121,7 +124,8 @@ const httpLoaderFactory = (http: HttpClient): TranslateHttpLoader => new Transl
MatCheckbox, MatCheckbox,
MatSelect, MatSelect,
MatOption, MatOption,
MatHint MatHint,
ProductGamesystemEditorComponent
], ],
providers: [], providers: [],
bootstrap: [AppComponent] bootstrap: [AppComponent]

View File

@ -1 +1,2 @@
<app-simple-gamesystem-editor *ngIf="isSimpleGamesystem()" [simpleGamesystem]="convertGamesystemToSimpleGamesystem()"></app-simple-gamesystem-editor> <app-simple-gamesystem-editor *ngIf="isSimpleGamesystem()" [simpleGamesystem]="convertGamesystemToSimpleGamesystem()"></app-simple-gamesystem-editor>
<app-product-gamesystem-editor *ngIf="!isSimpleGamesystem()" [gamesystem]="convertGamesystemToProductGamesystem()"></app-product-gamesystem-editor>

View File

@ -0,0 +1 @@
<app-product-state-editor [gamesystem]="gamesystem"></app-product-state-editor>

View File

@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ProductGamesystemEditorComponent } from './product-gamesystem-editor.component';
describe('ProductGamesystemEditorComponent', () => {
let component: ProductGamesystemEditorComponent;
let fixture: ComponentFixture<ProductGamesystemEditorComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [ProductGamesystemEditorComponent]
})
.compileComponents();
fixture = TestBed.createComponent(ProductGamesystemEditorComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -0,0 +1,17 @@
import {Component, Input} from '@angular/core';
import {ProductGamesystem} from "../../../game-model/gamesystems/ProductGamesystem";
import {ProductStateEditorComponent} from "../state-editor/product-state-editor/product-state-editor.component";
@Component({
selector: 'app-product-gamesystem-editor',
standalone: true,
imports: [
ProductStateEditorComponent
],
templateUrl: './product-gamesystem-editor.component.html',
styleUrl: './product-gamesystem-editor.component.scss'
})
export class ProductGamesystemEditorComponent {
@Input() gamesystem: ProductGamesystem | undefined
}

View File

@ -0,0 +1 @@
<p>product-state-editor works!</p>

View File

@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ProductStateEditorComponent } from './product-state-editor.component';
describe('ProductStateEditorComponent', () => {
let component: ProductStateEditorComponent;
let fixture: ComponentFixture<ProductStateEditorComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [ProductStateEditorComponent]
})
.compileComponents();
fixture = TestBed.createComponent(ProductStateEditorComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -0,0 +1,14 @@
import {Component, Input} from '@angular/core';
import {ProductGamesystem} from "../../../../game-model/gamesystems/ProductGamesystem";
@Component({
selector: 'app-product-state-editor',
standalone: true,
imports: [],
templateUrl: './product-state-editor.component.html',
styleUrl: './product-state-editor.component.scss'
})
export class ProductStateEditorComponent {
@Input() gamesystem: ProductGamesystem | undefined
}

View File

@ -11,8 +11,6 @@ export abstract class Gamesystem<S, T> extends ModelComponent{
super(gamesystemName, "", ModelComponentType.GAMESYTEM); super(gamesystemName, "", ModelComponentType.GAMESYTEM);
} }
abstract createState(label: string, description: string): S|undefined;
abstract createTransition(startingState: S, endingState: S): T|undefined; abstract createTransition(startingState: S, endingState: S): T|undefined;
abstract removeState(state: S): boolean; abstract removeState(state: S): boolean;

View File

@ -33,9 +33,15 @@ export class ProductGamesystem extends Gamesystem<ProductState, ProductTransitio
return productGamesystem; return productGamesystem;
} }
createState(label: string, description: string): ProductState | undefined { createState(innerStates: State<any>[]): ProductState | undefined {
if(innerStates.length == this.innerGamesystems.length && this.findProductStateByInnerStates(innerStates)== undefined) {
const productState = new ProductState(innerStates);
this.states.push(productState);
return productState;
} else {
return undefined; return undefined;
} }
}
createTransition(startingState: ProductState, endingState: ProductState): ProductTransition | undefined { createTransition(startingState: ProductState, endingState: ProductState): ProductTransition | undefined {
return undefined; return undefined;
@ -57,4 +63,21 @@ export class ProductGamesystem extends Gamesystem<ProductState, ProductTransitio
private removeChildGamesystem(gamesystem: Gamesystem<State<any>, Transition<any>>) { private removeChildGamesystem(gamesystem: Gamesystem<State<any>, Transition<any>>) {
this.innerGamesystems = this.innerGamesystems.filter(childSystem => childSystem != gamesystem); this.innerGamesystems = this.innerGamesystems.filter(childSystem => childSystem != gamesystem);
} }
findProductStateByInnerStates(innerStates: State<any>[]) {
return this.states.find(productState => productState.equalInnerStates(innerStates));
}
findChildSystemByName(gamesystemName: string) {
const gamesystemQueue: Gamesystem<State<any>, Transition<any>>[] = [];
this.innerGamesystems.forEach(gamesystem => gamesystemQueue.push(gamesystem));
while(gamesystemName.length > 0 ){
const currentGamesystem = gamesystemQueue.shift();
if(currentGamesystem!.componentName === gamesystemName) {
return currentGamesystem;
}
}
return undefined;
}
} }

View File

@ -1,7 +1,42 @@
import {ProductTransition} from "./ProductTransition"; import {ProductTransition} from "./ProductTransition";
import {State} from "./State"; import {State} from "./State";
import {SimpleState} from "./SimpleState"; import {SimpleState} from "./SimpleState";
import {Transition} from "./Transition";
export class ProductState extends State<ProductTransition> { export class ProductState extends State<ProductTransition> {
innerStates: SimpleState[] = []; innerStates: State<any>[] = [];
constructor(innerStates: State<any>[]) {
super();
this.innerStates = innerStates;
}
equalInnerStates(innerStates: State<any>[]) {
if(innerStates == undefined || this.innerStates.length != innerStates.length) {
return false;
}
for(let i=0; i<innerStates.length; i++) {
if(!this.innerStates[i].equals(innerStates[i])) {
return false;
}
}
return true;
}
equals(state: State<Transition<any>>): boolean {
if(state instanceof SimpleState || this.innerStates.length != (state as ProductState).innerStates.length) {
return false;
}
for(let i=0; i<this.innerStates.length; i++) {
if(!this.innerStates[i].equals((state as ProductState).innerStates[i])) {
return false;
}
}
return true;
}
} }

View File

@ -1,6 +1,24 @@
import {State} from "./State"; import {State} from "./State";
import {SimpleTransition} from "./SimpleTransition"; import {SimpleTransition} from "./SimpleTransition";
import {Transition} from "./Transition";
export class SimpleState extends State<SimpleTransition> { export class SimpleState extends State<SimpleTransition> {
stateLabel: string = "";
stateDescription: string = "";
constructor(stateLabel: string, stateDescription: string) {
super();
this.stateLabel = stateLabel;
this.stateDescription = stateDescription;
}
equals(state: State<Transition<any>>): boolean {
if(!(state instanceof SimpleState)) {
return false;
}
return this.stateLabel === (state as SimpleState).stateLabel;
}
} }

View File

@ -1,19 +1,12 @@
import {Transition} from "./Transition"; import {Transition} from "./Transition";
export abstract class State<T extends Transition<any>> { export abstract class State<T extends Transition<any>> {
stateLabel: string = "";
stateDescription: string = "";
incomingTransitions: T[] =[]; incomingTransitions: T[] =[];
outgoingTransitions: T[] =[]; outgoingTransitions: T[] =[];
initial: boolean = false; initial: boolean = false;
constructor(stateLabel: string, stateDescription: string) {
this.stateLabel = stateLabel;
this.stateDescription = stateDescription;
}
addIncomingTransition(transition: T) { addIncomingTransition(transition: T) {
this.incomingTransitions.push(transition); this.incomingTransitions.push(transition);
} }
@ -29,4 +22,6 @@ export abstract class State<T extends Transition<any>> {
removeOutgoingTransition(transition: T) { removeOutgoingTransition(transition: T) {
} }
abstract equals(state: State<Transition<any>>): boolean;
} }