ConceptCreator/e2e/game-model/gamesystems/CreateGamesystem.spec.ts

54 lines
2.9 KiB
TypeScript
Raw Normal View History

2024-02-10 10:11:07 +01:00
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";
test.describe('Test Create Gamesystems', () => {
test('Test creating gamesystem with invalid name', async => {
const gameModel = GamesystemTrainer.givenEmptyGameModel();
let result = gameModel.createGamesystem(undefined, undefined);
expect(result).toBeUndefined();
result = gameModel.createGamesystem(null, undefined);
expect(result).toBeUndefined();
})
test("Test creating gamesystem with valid name but without parent", async => {
const gameModel = GamesystemTrainer.givenEmptyGameModel();
let result = gameModel.createGamesystem(GamesystemTrainer.SIMPLEGAMESYSTEMNAME, undefined);
expect(result).toBeDefined();
expect(gameModel.gamesystems.length).toEqual(1);
expect(gameModel.findGamesystem(GamesystemTrainer.SIMPLEGAMESYSTEMNAME)).toBeDefined();
})
test("Test creating Gamesystem with valid name but with Product Parent", async => {
const gameModel = GamesystemTrainer.givenGameModelWithProductGamesytemOnTopLayer();
let result = gameModel.createGamesystem(GamesystemTrainer.SIMPLEGAMESYSTEM_LEAF_LEFT, GamesystemTrainer.TOP_PRODUCT_GAMESYSTEM_NAME);
expect(result).toBeDefined();
expect(result.parentGamesystem!.componentName).toEqual(GamesystemTrainer.TOP_PRODUCT_GAMESYSTEM_NAME);
expect(result.parentGamesystem!.innerGamesystems.length).toEqual(3);
expect(result.parentGamesystem!.innerGamesystems.includes(result)).toBeTruthy();
})
test("Test creating Gamesystem with valid name but with Simple Parent", async() => {
const gameModel = GamesystemTrainer.givenGameModelWithSimpleGamesystemOnTopLayer();
let result = gameModel.createGamesystem(GamesystemTrainer.SIMPLEGAMESYSTEM_LEAF_LEFT, GamesystemTrainer.SIMPLEGAMESYSTEMNAME);
expect(result).toBeDefined();
expect(gameModel.gamesystems.length).toEqual(1);
expect(gameModel.gamesystems[0]).toBeInstanceOf(ProductGamesystem);
expect(gameModel.gamesystems[0]).toEqual(result.parentGamesystem);
expect((gameModel.gamesystems[0] as ProductGamesystem).innerGamesystems.length).toEqual(1);
expect((gameModel.gamesystems[0] as ProductGamesystem).innerGamesystems.includes(result)).toBeTruthy();
})
});