mirror of
https://github.com/rommapp/romm.git
synced 2026-12-05 05:07:31 +01:00
simplify findings (reuse, simplification, efficiency, altitude). Behaviour it fixes along the way: - A state load held back the screen and the sound but not the writes, and dumping the SRAM for the new baseline fires a tick of its own: a tick that had already read the restored SRAM found it stable and changed, and uploaded the restore before the baseline landed. A state now closes the same write gate a save load does, and quick load goes through the same window. - Save & Quit rewrote the held row without the frame the tick had stored. The write now owns which frame goes with the bytes it is given, so no caller can pass the wrong one, and it does not write out again bytes already held. - A save whose first capture failed took a new screenshot on every retry. - The shell kept polling the store every 30s while offline, and in game kept a timer armed for a save only the running session would hand over. - A store upgrade wiped every row, which after release would drop users' unsynced progress. It now keeps them and only drops stores it stopped using. Reuse and one home per rule: - The save, state and screenshot files are built by the API modules for both the live uploads and the retries. - The core compatibility rule is shared by the launch screen and the in-game picker. - The banner uses useDelayedFlag, the toast host useEventListener, the retry refresh useRomSync().refetchRom, the refusal text errorMessage(), and the player's notices useSnackbar. - The ledger of rows the server took is read in list() alone, and the retry judges a refused upload and a failed request in one place. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QTsTgdoBinvvxzXeLUjBmV
103 lines
3.1 KiB
TypeScript
103 lines
3.1 KiB
TypeScript
import { mount } from "@vue/test-utils";
|
|
import { createPinia, setActivePinia } from "pinia";
|
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
import { ref } from "vue";
|
|
import storePlaying from "@/stores/playing";
|
|
import BackendStatusBanner from "./BackendStatusBanner.vue";
|
|
|
|
vi.mock("vue-i18n", () => ({
|
|
useI18n: () => ({ t: (key: string) => key }),
|
|
}));
|
|
|
|
const isOffline = ref(false);
|
|
vi.mock("@/v2/composables/useServerConnection", () => ({
|
|
useServerConnection: () => ({ isOffline, retryNow: vi.fn() }),
|
|
}));
|
|
|
|
vi.mock("@v2/lib", () => ({
|
|
RBtn: { name: "RBtn", template: "<button><slot /></button>" },
|
|
RIcon: { name: "RIcon", template: "<i />" },
|
|
RTooltip: {
|
|
name: "RTooltip",
|
|
props: ["text", "activator", "location"],
|
|
template: "<span class='r-tooltip-stub' />",
|
|
},
|
|
}));
|
|
|
|
let wrapper: ReturnType<typeof mount> | null = null;
|
|
|
|
async function render() {
|
|
wrapper = mount(BackendStatusBanner);
|
|
await wrapper.vm.$nextTick();
|
|
}
|
|
|
|
const banner = () => wrapper!.find(".r-backend-banner");
|
|
const body = () => wrapper!.find(".r-backend-banner__body");
|
|
|
|
describe("BackendStatusBanner", () => {
|
|
beforeEach(() => {
|
|
setActivePinia(createPinia());
|
|
vi.useFakeTimers();
|
|
isOffline.value = false;
|
|
});
|
|
|
|
afterEach(() => {
|
|
wrapper?.unmount();
|
|
wrapper = null;
|
|
vi.useRealTimers();
|
|
});
|
|
|
|
it("stays out of sight while the server answers", async () => {
|
|
await render();
|
|
|
|
expect(banner().exists()).toBe(false);
|
|
});
|
|
|
|
it("offers the retry button outside a game", async () => {
|
|
isOffline.value = true;
|
|
|
|
await render();
|
|
|
|
expect(banner().classes()).not.toContain("r-backend-banner--in-game");
|
|
expect(wrapper!.find(".r-backend-banner__retry").exists()).toBe(true);
|
|
// The message is right there to read, so nothing hovers over it.
|
|
expect(wrapper!.find(".r-tooltip-stub").exists()).toBe(false);
|
|
});
|
|
|
|
// A notice the player cannot dismiss has no business sitting over the game.
|
|
it("shrinks to its icon once a game has been running a while", async () => {
|
|
isOffline.value = true;
|
|
storePlaying().setPlaying(true);
|
|
|
|
await render();
|
|
expect(banner().classes()).toContain("r-backend-banner--in-game");
|
|
expect(body().exists()).toBe(true);
|
|
expect(wrapper!.find(".r-backend-banner__retry").exists()).toBe(false);
|
|
|
|
await vi.advanceTimersByTimeAsync(6000);
|
|
await wrapper!.vm.$nextTick();
|
|
|
|
expect(body().exists()).toBe(false);
|
|
expect(banner().classes()).toContain("r-backend-banner--collapsed");
|
|
// Only the icon is left, so the message moves into a tooltip of our own.
|
|
expect(wrapper!.find(".r-tooltip-stub").exists()).toBe(true);
|
|
});
|
|
|
|
it("says its piece again in full once the game is over", async () => {
|
|
isOffline.value = true;
|
|
const playing = storePlaying();
|
|
playing.setPlaying(true);
|
|
|
|
await render();
|
|
await vi.advanceTimersByTimeAsync(6000);
|
|
await wrapper!.vm.$nextTick();
|
|
expect(body().exists()).toBe(false);
|
|
|
|
playing.setPlaying(false);
|
|
await wrapper!.vm.$nextTick();
|
|
|
|
expect(body().exists()).toBe(true);
|
|
expect(wrapper!.find(".r-backend-banner__retry").exists()).toBe(true);
|
|
});
|
|
});
|