|
| 1 | +import { DatabaseSync } from "node:sqlite"; |
1 | 2 | import { expect, test } from "@playwright/test"; |
2 | | -import { addGoal, createBlock } from "./helpers"; |
| 3 | +import { |
| 4 | + activeProjectDbFile, |
| 5 | + addGoal, |
| 6 | + createBlock, |
| 7 | + goto, |
| 8 | + uniqueName, |
| 9 | +} from "./helpers"; |
3 | 10 |
|
4 | 11 | /** |
5 | 12 | * Inline building-count pin (#121): a recipe row's building count is click-to- |
@@ -38,3 +45,99 @@ test("building count: click to fix, tint shows fixed, clear to unpin", async ({ |
38 | 45 | await expect(page.locator('button[title="click to fix the building count"]')).toBeVisible(); |
39 | 46 | await expect(page.locator('button[title^="fixed at"]')).toHaveCount(0); |
40 | 47 | }); |
| 48 | + |
| 49 | +test("variable generator shows its average and min-max output", async ({ page }) => { |
| 50 | + const db = new DatabaseSync(activeProjectDbFile()); |
| 51 | + db.exec("PRAGMA busy_timeout = 5000"); |
| 52 | + const product = db |
| 53 | + .prepare( |
| 54 | + `SELECT amount, amount_min, amount_max FROM recipe_products |
| 55 | + WHERE recipe = 'generate-multiblade-turbine-mk01' AND name = 'pyops-electricity'`, |
| 56 | + ) |
| 57 | + .get() as { amount: number; amount_min: number | null; amount_max: number | null }; |
| 58 | + let id: number; |
| 59 | + try { |
| 60 | + db.prepare( |
| 61 | + `UPDATE recipe_products SET amount = 1.2, amount_min = 0.4, amount_max = 2 |
| 62 | + WHERE recipe = 'generate-multiblade-turbine-mk01' AND name = 'pyops-electricity'`, |
| 63 | + ).run(); |
| 64 | + const data = { |
| 65 | + recipes: [ |
| 66 | + "generate-steam-engine-250", |
| 67 | + "boil-steam-250", |
| 68 | + "generate-multiblade-turbine-mk01", |
| 69 | + ], |
| 70 | + made: ["steam"], |
| 71 | + pins: [{ kind: "count", recipe: "generate-multiblade-turbine-mk01", count: 40 }], |
| 72 | + machines: { |
| 73 | + "generate-steam-engine-250": "steam-engine", |
| 74 | + "boil-steam-250": "boiler", |
| 75 | + "generate-multiblade-turbine-mk01": "multiblade-turbine-mk01", |
| 76 | + }, |
| 77 | + fuels: { "boil-steam-250": "raw-coal" }, |
| 78 | + goals: [{ name: "pyops-electricity", rate: 50 }], |
| 79 | + }; |
| 80 | + const inserted = db |
| 81 | + .prepare("INSERT INTO blocks (name, data) VALUES (?, ?)") |
| 82 | + .run(uniqueName("Variable power"), JSON.stringify(data)); |
| 83 | + id = Number(inserted.lastInsertRowid); |
| 84 | + } finally { |
| 85 | + db.close(); |
| 86 | + } |
| 87 | + |
| 88 | + try { |
| 89 | + await goto(page, `/block/${id}`); |
| 90 | + const ignore = page.getByRole("button", { name: "Ignore for now" }); |
| 91 | + if (await ignore.isVisible()) await ignore.click(); |
| 92 | + await expect(page.locator('[data-rate-range="variable"]')).toHaveText( |
| 93 | + "48 MW avg · 16 MW–80 MW", |
| 94 | + ); |
| 95 | + } finally { |
| 96 | + const cleanup = new DatabaseSync(activeProjectDbFile()); |
| 97 | + try { |
| 98 | + cleanup.exec("PRAGMA busy_timeout = 5000"); |
| 99 | + cleanup |
| 100 | + .prepare( |
| 101 | + `UPDATE recipe_products SET amount = ?, amount_min = ?, amount_max = ? |
| 102 | + WHERE recipe = 'generate-multiblade-turbine-mk01' AND name = 'pyops-electricity'`, |
| 103 | + ) |
| 104 | + .run(product.amount, product.amount_min, product.amount_max); |
| 105 | + cleanup.prepare("DELETE FROM blocks WHERE id = ?").run(id); |
| 106 | + } finally { |
| 107 | + cleanup.close(); |
| 108 | + } |
| 109 | + } |
| 110 | +}); |
| 111 | + |
| 112 | +test("recipe picker groups unlocked choices and disables locked buildings", async ({ page }) => { |
| 113 | + await createBlock(page); |
| 114 | + await page.locator('button[title="add a goal product"]').click(); |
| 115 | + const goalDialog = page.getByRole("dialog", { name: "Add a goal product" }); |
| 116 | + await goalDialog.getByPlaceholder("search an item or fluid…").fill("pyops electricity"); |
| 117 | + await goalDialog.getByRole("button", { name: "Electricity (MJ)", exact: true }).click(); |
| 118 | + await expect(goalDialog).toBeHidden(); |
| 119 | + await page.locator('button[aria-label^="add a recipe that makes "]').click(); |
| 120 | + |
| 121 | + const picker = page.getByRole("dialog", { name: "Recipes that make Electricity (MJ)" }); |
| 122 | + const unlocked = picker.getByText("Unlocked now", { exact: true }); |
| 123 | + const locked = picker.getByText("Locked or unavailable", { exact: true }); |
| 124 | + await expect(unlocked).toBeVisible(); |
| 125 | + await expect(locked).toBeVisible(); |
| 126 | + expect((await unlocked.boundingBox())!.y).toBeLessThan((await locked.boundingBox())!.y); |
| 127 | + |
| 128 | + const steam = picker.getByRole("button", { name: /Steam engine power \(150°\)/ }); |
| 129 | + await expect(steam).toHaveAttribute("aria-disabled", "false"); |
| 130 | + await expect(steam).toContainText("unlocked now · Steam engine"); |
| 131 | + |
| 132 | + const solar = picker.getByRole("button", { name: /Solar panel power \(peak\)/ }); |
| 133 | + await expect(solar).toHaveAttribute("aria-disabled", "true"); |
| 134 | + await expect(solar).toContainText("building locked · Solar panel · needs Solar energy"); |
| 135 | + await solar.click({ force: true }); |
| 136 | + await expect(picker).toBeVisible(); |
| 137 | + |
| 138 | + // Py's `-blank` runtime entity uses the same localized name and output. It is |
| 139 | + // an alternate state of this building, not a second recipe choice. |
| 140 | + await expect( |
| 141 | + picker.getByText('Multiblade "fish" turbine power (average)', { exact: true }), |
| 142 | + ).toHaveCount(1); |
| 143 | +}); |
0 commit comments