diff --git a/old-ui/package.json b/old-ui/package.json index 7a7a1f82..dec545ed 100644 --- a/old-ui/package.json +++ b/old-ui/package.json @@ -1,6 +1,6 @@ { "name": "@gaia-project/old-ui", - "version": "1.2.24", + "version": "1.2.25", "scripts": { "serve": "vite --port 5193", "build": "vite build", diff --git a/old-ui/src/components/Game.vue b/old-ui/src/components/Game.vue index ab44fc59..85050284 100644 --- a/old-ui/src/components/Game.vue +++ b/old-ui/src/components/Game.vue @@ -5,19 +5,6 @@ -
-
- -
-
- { return data; }; +const planningEngine = () => { + const engine = new Engine( + Engine.parseMoves(`init 2 randomSeed +p1 faction terrans +p2 faction nevlas +terrans build m -1x2 +nevlas build m -1x0 +nevlas build m 0x-4 +terrans build m -4x-1 +nevlas booster booster7 +terrans booster booster3`) + ); + engine.players[0].data.knowledge = 12; + return engine; +}; + describe("old UI on the current engine", () => { beforeAll(() => { const Observer = class { @@ -78,6 +94,158 @@ terrans booster booster3`) } }); + it("inspects plan steps directly in the old UI without losing the list, then opens the explicit pencil", async () => { + const engine = new Engine( + Engine.parseMoves(`init 2 randomSeed +p1 faction terrans +p2 faction nevlas +terrans build m -1x2 +nevlas build m -1x0 +nevlas build m 0x-4 +terrans build m -4x-1 +nevlas booster booster7 +terrans booster booster3`) + ); + engine.players[0].data.knowledge = 12; + const host = document.createElement("div"); + host.id = "old-test"; + document.body.append(host); + const viewer = launch("#old-test"); + try { + viewer.emit("player", { index: 0 }); + viewer.emit("state", JSON.parse(JSON.stringify(engine))); + await vi.waitFor(() => expect(viewer.app.$el.querySelector(".old-map-canvas")).not.toBeNull()); + const game = (viewer.app.$el.querySelector(".old-ui-game") as any).__vue__; + game.enterAnalysisMode(); + game.resetAnalysisLine(); + game.applyAnalysisMove("terrans up nav."); + game.chargeAnalysisPower(); + game.applyAnalysisMove("terrans up gaia."); + await game.$nextTick(); + const moves = () => viewer.app.$el.querySelectorAll(".analysis-moves__move"); + moves()[0].click(); + await game.$nextTick(); + expect(game.analysisEdit).toEqual({ index: 0, appliedCount: 3, mode: "inspect" }); + expect(game.engine.players[0].data.knowledge).toBe(8); + expect(game.canPlay).toBe(false); + expect(moves()).toHaveLength(2); + moves()[1].click(); + await game.$nextTick(); + expect(game.analysisEdit.index).toBe(2); + expect(game.engine.players[0].data.knowledge).toBe(4); + expect(viewer.app.$el.querySelector('[aria-current="step"]')?.textContent).toContain("terrans up gaia."); + viewer.app.$el.querySelectorAll(".analysis-moves__edit")[1].click(); + await game.$nextTick(); + expect(game.analysisEdit).toEqual({ index: 2, appliedCount: 3, mode: "replace" }); + expect(game.engine.players[0].data.knowledge).toBe(8); + expect(game.canPlay).toBe(true); + expect(game.analysisEntries).toHaveLength(3); + } finally { + viewer.app.$destroy(); + window.localStorage.clear(); + document.body.replaceChildren(); + } + }); + + for (const uiMode of ["graphical", "table"]) { + it(`keeps hotseat final-pass resources and disables end insertion at earlier steps (${uiMode})`, async () => { + const engine = planningEngine(); + engine.round = 6; + engine.clearAvailableCommands(); + engine.generateAvailableCommands(); + const host = document.createElement("div"); + host.id = "old-test"; + document.body.append(host); + const viewer = launch("#old-test"); + try { + // No "player" event: this is hotseat, with no locked seat to identify the plan's owner. + viewer.emit("state", JSON.parse(JSON.stringify(engine))); + viewer.emit("preferences", { uiMode }); + await vi.waitFor(() => expect(viewer.app.$el.querySelector(".old-ui-game")).not.toBeNull()); + const game = (viewer.app.$el.querySelector(".old-ui-game") as any).__vue__; + await vi.waitFor(() => expect(game.engine.moveHistory).toEqual(engine.moveHistory)); + await vi.waitFor(() => expect(game.uiMode).toBe(uiMode)); + viewer.store.commit("hosted", false); + expect(game.myLockedSeat).toBeUndefined(); + game.enterAnalysisMode(); + expect(game.analysisMode).toBe(true); + game.resetAnalysisLine(); + game.applyAnalysisMove("terrans up nav."); + game.applyAnalysisMove("terrans pass"); + expect(game.engine.ended).toBe(true); + expect(game.analysisCanAppend).toBe(false); + game.inspectAnalysisMove(1); + await game.$nextTick(); + const resourceBar = viewer.app.$el.querySelector(".sticky-resource-bar") as any; + expect(resourceBar).not.toBeNull(); + expect(resourceBar.__vue__.player).toBe(game.engine.players[game.analysisSeat]); + const addAtEnd = () => viewer.app.$el.querySelector('[aria-label="Add move at end"]'); + expect(addAtEnd().disabled).toBe(true); + viewer.app.$el.querySelectorAll(".analysis-moves__move")[0].click(); + await game.$nextTick(); + expect(game.analysisEdit).toEqual({ index: 0, appliedCount: 2, mode: "inspect" }); + expect(game.engine.ended).toBe(false); + expect(game.analysisCanAppend).toBe(false); + expect(addAtEnd().disabled).toBe(true); + expect(viewer.app.$el.querySelector(".analysis-strip, #root > [role='alert']")).toBeNull(); + } finally { + viewer.app.$destroy(); + window.localStorage.clear(); + document.body.replaceChildren(); + } + }); + + it(`keeps rollback restore/discard controls inline without a top alert (${uiMode})`, async () => { + const engine = planningEngine(); + const entries = [{ kind: "move", move: "terrans up nav." }]; + const saveDivergentPlan = () => + window.localStorage.setItem( + "analysis-mode::0", + JSON.stringify({ lines: [entries], active: 0, baseMoveCount: engine.moveHistory.length + 1 }) + ); + const host = document.createElement("div"); + host.id = "old-test"; + document.body.append(host); + const viewer = launch("#old-test"); + try { + viewer.emit("player", { index: 0 }); + viewer.emit("state", JSON.parse(JSON.stringify(engine))); + viewer.emit("preferences", { uiMode }); + await vi.waitFor(() => expect(viewer.app.$el.querySelector(".old-ui-game")).not.toBeNull()); + const game = (viewer.app.$el.querySelector(".old-ui-game") as any).__vue__; + await vi.waitFor(() => expect(game.engine.moveHistory).toEqual(engine.moveHistory)); + await vi.waitFor(() => expect(game.uiMode).toBe(uiMode)); + viewer.store.commit("hosted", false); + for (const choice of ["Restore anyway", "Discard"]) { + saveDivergentPlan(); + game.enterAnalysisMode(); + await game.$nextTick(); + expect(game.analysisPendingRestore).not.toBeNull(); + expect(viewer.app.$el.querySelector(".analysis-strip, #root > [role='alert']")).toBeNull(); + const prompt = viewer.app.$el.querySelector("#move .analysis-restore"); + expect(prompt).not.toBeNull(); + const button = [...prompt.querySelectorAll("button")].find( + (button) => button.textContent.trim() === choice + ); + button.click(); + await game.$nextTick(); + expect(game.analysisPendingRestore).toBeNull(); + expect(viewer.app.$el.querySelector(".analysis-restore")).toBeNull(); + expect(game.analysisEntries).toEqual(choice === "Restore anyway" ? entries : []); + if (choice === "Restore anyway") { + expect(viewer.app.$el.querySelector(".analysis-moves__move")?.textContent).toContain("terrans up nav."); + } + game.exitAnalysisMode(); + await game.$nextTick(); + } + } finally { + viewer.app.$destroy(); + window.localStorage.clear(); + document.body.replaceChildren(); + } + }); + } + for (const id of ["base", ...selfContainedScenarios.map((s) => s.id)]) { it(`renders the actual old player/map components and current controls for ${id}`, async () => { const host = document.createElement("div"); diff --git a/viewer/package.json b/viewer/package.json index 0a78e350..24c5c5d9 100644 --- a/viewer/package.json +++ b/viewer/package.json @@ -1,6 +1,6 @@ { "name": "@gaia-project/viewer", - "version": "5.22.24", + "version": "5.22.25", "description": "Functions to visualize the map and boards for gaia project inside html canvas", "contributors": [ "coyotte508", diff --git a/viewer/src/components/AnalysisMoves.spec.ts b/viewer/src/components/AnalysisMoves.spec.ts index dadc752d..40a7529b 100644 --- a/viewer/src/components/AnalysisMoves.spec.ts +++ b/viewer/src/components/AnalysisMoves.spec.ts @@ -28,13 +28,57 @@ describe("AnalysisMoves prefix programming", () => { await buttons.at(3).trigger("click"); expect(wrapper.emitted("commit")).to.have.length(1); // Existing edit and delete events still carry entry indices, not move counts. - await wrapper.findAll(".analysis-moves__move").at(1).trigger("click"); + await wrapper.findAll(".analysis-moves__edit").at(1).trigger("click"); await wrapper.findAll(".analysis-moves__remove").at(2).trigger("click"); expect(wrapper.emitted("edit")).to.deep.equal([[2]]); expect(wrapper.emitted("remove")).to.deep.equal([[2]]); wrapper.destroy(); }); + it("keeps the whole plan visible, highlights the inspected step and separates viewing from editing", async () => { + const wrapper = mount(AnalysisMoves, { + propsData: { ...propsData, activeIndex: 2, inspecting: true, mutationsDisabled: true }, + }); + expect(wrapper.findAll(".analysis-moves__row")).to.have.length(5); + expect(wrapper.findAll(".analysis-moves__past")).to.have.length(1); + expect(wrapper.findAll(".analysis-moves__row--selected")).to.have.length(1); + expect(wrapper.find('[aria-current="step"]').text()).to.contain("b"); + expect(wrapper.find(".analysis-moves__selected-state").text()).to.equal("Viewing"); + const moves = wrapper.findAll(".analysis-moves__move"); + expect(moves.at(1).attributes("aria-label")).to.equal("View after move 3: b"); + await moves.at(0).trigger("click"); + await moves.at(1).trigger("click"); + expect(wrapper.emitted("inspect")).to.deep.equal([[0], [2]]); + expect(wrapper.emitted("edit")).to.equal(undefined); + await wrapper.findAll(".analysis-moves__edit").at(1).trigger("click"); + expect(wrapper.emitted("edit")).to.deep.equal([[2]]); + await wrapper.find(".analysis-moves__remove").trigger("click"); + await wrapper.find(".analysis-moves__program").trigger("click"); + expect(wrapper.emitted("remove")).to.equal(undefined); + expect(wrapper.emitted("commit")).to.equal(undefined); + // A blocked move can be repaired, but its after-position does not exist yet. + await moves.at(2).trigger("click"); + await wrapper.findAll(".analysis-moves__edit").at(2).trigger("click"); + expect(wrapper.emitted("inspect")).to.have.length(2); + expect(wrapper.emitted("edit")).to.deep.equal([[2], [3]]); + wrapper.destroy(); + }); + + it("highlights editing and insertion without hiding the remaining rows", async () => { + const wrapper = mount(AnalysisMoves, { propsData: { ...propsData, activeIndex: 0 } }); + expect(wrapper.find(".analysis-moves__selected-state").text()).to.equal("Editing"); + expect(wrapper.findAll(".analysis-moves__row")).to.have.length(5); + await wrapper.setProps({ inserting: true, activeIndex: 2 }); + expect(wrapper.find(".analysis-moves__row--selected").exists()).to.equal(false); + expect(wrapper.find(".analysis-moves__insert--selected").attributes("aria-label")).to.equal("Insert before move 3"); + await wrapper.setProps({ disabled: true }); + await wrapper.find(".analysis-moves__move").trigger("click"); + await wrapper.find(".analysis-moves__edit").trigger("click"); + expect(wrapper.emitted("inspect")).to.equal(undefined); + expect(wrapper.emitted("edit")).to.equal(undefined); + wrapper.destroy(); + }); + it("disables simulated but uncommittable endpoints and all controls during an unfinished move", async () => { const wrapper = mount(AnalysisMoves, { propsData: { ...propsData, appliedCount: 5, committableMoves: 1 } }); expect(wrapper.findAll(".analysis-moves__program").at(1).attributes("disabled")).to.equal("disabled"); diff --git a/viewer/src/components/AnalysisMoves.vue b/viewer/src/components/AnalysisMoves.vue index 2fae063f..44888a03 100644 --- a/viewer/src/components/AnalysisMoves.vue +++ b/viewer/src/components/AnalysisMoves.vue @@ -10,6 +10,7 @@ v-if="entry.kind !== 'faction'" type="button" class="analysis-moves__insert" + :class="{ 'analysis-moves__insert--selected': activeIndex === index && inserting }" :disabled="disabled || index > appliedCount" :aria-label="insertLabel(index)" :title="insertLabel(index)" @@ -18,7 +19,11 @@ > -
+
{{ entry.kind === "adjust" ? `Assume ${entry.charge} power charged` : `Faction setup: ${entry.lineup.join(", ")}` }} +
-