CORPORATION: Rework share price calculation + UI improvements (#782)

This commit is contained in:
Jesse Clark
2023-09-19 21:36:48 -07:00
committed by GitHub
parent f6e1c171ae
commit 3ae3f947ac
34 changed files with 654 additions and 417 deletions

View File

@@ -2,11 +2,22 @@ import { PositiveInteger } from "../../src/types";
import { Corporation } from "../../src/Corporation/Corporation";
import { CorpUpgrades } from "../../src/Corporation/data/CorporationUpgrades";
import { calculateMaxAffordableUpgrade, calculateUpgradeCost } from "../../src/Corporation/helpers";
import { Player, setPlayer } from "../../src/Player";
import { PlayerObject } from "../../src/PersonObjects/Player/PlayerObject";
import {
AcceptInvestmentOffer,
BuyBackShares,
GoPublic,
IssueNewShares,
SellShares,
} from "../../src/Corporation/Actions";
describe("Corporation", () => {
let corporation: Corporation;
beforeEach(() => {
setPlayer(new PlayerObject());
Player.init();
corporation = new Corporation({ name: "Test" });
});
@@ -57,4 +68,48 @@ describe("Corporation", () => {
}
});
});
describe("Corporation totalShares", () => {
function expectSharesToAddUp(corp: Corporation) {
expect(corp.totalShares).toEqual(corp.numShares + corp.investorShares + corp.issuedShares);
}
it("should equal the sum of each kind of shares", () => {
expectSharesToAddUp(corporation);
});
it("should be preserved by seed funding", () => {
const seedFunded = true;
Player.startCorporation("TestCorp", seedFunded);
expectSharesToAddUp(Player.corporation!);
});
it("should be preserved by acceptInvestmentOffer", () => {
AcceptInvestmentOffer(corporation);
expectSharesToAddUp(corporation);
});
it("should be preserved by goPublic", () => {
const numShares = 1e8;
GoPublic(corporation, numShares);
expectSharesToAddUp(corporation);
});
it("should be preserved by IssueNewShares", () => {
const numShares = 1e8;
GoPublic(corporation, numShares);
corporation.issueNewSharesCooldown = 0;
IssueNewShares(corporation, numShares);
expectSharesToAddUp(corporation);
});
it("should be preserved by BuyBackShares", () => {
const numShares = 1e8;
GoPublic(corporation, numShares);
BuyBackShares(corporation, numShares);
expectSharesToAddUp(corporation);
});
it("should be preserved by SellShares", () => {
const numShares = 1e8;
GoPublic(corporation, numShares);
corporation.shareSaleCooldown = 0;
SellShares(corporation, numShares);
expectSharesToAddUp(corporation);
});
});
});

View File

@@ -1150,6 +1150,7 @@ exports[`Check Save File Continuity PlayerSave continuity 1`] = `
"expenses": 0,
"fundingRound": 0,
"funds": 150000000000,
"investorShares": 0,
"issueNewSharesCooldown": 0,
"issuedShares": 0,
"maxDivisions": 20,