mirror of
https://github.com/rommapp/romm.git
synced 2026-12-03 10:33:22 +01:00
Share the vue-i18n test mock and let Vitest reset mocks, stubs and env (#5027)
This commit is contained in:
3
frontend/__mocks__/vue-i18n.ts
Normal file
3
frontend/__mocks__/vue-i18n.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
// Used by `vi.mock("vue-i18n")` with no factory: `t` echoes the key, so tests
|
||||
// assert on which message a component asked for rather than its wording.
|
||||
export const useI18n = () => ({ t: (key: string) => key });
|
||||
@@ -1,4 +1,4 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { DetailedRomSchema } from "@/__generated__";
|
||||
import saveApi, { UNLOAD_SAVE_MAX_BYTES } from "@/services/api/save";
|
||||
import { saveFixture } from "@/utils/assets.fixtures";
|
||||
@@ -35,11 +35,6 @@ describe("sendSaveOnUnload", () => {
|
||||
document.cookie = "romm_csrftoken=token";
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.unstubAllGlobals();
|
||||
fetchMock.mockClear();
|
||||
});
|
||||
|
||||
it("opens a version with a keepalive request the page does not wait for", () => {
|
||||
const sent = saveApi.sendSaveOnUnload({
|
||||
rom,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import streamingApi from "@/services/api/streaming";
|
||||
|
||||
const post = vi.hoisted(() => vi.fn());
|
||||
@@ -15,12 +15,6 @@ describe("releaseSessionKeepalive", () => {
|
||||
vi.stubGlobal("fetch", fetchMock);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.unstubAllGlobals();
|
||||
vi.restoreAllMocks();
|
||||
fetchMock.mockClear();
|
||||
});
|
||||
|
||||
it("names the container and the claim where URLSearchParams has no size", async () => {
|
||||
// Chrome 111-112 and Safari 16.4 are in .browserslistrc and predate it.
|
||||
vi.spyOn(URLSearchParams.prototype, "size", "get").mockReturnValue(
|
||||
@@ -52,11 +46,6 @@ describe("saveAndExitKeepalive", () => {
|
||||
vi.stubGlobal("fetch", fetchMock);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.unstubAllGlobals();
|
||||
fetchMock.mockClear();
|
||||
});
|
||||
|
||||
it("names the container and the claim it saves", async () => {
|
||||
await streamingApi.saveAndExitKeepalive(
|
||||
"ps2",
|
||||
|
||||
1
frontend/src/services/cache/api.test.ts
vendored
1
frontend/src/services/cache/api.test.ts
vendored
@@ -34,7 +34,6 @@ function clearedPattern(callIndex = 0): string {
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
vi.mocked(cacheService.request).mockResolvedValue({
|
||||
data: { items: [] },
|
||||
} as AxiosResponse);
|
||||
|
||||
@@ -37,7 +37,6 @@ function installBridge(bridge: Partial<RommNativeBridge>): void {
|
||||
|
||||
beforeEach(() => {
|
||||
delete window.rommNative;
|
||||
vi.restoreAllMocks();
|
||||
vi.spyOn(console, "error").mockImplementation(() => {});
|
||||
});
|
||||
|
||||
|
||||
@@ -33,10 +33,6 @@ describe("pendingAssetStore without IndexedDB", () => {
|
||||
vi.spyOn(console, "error").mockImplementation(() => undefined);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
// A private window looks the same: the player must hear nothing was kept.
|
||||
it("says a write kept nothing rather than throwing", async () => {
|
||||
await expect(
|
||||
@@ -69,10 +65,6 @@ describe("pendingAssetStore without IndexedDB", () => {
|
||||
});
|
||||
|
||||
describe("pendingAssetId", () => {
|
||||
afterEach(() => {
|
||||
vi.unstubAllGlobals();
|
||||
});
|
||||
|
||||
it("keys a capture to its rom", () => {
|
||||
expect(pendingAssetId(7)).toMatch(/^7:.+/);
|
||||
});
|
||||
@@ -236,9 +228,6 @@ describe("syncPendingAssets", () => {
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.unstubAllGlobals();
|
||||
vi.unstubAllEnvs();
|
||||
vi.restoreAllMocks();
|
||||
romApiMocks.getRom.mockReset();
|
||||
saveApiMocks.uploadSaves.mockReset();
|
||||
stateApiMocks.uploadStates.mockReset();
|
||||
|
||||
@@ -93,17 +93,12 @@ function makeRom(overrides: Partial<SimpleRom> = {}): SimpleRom {
|
||||
beforeEach(() => {
|
||||
shellPresent.value = true;
|
||||
emit = null;
|
||||
fetchPlatformSupport.mockClear();
|
||||
fetchPlatformSupport.mockResolvedValue({});
|
||||
launchNative.mockClear();
|
||||
launchNative.mockResolvedValue({ romId: 1, emulator: "RetroArch" });
|
||||
cancelNative.mockClear();
|
||||
cancelNative.mockResolvedValue(true);
|
||||
getRom.mockClear();
|
||||
getRom.mockResolvedValue({
|
||||
data: { files: [{ full_path: "psx/disc.chd", file_size_bytes: 700 }] },
|
||||
});
|
||||
unsubscribe.mockClear();
|
||||
soleFile.value = { full_path: "snes/game.sfc", file_size_bytes: 4194304 };
|
||||
});
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ function boxSize({ width, height }: Size): ResizeObserverSize[] {
|
||||
return [{ inlineSize: width, blockSize: height }];
|
||||
}
|
||||
|
||||
/** Installs the fake for the current test; undo with `vi.unstubAllGlobals()`. */
|
||||
/** Installs the fake for the current test; `unstubGlobals` removes it before the next one. */
|
||||
export function stubResizeObserver() {
|
||||
FakeResizeObserver.instances.clear();
|
||||
vi.stubGlobal("ResizeObserver", FakeResizeObserver);
|
||||
|
||||
@@ -3,9 +3,7 @@ import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { computed, nextTick, ref } from "vue";
|
||||
import AppNav from "./AppNav.vue";
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
vi.mock("vue-i18n");
|
||||
|
||||
vi.mock("@/v2/composables/useNavDestinations", () => ({
|
||||
useNavDestinations: () => ({
|
||||
|
||||
@@ -4,9 +4,7 @@ import { ref } from "vue";
|
||||
import storePlaying from "@/stores/playing";
|
||||
import BackendStatusBanner from "./BackendStatusBanner.vue";
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
vi.mock("vue-i18n");
|
||||
|
||||
const isOffline = ref(false);
|
||||
const isWebSocketDegraded = ref(false);
|
||||
@@ -46,8 +44,6 @@ describe("BackendStatusBanner", () => {
|
||||
vi.useFakeTimers();
|
||||
isOffline.value = false;
|
||||
isWebSocketDegraded.value = false;
|
||||
retryNow.mockClear();
|
||||
retryWebSocket.mockClear();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
||||
@@ -11,9 +11,7 @@ const { requestPasswordReset, success } = vi.hoisted(() => ({
|
||||
vi.mock("@/services/api/identity", () => ({
|
||||
default: { requestPasswordReset },
|
||||
}));
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
vi.mock("vue-i18n");
|
||||
vi.mock("@/v2/composables/useSnackbar", async (importOriginal) => ({
|
||||
...(await importOriginal<typeof import("@/v2/composables/useSnackbar")>()),
|
||||
useSnackbar: () => ({ success, error: vi.fn() }),
|
||||
|
||||
@@ -2,9 +2,7 @@ import { mount } from "@vue/test-utils";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import CollectionTile from "./CollectionTile.vue";
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
vi.mock("vue-i18n");
|
||||
vi.mock("vue-router", async (importOriginal) => ({
|
||||
...(await importOriginal<typeof import("vue-router")>()),
|
||||
useRouter: () => ({ push: vi.fn() }),
|
||||
|
||||
@@ -8,9 +8,7 @@ import storeHeartbeat from "@/stores/heartbeat";
|
||||
import type { Events } from "@/types/emitter";
|
||||
import AboutDialog from "./AboutDialog.vue";
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
vi.mock("vue-i18n");
|
||||
|
||||
// happy-dom has no ResizeObserver that fires, so the test lays the grid out.
|
||||
const resize = vi.hoisted(() => ({ layout: () => {} }));
|
||||
|
||||
@@ -6,9 +6,7 @@ import CopyDownloadLinkDialog from "./CopyDownloadLinkDialog.vue";
|
||||
|
||||
const { copy } = vi.hoisted(() => ({ copy: vi.fn() }));
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
vi.mock("vue-i18n");
|
||||
|
||||
vi.mock("@/v2/composables/useClipboard", () => ({
|
||||
useClipboard: () => ({ isSupported: true, copy }),
|
||||
|
||||
@@ -18,9 +18,7 @@ const route = reactive<{ name: string; params: Record<string, string> }>({
|
||||
params: { rom: "5" },
|
||||
});
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
vi.mock("vue-i18n");
|
||||
vi.mock("vue-router", async (importOriginal) => ({
|
||||
...(await importOriginal<typeof import("vue-router")>()),
|
||||
useRoute: () => route,
|
||||
@@ -87,7 +85,6 @@ async function deleteShownGame() {
|
||||
|
||||
describe("DeleteRomDialog", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
route.name = "rom";
|
||||
route.params = { rom: "5" };
|
||||
deleteRoms.mockResolvedValue({
|
||||
@@ -124,7 +121,6 @@ describe("DeleteRomDialog", () => {
|
||||
|
||||
describe("DeleteRomDialog with a large selection", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
deleteRoms.mockResolvedValue({
|
||||
data: { failed_ids: [], successful_items: 120 },
|
||||
});
|
||||
|
||||
@@ -23,11 +23,7 @@ const {
|
||||
socketHandlers: new Map<string, (payload: unknown) => void>(),
|
||||
}));
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({
|
||||
t: (key: string) => key,
|
||||
}),
|
||||
}));
|
||||
vi.mock("vue-i18n");
|
||||
|
||||
vi.mock("@/services/api/device", () => ({
|
||||
default: { fetchDevices, fetchOnlineDeviceIds },
|
||||
@@ -131,7 +127,6 @@ async function toggle(wrapper: VueWrapper, checked: boolean) {
|
||||
describe("InstallOnDeviceDialog", () => {
|
||||
beforeEach(() => {
|
||||
vi.useFakeTimers();
|
||||
vi.clearAllMocks();
|
||||
socketHandlers.clear();
|
||||
fetchOnlineDeviceIds.mockResolvedValue({ data: [] });
|
||||
fetchRomInstalls.mockResolvedValue({ data: [] });
|
||||
|
||||
@@ -24,9 +24,7 @@ const {
|
||||
snackbarError: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
vi.mock("vue-i18n");
|
||||
|
||||
vi.mock("@/services/api/collection", () => ({
|
||||
default: {
|
||||
@@ -119,7 +117,6 @@ function mountDialog(
|
||||
|
||||
describe("ManageCollectionsDialog gallery reconcile", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
storeAuth().setCurrentUser({ id: USER_ID } as User);
|
||||
});
|
||||
|
||||
@@ -218,7 +215,6 @@ describe("ManageCollectionsDialog gallery reconcile", () => {
|
||||
|
||||
describe("ManageCollectionsDialog create", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
storeAuth().setCurrentUser(userFixture({ id: USER_ID }));
|
||||
});
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { flushPromises, mount, type VueWrapper } from "@vue/test-utils";
|
||||
import mitt, { type Emitter } from "mitt";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import type { DetailedRom } from "@/stores/roms";
|
||||
import type { Events } from "@/types/emitter";
|
||||
import ManualUploadTargetDialog from "./ManualUploadTargetDialog.vue";
|
||||
@@ -15,9 +15,7 @@ const { uploadManuals, uploadFiles, getRom } = vi.hoisted(() => ({
|
||||
getRom: vi.fn(() => Promise.resolve({ data: {} })),
|
||||
}));
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
vi.mock("vue-i18n");
|
||||
|
||||
vi.mock("@/services/api/rom", () => ({
|
||||
default: { uploadManuals, getRom },
|
||||
@@ -104,10 +102,6 @@ async function upload(target: DetailedRom): Promise<VueWrapper> {
|
||||
}
|
||||
|
||||
describe("ManualUploadTargetDialog", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it("sends a single-file ROM's manual to resources without asking", async () => {
|
||||
const wrapper = await upload(rom({ has_simple_single_file: true }));
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { flushPromises, mount } from "@vue/test-utils";
|
||||
import mitt, { type Emitter } from "mitt";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { ref } from "vue";
|
||||
import type { SearchRom, SimpleRom } from "@/stores/roms";
|
||||
import type { Events } from "@/types/emitter";
|
||||
@@ -8,9 +8,7 @@ import MatchRomDialog from "./MatchRomDialog.vue";
|
||||
|
||||
const { searchRom } = vi.hoisted(() => ({ searchRom: vi.fn() }));
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
vi.mock("vue-i18n");
|
||||
vi.mock("vue-router", async (importOriginal) => ({
|
||||
...(await importOriginal<typeof import("vue-router")>()),
|
||||
useRoute: () => ({ name: "gallery" }),
|
||||
@@ -70,10 +68,6 @@ function match(overrides: Partial<SearchRom> = {}): SearchRom {
|
||||
}
|
||||
|
||||
describe("MatchRomDialog", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it("drops a search left running when the dialog closes", async () => {
|
||||
let finishStale: (value: { data: SearchRom[] }) => void = () => {};
|
||||
searchRom
|
||||
|
||||
@@ -14,9 +14,7 @@ const { startScan, persistSelection, snackbarInfo, sources } = vi.hoisted(
|
||||
}),
|
||||
);
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
vi.mock("vue-i18n");
|
||||
vi.mock("@/v2/composables/useScanTrigger", () => ({
|
||||
useScanTrigger: () => ({ startScan }),
|
||||
}));
|
||||
@@ -109,7 +107,6 @@ function scanButton(wrapper: Awaited<ReturnType<typeof openDialog>>) {
|
||||
|
||||
describe("RefreshMetadataDialog", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
startScan.mockReturnValue(true);
|
||||
sources.value = [];
|
||||
});
|
||||
|
||||
@@ -23,9 +23,7 @@ const { searchCover, searchRom, heartbeat } = vi.hoisted(() => ({
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
vi.mock("vue-i18n");
|
||||
vi.mock("@/services/api/sgdb", () => ({ default: { searchCover } }));
|
||||
vi.mock("@/services/api/rom", () => ({ default: { searchRom } }));
|
||||
vi.mock("@/stores/heartbeat", () => ({ default: () => heartbeat }));
|
||||
@@ -129,7 +127,6 @@ function gridThumbs(
|
||||
|
||||
describe("SearchCoverDialog", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
searchRom.mockResolvedValue({ data: [] });
|
||||
});
|
||||
|
||||
|
||||
@@ -4,9 +4,7 @@ import { describe, expect, it, vi } from "vitest";
|
||||
import { defineComponent, h } from "vue";
|
||||
import AlphaJumpMenu from "./AlphaJumpMenu.vue";
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
vi.mock("vue-i18n");
|
||||
|
||||
vi.mock("@/v2/composables/useWrapGridNav", () => ({
|
||||
useWrapGridNav: vi.fn(),
|
||||
|
||||
@@ -2,9 +2,7 @@ import { mount } from "@vue/test-utils";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import BackToTopButton from "./BackToTopButton.vue";
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
vi.mock("vue-i18n");
|
||||
|
||||
const { resized } = vi.hoisted(() => ({ resized: { callback: () => {} } }));
|
||||
vi.mock("@vueuse/core", async (importOriginal) => ({
|
||||
|
||||
@@ -57,7 +57,6 @@ function mountTab() {
|
||||
|
||||
describe("CollectionSettingsTab visibility", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
storeAuth().setCurrentUser(
|
||||
userFixture({ id: 1, oauth_scopes: ["collections.write"] }),
|
||||
);
|
||||
|
||||
@@ -3,9 +3,7 @@ import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { ref } from "vue";
|
||||
import GalleryToolbar from "./GalleryToolbar.vue";
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
vi.mock("vue-i18n");
|
||||
|
||||
const smAndUp = ref(true);
|
||||
vi.mock("@/v2/composables/useBreakpoint", () => ({
|
||||
|
||||
@@ -3,9 +3,7 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { ref } from "vue";
|
||||
import GameListHeader from "./GameListHeader.vue";
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
vi.mock("vue-i18n");
|
||||
|
||||
const smAndDown = ref(false);
|
||||
vi.mock("@/v2/composables/useBreakpoint", () => ({
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { flushPromises, mount, type VueWrapper } from "@vue/test-utils";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { nextTick, ref } from "vue";
|
||||
import storeAuth from "@/stores/auth";
|
||||
import storeCollections, { type Collection } from "@/stores/collections";
|
||||
@@ -155,7 +155,6 @@ async function clickHeart(wrapper: VueWrapper) {
|
||||
describe("SelectionBar bulk favorite", () => {
|
||||
beforeEach(() => {
|
||||
storeAuth().setCurrentUser(userFixture());
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it("creates the favourites collection when the instance has none", async () => {
|
||||
@@ -295,10 +294,6 @@ describe("SelectionBar bulk favorite", () => {
|
||||
});
|
||||
|
||||
describe("SelectionBar download", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it("offers the download action by default", () => {
|
||||
select(rom(1));
|
||||
|
||||
@@ -321,10 +316,6 @@ describe("SelectionBar download", () => {
|
||||
});
|
||||
|
||||
describe("SelectionBar select all", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it("triggers the whole-result select-all", async () => {
|
||||
select(rom(1));
|
||||
const wrapper = mountBar();
|
||||
@@ -350,10 +341,6 @@ describe("SelectionBar select all", () => {
|
||||
});
|
||||
|
||||
describe("SelectionBar bulk status", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it("ignores a status choice while the previous batch is running", async () => {
|
||||
let finish: () => void = () => {};
|
||||
updateUserRomProps.mockImplementation(
|
||||
@@ -390,7 +377,6 @@ describe("SelectionBar outline", () => {
|
||||
beforeEach(() => {
|
||||
storeAuth().setCurrentUser(userFixture());
|
||||
});
|
||||
afterEach(() => vi.unstubAllGlobals());
|
||||
|
||||
it("draws the outline from the bar's and notch's measured sizes", async () => {
|
||||
const observer = stubResizeObserver();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { flushPromises, mount } from "@vue/test-utils";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import type { Platform } from "@/stores/platforms";
|
||||
import SettingsTab from "./SettingsTab.vue";
|
||||
|
||||
@@ -81,10 +81,6 @@ function mountTab(p: Platform) {
|
||||
}
|
||||
|
||||
describe("SettingsTab platform save", () => {
|
||||
beforeEach(() => {
|
||||
updatePlatform.mockClear();
|
||||
});
|
||||
|
||||
it("does not stamp custom_name when only the description changed", async () => {
|
||||
updatePlatform.mockResolvedValue({ data: platform() });
|
||||
const p = platform();
|
||||
|
||||
@@ -7,9 +7,7 @@ import GameActionBtn from "./GameActionBtn.vue";
|
||||
const play = vi.fn();
|
||||
const needsLaunchConfirm = { value: false };
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
vi.mock("vue-i18n");
|
||||
|
||||
vi.mock("@/v2/composables/useBreakpoint", () => ({
|
||||
useBreakpoint: () => ({ smAndDown: ref(false) }),
|
||||
@@ -56,7 +54,6 @@ function click(el: Element, init: MouseEventInit = {}): boolean {
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
play.mockClear();
|
||||
needsLaunchConfirm.value = false;
|
||||
});
|
||||
|
||||
|
||||
@@ -3,9 +3,7 @@ import { describe, expect, it, vi } from "vitest";
|
||||
import type { SimpleRom } from "@/stores/roms";
|
||||
import GameActionsList from "./GameActionsList.vue";
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
vi.mock("vue-i18n");
|
||||
|
||||
type Flags = {
|
||||
canPlayLocally: boolean;
|
||||
|
||||
@@ -5,9 +5,7 @@ import type { SimpleRom } from "@/stores/roms";
|
||||
import storeGallerySelection from "@/v2/stores/gallerySelection";
|
||||
import GameCard from "./GameCard.vue";
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
vi.mock("vue-i18n");
|
||||
|
||||
function rom(id: number): SimpleRom {
|
||||
return { id, name: `Game ${id}`, platform_slug: "snes" } as SimpleRom;
|
||||
|
||||
@@ -2,9 +2,7 @@ import { mount } from "@vue/test-utils";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import AssetEditDialog from "./AssetEditDialog.vue";
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
vi.mock("vue-i18n");
|
||||
vi.mock("@/locales", () => ({
|
||||
default: { global: { t: (key: string) => key } },
|
||||
}));
|
||||
|
||||
@@ -26,9 +26,7 @@ const {
|
||||
grants: { upload: true, delete: false },
|
||||
}));
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
vi.mock("vue-i18n");
|
||||
vi.mock("vue-router", async (importOriginal) => ({
|
||||
...(await importOriginal<typeof import("vue-router")>()),
|
||||
useRoute: () => ({ query: routeQuery, path: "/rom/1", params: {} }),
|
||||
@@ -141,7 +139,6 @@ async function pickFile(wrapper: ReturnType<typeof mountTab>, name: string) {
|
||||
|
||||
describe("FilesTab uploads", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
routeQuery.subtab = undefined;
|
||||
grants.upload = true;
|
||||
uploadRoms.mockResolvedValue([{ status: "fulfilled", value: null }]);
|
||||
@@ -250,7 +247,6 @@ describe("FilesTab uploads", () => {
|
||||
|
||||
describe("FilesTab on a rom missing from the filesystem", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
routeQuery.subtab = undefined;
|
||||
grants.upload = true;
|
||||
});
|
||||
@@ -283,7 +279,6 @@ describe("FilesTab on a rom missing from the filesystem", () => {
|
||||
|
||||
describe("FilesTab selection", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
routeQuery.subtab = undefined;
|
||||
grants.upload = true;
|
||||
});
|
||||
@@ -329,10 +324,7 @@ describe("FilesTab copy link", () => {
|
||||
writeText: ((text: string) => Promise<void>) | null,
|
||||
secure = true,
|
||||
) {
|
||||
Object.defineProperty(window, "isSecureContext", {
|
||||
configurable: true,
|
||||
value: secure,
|
||||
});
|
||||
vi.stubGlobal("isSecureContext", secure);
|
||||
Object.defineProperty(navigator, "clipboard", {
|
||||
configurable: true,
|
||||
value: writeText ? { writeText } : undefined,
|
||||
|
||||
@@ -3,9 +3,7 @@ import { describe, expect, it, vi } from "vitest";
|
||||
import { nextTick } from "vue";
|
||||
import UploadFilesDialog from "./UploadFilesDialog.vue";
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
vi.mock("vue-i18n");
|
||||
vi.mock("@/locales", () => ({
|
||||
default: { global: { t: (key: string) => key } },
|
||||
}));
|
||||
|
||||
@@ -9,9 +9,7 @@ const { showLogoTitle, xs } = vi.hoisted(() => ({
|
||||
xs: { value: false },
|
||||
}));
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
vi.mock("vue-i18n");
|
||||
|
||||
vi.mock("@/composables/useUISettings", () => ({
|
||||
useUISettings: () => ({ showLogoTitle }),
|
||||
|
||||
@@ -5,9 +5,7 @@ import { createMemoryHistory, createRouter, type Router } from "vue-router";
|
||||
import { makeDetailedRom } from "@/utils/rom.fixtures";
|
||||
import MediaTab from "./MediaTab.vue";
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
vi.mock("vue-i18n");
|
||||
vi.mock("@/v2/composables/useRomSync", () => ({
|
||||
useRomSync: () => ({ refetchRom: vi.fn() }),
|
||||
}));
|
||||
|
||||
@@ -3,9 +3,7 @@ import { describe, expect, it, vi } from "vitest";
|
||||
import type { DetailedRom } from "@/stores/roms";
|
||||
import MetadataTab from "./MetadataTab.vue";
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
vi.mock("vue-i18n");
|
||||
|
||||
const CRC = "aabbccdd";
|
||||
const MD5 = "0123456789abcdef0123456789abcdef";
|
||||
|
||||
@@ -6,9 +6,7 @@ import type { DetailedRom } from "@/stores/roms";
|
||||
import type { MediaShelfItem } from "./MediaShelf.vue";
|
||||
import OverviewTab from "./OverviewTab.vue";
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
vi.mock("vue-i18n");
|
||||
|
||||
const showRecommendations = ref(true);
|
||||
|
||||
|
||||
@@ -5,9 +5,7 @@ import PatcherTab from "./PatcherTab.vue";
|
||||
|
||||
const { post } = vi.hoisted(() => ({ post: vi.fn() }));
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
vi.mock("vue-i18n");
|
||||
vi.mock("pinia", async (importOriginal) => ({
|
||||
...(await importOriginal<typeof import("pinia")>()),
|
||||
storeToRefs: (store: object) => store,
|
||||
@@ -103,7 +101,6 @@ function rom(): DetailedRomSchema {
|
||||
|
||||
describe("PatcherTab", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
post.mockResolvedValue({ data: new Blob(["patched"]), headers: {} });
|
||||
vi.spyOn(HTMLAnchorElement.prototype, "click").mockImplementation(() => {});
|
||||
});
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
import { mount } from "@vue/test-utils";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { nextTick, ref } from "vue";
|
||||
import PdfViewer from "./PdfViewer.vue";
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
vi.mock("vue-i18n");
|
||||
vi.mock("vue3-pdf-app", () => ({
|
||||
default: { name: "VuePdfApp", template: `<div class="pdf-app-stub" />` },
|
||||
}));
|
||||
@@ -36,10 +34,6 @@ beforeEach(() => {
|
||||
);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.unstubAllGlobals();
|
||||
});
|
||||
|
||||
describe("PdfViewer", () => {
|
||||
it("waits for a laid-out container before loading pdf.js", async () => {
|
||||
const wrapper = mount(PdfViewer, {
|
||||
|
||||
@@ -8,9 +8,7 @@ const { gallery, fromGallery } = vi.hoisted(() => ({
|
||||
fromGallery: { value: true },
|
||||
}));
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
vi.mock("vue-i18n");
|
||||
|
||||
vi.mock("vue-router", async (importOriginal) => ({
|
||||
...(await importOriginal<typeof import("vue-router")>()),
|
||||
|
||||
@@ -5,9 +5,7 @@ import storeAuth from "@/stores/auth";
|
||||
import type { User } from "@/stores/users";
|
||||
import SaveDataTab from "./SaveDataTab.vue";
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
vi.mock("vue-i18n");
|
||||
vi.mock("vue-router", async (importOriginal) => ({
|
||||
...(await importOriginal<typeof import("vue-router")>()),
|
||||
useRoute: () => ({ query: {}, path: "/rom/1", params: {} }),
|
||||
|
||||
@@ -2,9 +2,7 @@ import { mount } from "@vue/test-utils";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import ScreenshotEditDialog from "./ScreenshotEditDialog.vue";
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
vi.mock("vue-i18n");
|
||||
|
||||
const RDialog = {
|
||||
props: { modelValue: { type: Boolean, default: false } },
|
||||
|
||||
@@ -2,9 +2,7 @@ import { mount } from "@vue/test-utils";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import SubtabNav, { type SubtabNavItem } from "./SubtabNav.vue";
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
vi.mock("vue-i18n");
|
||||
|
||||
const RMenu = {
|
||||
props: { searchable: { type: Boolean, default: false } },
|
||||
|
||||
@@ -5,9 +5,7 @@ import UploadAssetDialog, {
|
||||
type UploadAssetPayload,
|
||||
} from "./UploadAssetDialog.vue";
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
vi.mock("vue-i18n");
|
||||
vi.mock("@/locales", () => ({
|
||||
default: { global: { t: (key: string) => key } },
|
||||
}));
|
||||
|
||||
@@ -101,7 +101,6 @@ function loadingOf(wrapper: ReturnType<typeof mountWidget>) {
|
||||
|
||||
describe("AnniversaryWidget", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
// 8 September 2026, local time, so the request is asserted against a
|
||||
// known calendar day rather than whenever the suite happens to run.
|
||||
vi.useFakeTimers();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* eslint-disable vue/one-component-per-file */
|
||||
import { flushPromises, mount } from "@vue/test-utils";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { defineComponent } from "vue";
|
||||
import type { SimpleRom } from "@/stores/roms";
|
||||
import RandomPickWidget from "./RandomPickWidget.vue";
|
||||
@@ -10,9 +10,7 @@ const { getRandomRom, snackbarError } = vi.hoisted(() => ({
|
||||
snackbarError: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
vi.mock("vue-i18n");
|
||||
|
||||
vi.mock("@/plugins/router", () => ({
|
||||
ROUTES: { ROM: "rom" },
|
||||
@@ -70,10 +68,6 @@ function mountWidget() {
|
||||
}
|
||||
|
||||
describe("RandomPickWidget", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it("resolves a pick with a single request", async () => {
|
||||
// Issue #4066: the pick used to cost a count request plus a fetch at a
|
||||
// random offset, which got slower the bigger the library was.
|
||||
|
||||
@@ -3,9 +3,7 @@ import { describe, expect, it, vi } from "vitest";
|
||||
import { makeRom } from "@/utils/rom.fixtures";
|
||||
import MatchRomRenameToggle from "./MatchRomRenameToggle.vue";
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
vi.mock("vue-i18n");
|
||||
|
||||
const rom = makeRom({
|
||||
fs_name: "Zelda (USA).gba",
|
||||
|
||||
@@ -21,9 +21,7 @@ const snackbar = vi.hoisted(() => ({
|
||||
const confirmDialog = vi.hoisted(() => vi.fn());
|
||||
|
||||
vi.mock("@/services/api/notificationChannel", () => ({ default: api }));
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
vi.mock("vue-i18n");
|
||||
vi.mock("@/v2/composables/useSnackbar", async (importOriginal) => ({
|
||||
...(await importOriginal<typeof import("@/v2/composables/useSnackbar")>()),
|
||||
useSnackbar: () => snackbar,
|
||||
|
||||
@@ -19,9 +19,7 @@ const { api, confirm } = vi.hoisted(() => ({
|
||||
|
||||
vi.mock("@/services/api/notification", () => ({ default: api }));
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
vi.mock("vue-i18n");
|
||||
|
||||
vi.mock("@/v2/utils/notifications", () => ({
|
||||
describeNotification: (n: NotificationSchema) => ({
|
||||
|
||||
@@ -11,9 +11,7 @@ const { create, fetchUsers, success } = vi.hoisted(() => ({
|
||||
vi.mock("@/services/api/notification", () => ({ default: { create } }));
|
||||
vi.mock("@/services/api/user", () => ({ default: { fetchUsers } }));
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
vi.mock("vue-i18n");
|
||||
|
||||
vi.mock("@/v2/composables/useSnackbar", async (importOriginal) => ({
|
||||
...(await importOriginal<typeof import("@/v2/composables/useSnackbar")>()),
|
||||
|
||||
@@ -3,9 +3,7 @@ import { describe, expect, it, vi } from "vitest";
|
||||
import { stateFixture } from "@/utils/assets.fixtures";
|
||||
import AssetPreview from "./AssetPreview.vue";
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
vi.mock("vue-i18n");
|
||||
vi.mock("@/stores/streaming", () => import("@/test-utils/streamingStore"));
|
||||
|
||||
const RTag = {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { flushPromises, mount } from "@vue/test-utils";
|
||||
import mitt, { type Emitter } from "mitt";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import type { SaveSchema, StateSchema } from "@/__generated__";
|
||||
import type { DetailedRom } from "@/stores/roms";
|
||||
import type { Events } from "@/types/emitter";
|
||||
@@ -11,9 +11,7 @@ const { confirm } = vi.hoisted(() => ({
|
||||
confirm: vi.fn(async (_opts: { title: string }) => true),
|
||||
}));
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
vi.mock("vue-i18n");
|
||||
vi.mock("@/stores/streaming", () => import("@/test-utils/streamingStore"));
|
||||
vi.mock("@/v2/composables/useConfirm", () => ({
|
||||
useConfirm: () => confirm,
|
||||
@@ -86,10 +84,6 @@ function openDialog() {
|
||||
}
|
||||
|
||||
describe("LoadSaveStateDialog", () => {
|
||||
beforeEach(() => {
|
||||
confirm.mockClear();
|
||||
});
|
||||
|
||||
it("opens on States and loads a state once confirmed", async () => {
|
||||
const { wrapper, open, stateSelected, saveSelected } = openDialog();
|
||||
await open();
|
||||
|
||||
@@ -2,9 +2,7 @@ import { mount } from "@vue/test-utils";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import MemoryCardDialog from "./MemoryCardDialog.vue";
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
vi.mock("vue-i18n");
|
||||
vi.mock("@/locales", () => ({
|
||||
default: { global: { t: (key: string) => key } },
|
||||
}));
|
||||
|
||||
@@ -4,9 +4,7 @@ import type { MemoryCardSchema } from "@/__generated__";
|
||||
import memoryCardApi from "@/services/api/memory-card";
|
||||
import MemoryCardManager from "./MemoryCardManager.vue";
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
vi.mock("vue-i18n");
|
||||
vi.mock("@/services/api/memory-card", () => ({
|
||||
default: {
|
||||
getMemoryCards: vi.fn(),
|
||||
@@ -58,7 +56,6 @@ async function openEdit() {
|
||||
|
||||
describe("MemoryCardManager edit", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
vi.mocked(memoryCardApi.getMemoryCards).mockResolvedValue({
|
||||
data: [card],
|
||||
} as never);
|
||||
|
||||
@@ -6,9 +6,7 @@ import PlayerShell from "./PlayerShell.vue";
|
||||
|
||||
const mocks = vi.hoisted(() => ({ setStageActive: vi.fn() }));
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
vi.mock("vue-i18n");
|
||||
|
||||
vi.mock("@/stores/playing", () => ({
|
||||
default: () => ({ setStageActive: mocks.setStageActive }),
|
||||
|
||||
@@ -2,9 +2,7 @@ import { mount } from "@vue/test-utils";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import SessionEndedReason from "./SessionEndedReason.vue";
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
vi.mock("vue-i18n");
|
||||
|
||||
describe("SessionEndedReason", () => {
|
||||
it("shows the reason under its label", () => {
|
||||
|
||||
@@ -3,9 +3,7 @@ import { describe, expect, it, vi } from "vitest";
|
||||
import type { ScanningPlatform } from "@/stores/scanning";
|
||||
import ScanPlatform from "./ScanPlatform.vue";
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
vi.mock("vue-i18n");
|
||||
|
||||
function mountPlatform(overrides: Partial<ScanningPlatform> = {}) {
|
||||
const platform: ScanningPlatform = {
|
||||
|
||||
@@ -3,9 +3,7 @@ import { describe, expect, it, vi } from "vitest";
|
||||
import { makeRom } from "@/utils/rom.fixtures";
|
||||
import ScanPlatformRow from "./ScanPlatformRow.vue";
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
vi.mock("vue-i18n");
|
||||
vi.mock("@/v2/composables/useWebpSupport", () => ({
|
||||
useWebpSupport: () => ({ toWebp: (src: string) => src }),
|
||||
}));
|
||||
|
||||
@@ -3,9 +3,7 @@ import { describe, expect, it, vi } from "vitest";
|
||||
import type { MetadataOption } from "@/stores/heartbeat";
|
||||
import ScanProviderSelect from "./ScanProviderSelect.vue";
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
vi.mock("vue-i18n");
|
||||
|
||||
const provider = (value: string, name: string): MetadataOption => ({
|
||||
value,
|
||||
|
||||
@@ -34,9 +34,7 @@ vi.mock("@/services/api/config", () => ({
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
vi.mock("vue-i18n");
|
||||
|
||||
vi.mock("@/v2/composables/useSnackbar", () => ({
|
||||
useSnackbar: () => ({ success: vi.fn(), error: vi.fn() }),
|
||||
|
||||
@@ -6,9 +6,7 @@ import HiddenGamesPicker from "./HiddenGamesPicker.vue";
|
||||
|
||||
const { getRoms } = vi.hoisted(() => ({ getRoms: vi.fn() }));
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
vi.mock("vue-i18n");
|
||||
|
||||
vi.mock("@v2/lib", () => {
|
||||
const stub = defineComponent({ template: "<span><slot /></span>" });
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { mount } from "@vue/test-utils";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { createI18n } from "vue-i18n";
|
||||
import type { MetadataCoverageItem } from "@/__generated__/models/MetadataCoverageItem";
|
||||
import type { RegionBreakdownItem } from "@/__generated__/models/RegionBreakdownItem";
|
||||
@@ -170,10 +170,6 @@ function duplicateSlugLibrary(): Platform[] {
|
||||
}
|
||||
|
||||
describe("PlatformsStatsSection", () => {
|
||||
beforeEach(() => {
|
||||
push.mockClear();
|
||||
});
|
||||
|
||||
it("links each row to its platform gallery", async () => {
|
||||
const wrapper = mountSection(duplicateSlugLibrary());
|
||||
|
||||
|
||||
@@ -4,9 +4,7 @@ import ScanPriorityList from "./ScanPriorityList.vue";
|
||||
|
||||
// vue-i18n's `t` is stubbed to echo the key so the component mounts without
|
||||
// the full i18n plugin.
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
vi.mock("vue-i18n");
|
||||
|
||||
const SOURCES = [
|
||||
{ value: "igdb", label: "IGDB" },
|
||||
|
||||
@@ -4,9 +4,7 @@ import type { SaveSchema } from "@/__generated__";
|
||||
import { saveFixture } from "@/utils/assets.fixtures";
|
||||
import AssetActions from "./AssetActions.vue";
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
vi.mock("vue-i18n");
|
||||
|
||||
const RBtn = {
|
||||
props: { ariaLabel: { type: String, default: "" } },
|
||||
|
||||
@@ -4,9 +4,7 @@ import type { SaveSchema } from "@/__generated__";
|
||||
import { saveFixture } from "@/utils/assets.fixtures";
|
||||
import AssetChips from "./AssetChips.vue";
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
vi.mock("vue-i18n");
|
||||
vi.mock("@/stores/streaming", () => import("@/test-utils/streamingStore"));
|
||||
|
||||
const RTag = {
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
import { flushPromises, mount, type VueWrapper } from "@vue/test-utils";
|
||||
import mitt, { type Emitter } from "mitt";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import type { Events } from "@/types/emitter";
|
||||
import ConfirmDialog from "./ConfirmDialog.vue";
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
vi.mock("vue-i18n");
|
||||
|
||||
const RBtnStub = {
|
||||
props: { disabled: { type: Boolean, default: false } },
|
||||
@@ -53,10 +51,6 @@ function confirmButton(wrapper: VueWrapper) {
|
||||
}
|
||||
|
||||
describe("ConfirmDialog typed confirmation", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it("keeps the action disabled until the phrase is typed", async () => {
|
||||
const wrapper = await promptFor("Philips Videopac+");
|
||||
expect(confirmButton(wrapper).attributes("disabled")).toBeDefined();
|
||||
|
||||
@@ -4,9 +4,7 @@ import LocationChip from "./LocationChip.vue";
|
||||
|
||||
const { copy } = vi.hoisted(() => ({ copy: vi.fn() }));
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
vi.mock("vue-i18n");
|
||||
|
||||
vi.mock("@/v2/composables/useClipboard", () => ({
|
||||
useClipboard: () => ({ isSupported: true, copy }),
|
||||
|
||||
@@ -2,9 +2,7 @@ import { mount } from "@vue/test-utils";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import VisibilitySwitch from "./VisibilitySwitch.vue";
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
vi.mock("vue-i18n");
|
||||
|
||||
describe("VisibilitySwitch", () => {
|
||||
it("keeps both labels in place and shows the one it is on", async () => {
|
||||
|
||||
@@ -8,9 +8,7 @@ import {
|
||||
promotePlatformsWithGamesFirst,
|
||||
} from "./platformSelect";
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
vi.mock("vue-i18n");
|
||||
|
||||
type Row = Pick<Platform, "rom_count" | "display_name">;
|
||||
|
||||
|
||||
@@ -65,12 +65,6 @@ beforeEach(() => {
|
||||
support.pico8Rom.mockReturnValue(false);
|
||||
support.ruffle.mockReturnValue(false);
|
||||
support.jsDosBundle.mockReturnValue(true);
|
||||
support.ejs.mockClear();
|
||||
support.jsDos.mockClear();
|
||||
support.pico8.mockClear();
|
||||
support.pico8Rom.mockClear();
|
||||
support.ruffle.mockClear();
|
||||
support.jsDosBundle.mockClear();
|
||||
streamContainer.value = null;
|
||||
nativeSupported.value = false;
|
||||
});
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { useClipboard } from "./index";
|
||||
|
||||
const success = vi.fn();
|
||||
@@ -16,10 +16,7 @@ vi.mock("@/v2/composables/useSnackbar", () => ({
|
||||
}));
|
||||
|
||||
function setSecureContext(value: boolean) {
|
||||
Object.defineProperty(window, "isSecureContext", {
|
||||
configurable: true,
|
||||
value,
|
||||
});
|
||||
vi.stubGlobal("isSecureContext", value);
|
||||
}
|
||||
|
||||
function setClipboard(writeText: ((text: string) => Promise<void>) | null) {
|
||||
@@ -29,11 +26,6 @@ function setClipboard(writeText: ((text: string) => Promise<void>) | null) {
|
||||
});
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
success.mockClear();
|
||||
error.mockClear();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
setClipboard(null);
|
||||
});
|
||||
|
||||
@@ -3,9 +3,7 @@ import { nextTick, ref } from "vue";
|
||||
import type { CoverResource, SearchCoverSchema } from "@/__generated__";
|
||||
import { useCoverFilters } from "./index";
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
vi.mock("vue-i18n");
|
||||
|
||||
function resource(overrides: Partial<CoverResource> = {}): CoverResource {
|
||||
return {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { flushPromises } from "@vue/test-utils";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import type { SimpleRom } from "@/stores/roms";
|
||||
import { useGallerySelectAll } from "@/v2/composables/useGallerySelectAll";
|
||||
import storeGalleryRoms from "@/v2/stores/galleryRoms";
|
||||
@@ -23,9 +23,7 @@ vi.mock("@/v2/composables/useSnackbar", () => ({
|
||||
}),
|
||||
}));
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
vi.mock("vue-i18n");
|
||||
|
||||
function rom(id: number): SimpleRom {
|
||||
return { id, name: `Game ${id}`, platform_id: 1 } as SimpleRom;
|
||||
@@ -60,15 +58,6 @@ function setupGallery({
|
||||
}
|
||||
|
||||
describe("useGallerySelectAll", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
// Un-stub the console.error spy from the failure-path test.
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
it("selects the whole filtered result, not just the loaded windows", async () => {
|
||||
setupGallery({ ids: [1, 2, 3, 4], loaded: [rom(1), rom(2)] });
|
||||
const selection = storeGallerySelection();
|
||||
|
||||
@@ -32,9 +32,7 @@ vi.mock("vue", async (importOriginal) => ({
|
||||
...(await importOriginal<typeof import("vue")>()),
|
||||
inject: () => ({ emit: emitterEmit }),
|
||||
}));
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
vi.mock("vue-i18n");
|
||||
vi.mock("vue-router", () => ({
|
||||
useRouter: () => ({ push }),
|
||||
}));
|
||||
@@ -163,11 +161,6 @@ function makeRom(status: SimpleRom["rom_user"]["status"] = null): SimpleRom {
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
push.mockClear();
|
||||
confirmFn.mockClear();
|
||||
startScan.mockClear();
|
||||
snackbarInfo.mockClear();
|
||||
snackbarError.mockClear();
|
||||
probeFormatDownload.mockReset();
|
||||
downloadRom.mockReset();
|
||||
clipboardCopy.mockReset();
|
||||
|
||||
@@ -101,8 +101,6 @@ describe("useGamepad", () => {
|
||||
window.removeEventListener("keydown", onKeydown);
|
||||
wrapper?.unmount();
|
||||
wrapper = null;
|
||||
vi.unstubAllGlobals();
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
it("steers with the left stick", () => {
|
||||
|
||||
@@ -42,7 +42,6 @@ function press(key: string, target: EventTarget = document.body) {
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
push.mockClear();
|
||||
playingStore.playing = false;
|
||||
document.body.innerHTML = "";
|
||||
});
|
||||
|
||||
@@ -1,12 +1,4 @@
|
||||
import {
|
||||
afterAll,
|
||||
beforeAll,
|
||||
beforeEach,
|
||||
describe,
|
||||
expect,
|
||||
it,
|
||||
vi,
|
||||
} from "vitest";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { useIsolatedLaunch } from "./index";
|
||||
|
||||
interface Intent {
|
||||
@@ -24,17 +16,16 @@ function isIntent(value: unknown): value is Intent {
|
||||
|
||||
const KEY = "player:7:ejs:launch";
|
||||
const reload = vi.fn();
|
||||
let originalLocation: Location;
|
||||
const realStorage = window.sessionStorage;
|
||||
|
||||
/** Stand in for a browser that denies storage access outright. */
|
||||
function blockStorage() {
|
||||
const denied = () => {
|
||||
throw new Error("storage is blocked");
|
||||
};
|
||||
Object.defineProperty(window, "sessionStorage", {
|
||||
configurable: true,
|
||||
value: { getItem: denied, setItem: denied, removeItem: denied },
|
||||
vi.stubGlobal("sessionStorage", {
|
||||
getItem: denied,
|
||||
setItem: denied,
|
||||
removeItem: denied,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -43,33 +34,11 @@ function launch() {
|
||||
}
|
||||
|
||||
function setSecureContext(secure: boolean) {
|
||||
Object.defineProperty(window, "isSecureContext", {
|
||||
configurable: true,
|
||||
value: secure,
|
||||
});
|
||||
vi.stubGlobal("isSecureContext", secure);
|
||||
}
|
||||
|
||||
beforeAll(() => {
|
||||
originalLocation = window.location;
|
||||
Object.defineProperty(window, "location", {
|
||||
configurable: true,
|
||||
value: { ...originalLocation, reload },
|
||||
});
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
Object.defineProperty(window, "location", {
|
||||
configurable: true,
|
||||
value: originalLocation,
|
||||
});
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
reload.mockClear();
|
||||
Object.defineProperty(window, "sessionStorage", {
|
||||
configurable: true,
|
||||
value: realStorage,
|
||||
});
|
||||
vi.stubGlobal("location", { ...window.location, reload });
|
||||
sessionStorage.clear();
|
||||
setSecureContext(true);
|
||||
});
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { useJoinStreamConfirm } from "./index";
|
||||
|
||||
const push = vi.fn();
|
||||
const confirmFn = vi.fn();
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
vi.mock("vue-i18n");
|
||||
vi.mock("vue-router", () => ({
|
||||
useRouter: () => ({ push }),
|
||||
}));
|
||||
@@ -22,11 +20,6 @@ const target = {
|
||||
};
|
||||
|
||||
describe("useJoinStreamConfirm", () => {
|
||||
beforeEach(() => {
|
||||
push.mockClear();
|
||||
confirmFn.mockClear();
|
||||
});
|
||||
|
||||
it("does not navigate until the user confirms", async () => {
|
||||
confirmFn.mockResolvedValue(false);
|
||||
const { joinStream } = useJoinStreamConfirm();
|
||||
|
||||
@@ -95,7 +95,6 @@ describe("useMediaSession", () => {
|
||||
afterEach(() => {
|
||||
scope.stop();
|
||||
Reflect.deleteProperty(navigator, "mediaSession");
|
||||
vi.unstubAllGlobals();
|
||||
});
|
||||
|
||||
function start(blocked?: () => boolean) {
|
||||
|
||||
@@ -54,22 +54,13 @@ function feedback() {
|
||||
describe("installNativeLaunchFeedback", () => {
|
||||
beforeEach(() => {
|
||||
emit = null;
|
||||
install.mockClear();
|
||||
nameFor.mockClear();
|
||||
nameFor.mockImplementation(() => "Chrono Trigger");
|
||||
consumeCancelled.mockClear();
|
||||
success.mockClear();
|
||||
error.mockClear();
|
||||
warning.mockClear();
|
||||
info.mockClear();
|
||||
t.mockClear();
|
||||
vi.spyOn(console, "error").mockImplementation(() => {});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
wrapper?.unmount();
|
||||
wrapper = null;
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
it("subscribes on install", () => {
|
||||
|
||||
@@ -53,9 +53,7 @@ vi.mock("@/v2/composables/useSnackbar", () => ({
|
||||
}),
|
||||
}));
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
vi.mock("vue-i18n");
|
||||
|
||||
const refetchRom = vi.fn(async () => null);
|
||||
vi.mock("@/v2/composables/useRomSync", () => ({
|
||||
@@ -95,16 +93,11 @@ describe("installPendingAssetSync", () => {
|
||||
isOffline.value = false;
|
||||
syncPendingAssets.mockReset();
|
||||
syncPendingAssets.mockImplementation(acceptAll);
|
||||
refetchRom.mockClear();
|
||||
success.mockClear();
|
||||
error.mockClear();
|
||||
warning.mockClear();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
wrapper?.unmount();
|
||||
wrapper = null;
|
||||
vi.unstubAllGlobals();
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { flushPromises } from "@vue/test-utils";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { reactive, shallowRef } from "vue";
|
||||
import type { RomUserSchema } from "@/__generated__";
|
||||
@@ -5,9 +6,7 @@ import romApi from "@/services/api/rom";
|
||||
import type { DetailedRom } from "@/stores/roms";
|
||||
import { usePinnedMedia } from "./index";
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
vi.mock("vue-i18n");
|
||||
|
||||
vi.mock("@/services/api/rom", () => ({
|
||||
default: { updateUserRomProps: vi.fn() },
|
||||
@@ -45,10 +44,6 @@ function makeRom(pinnedMedia: string[] | null): DetailedRom {
|
||||
}) as DetailedRom;
|
||||
}
|
||||
|
||||
async function settle() {
|
||||
await new Promise((resolve) => setTimeout(resolve));
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
update.mockReset();
|
||||
snackbarError.mockReset();
|
||||
@@ -66,7 +61,7 @@ describe("usePinnedMedia", () => {
|
||||
togglePin("file:2");
|
||||
expect(rom.rom_user.pinned_media).toEqual(["file:1", "file:2"]);
|
||||
expect(isCustomized.value).toBe(true);
|
||||
await settle();
|
||||
await flushPromises();
|
||||
expect(update).toHaveBeenCalledWith({
|
||||
romId: rom.id,
|
||||
data: { pinned_media: ["file:1", "file:2"] },
|
||||
@@ -84,17 +79,17 @@ describe("usePinnedMedia", () => {
|
||||
|
||||
screenshots.togglePin("file:1");
|
||||
artwork.togglePin("file:2");
|
||||
await settle();
|
||||
await flushPromises();
|
||||
expect(update).toHaveBeenCalledTimes(1);
|
||||
|
||||
releases[0]();
|
||||
await settle();
|
||||
await flushPromises();
|
||||
expect(update).toHaveBeenCalledTimes(2);
|
||||
expect(update.mock.calls[1][0].data).toEqual({
|
||||
pinned_media: ["file:1", "file:2"],
|
||||
});
|
||||
releases[1]();
|
||||
await settle();
|
||||
await flushPromises();
|
||||
});
|
||||
|
||||
it("restores the previous pins and reports a failed write", async () => {
|
||||
@@ -104,7 +99,7 @@ describe("usePinnedMedia", () => {
|
||||
|
||||
togglePin("file:1");
|
||||
expect(rom.rom_user.pinned_media).toEqual([]);
|
||||
await settle();
|
||||
await flushPromises();
|
||||
expect(rom.rom_user.pinned_media).toEqual(["file:1"]);
|
||||
expect(snackbarError).toHaveBeenCalledWith(
|
||||
"rom.pinned-media-update-failed",
|
||||
@@ -121,7 +116,7 @@ describe("usePinnedMedia", () => {
|
||||
|
||||
togglePin("file:1");
|
||||
togglePin("file:2");
|
||||
await settle();
|
||||
await flushPromises();
|
||||
expect(rom.rom_user.pinned_media).toEqual(["file:1", "file:2"]);
|
||||
expect(snackbarError).toHaveBeenCalledOnce();
|
||||
});
|
||||
@@ -133,7 +128,7 @@ describe("usePinnedMedia", () => {
|
||||
|
||||
togglePin("file:1");
|
||||
togglePin("file:2");
|
||||
await settle();
|
||||
await flushPromises();
|
||||
expect(rom.rom_user.pinned_media).toEqual(["file:9"]);
|
||||
});
|
||||
|
||||
@@ -149,7 +144,7 @@ describe("usePinnedMedia", () => {
|
||||
rom_user: { pinned_media: [] as string[] } as RomUserSchema,
|
||||
}) as DetailedRom;
|
||||
current.value = refetched;
|
||||
await settle();
|
||||
await flushPromises();
|
||||
expect(refetched.rom_user.pinned_media).toEqual(["file:1"]);
|
||||
});
|
||||
|
||||
@@ -158,7 +153,7 @@ describe("usePinnedMedia", () => {
|
||||
const { togglePin } = usePinnedMedia(rom);
|
||||
|
||||
togglePin("file:4");
|
||||
await settle();
|
||||
await flushPromises();
|
||||
expect(rom.rom_user.pinned_media).toEqual(["file:1", "file:2", "file:3"]);
|
||||
expect(update).not.toHaveBeenCalled();
|
||||
expect(snackbarError).toHaveBeenCalledWith(
|
||||
@@ -182,7 +177,7 @@ describe("usePinnedMedia", () => {
|
||||
|
||||
resetPins();
|
||||
expect(rom.rom_user.pinned_media).toBeNull();
|
||||
await settle();
|
||||
await flushPromises();
|
||||
expect(update).toHaveBeenCalledWith({
|
||||
romId: rom.id,
|
||||
data: { pinned_media: null },
|
||||
|
||||
@@ -1,50 +1,22 @@
|
||||
import { flushPromises } from "@vue/test-utils";
|
||||
import {
|
||||
afterAll,
|
||||
afterEach,
|
||||
beforeAll,
|
||||
describe,
|
||||
expect,
|
||||
it,
|
||||
vi,
|
||||
} from "vitest";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { installFullscreenFallback } from "@/v2/utils/playerFullscreen";
|
||||
import { usePlayerExit } from "./index";
|
||||
|
||||
const replace = vi.fn();
|
||||
const locationReplace = vi.fn();
|
||||
let originalLocation: Location;
|
||||
|
||||
vi.mock("vue-router", () => ({
|
||||
useRouter: () => ({ replace }),
|
||||
}));
|
||||
|
||||
function setIsolated(isolated: boolean) {
|
||||
Object.defineProperty(window, "crossOriginIsolated", {
|
||||
configurable: true,
|
||||
value: isolated,
|
||||
});
|
||||
vi.stubGlobal("crossOriginIsolated", isolated);
|
||||
}
|
||||
|
||||
beforeAll(() => {
|
||||
originalLocation = window.location;
|
||||
Object.defineProperty(window, "location", {
|
||||
configurable: true,
|
||||
value: { ...originalLocation, replace: locationReplace },
|
||||
});
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
Object.defineProperty(window, "location", {
|
||||
configurable: true,
|
||||
value: originalLocation,
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
replace.mockClear();
|
||||
beforeEach(() => {
|
||||
vi.stubGlobal("location", { ...window.location, replace: locationReplace });
|
||||
locationReplace.mockReset();
|
||||
setIsolated(false);
|
||||
});
|
||||
|
||||
describe("usePlayerExit", () => {
|
||||
@@ -150,9 +122,7 @@ describe("usePlayerExit", () => {
|
||||
|
||||
it("replaces the document even when settling fails", async () => {
|
||||
setIsolated(true);
|
||||
const error = vi
|
||||
.spyOn(console, "error")
|
||||
.mockImplementation(() => undefined);
|
||||
vi.spyOn(console, "error").mockImplementation(() => undefined);
|
||||
const exit = usePlayerExit(
|
||||
() => false,
|
||||
() => Promise.reject(new Error("nope")),
|
||||
@@ -162,7 +132,6 @@ describe("usePlayerExit", () => {
|
||||
await flushPromises();
|
||||
|
||||
expect(locationReplace).toHaveBeenCalledWith("/platform/2");
|
||||
error.mockRestore();
|
||||
});
|
||||
|
||||
// The view arms an unload prompt while a game is up, and the exit it asked
|
||||
|
||||
@@ -49,7 +49,6 @@ describe("usePlayerFullscreen", () => {
|
||||
await expect(value.exit()).resolves.toBeUndefined();
|
||||
|
||||
expect(error).toHaveBeenCalledOnce();
|
||||
error.mockRestore();
|
||||
});
|
||||
|
||||
it("swallows a denied request instead of rejecting", async () => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { nextTick } from "vue";
|
||||
|
||||
const KEY = "settings.v2.reducedMotion";
|
||||
@@ -23,16 +23,19 @@ let store: Storage;
|
||||
|
||||
// Force the OS `prefers-reduced-motion` result the next fresh import will read.
|
||||
function stubReducedMotion(matches: boolean) {
|
||||
window.matchMedia = vi.fn().mockImplementation((query: string) => ({
|
||||
matches,
|
||||
media: query,
|
||||
onchange: null,
|
||||
addEventListener: vi.fn(),
|
||||
removeEventListener: vi.fn(),
|
||||
addListener: vi.fn(),
|
||||
removeListener: vi.fn(),
|
||||
dispatchEvent: vi.fn(),
|
||||
}));
|
||||
vi.stubGlobal(
|
||||
"matchMedia",
|
||||
vi.fn().mockImplementation((query: string) => ({
|
||||
matches,
|
||||
media: query,
|
||||
onchange: null,
|
||||
addEventListener: vi.fn(),
|
||||
removeEventListener: vi.fn(),
|
||||
addListener: vi.fn(),
|
||||
removeListener: vi.fn(),
|
||||
dispatchEvent: vi.fn(),
|
||||
})),
|
||||
);
|
||||
}
|
||||
|
||||
// `override` / `systemPreference` / `enabled` are module-level singletons
|
||||
@@ -45,24 +48,12 @@ async function loadFresh() {
|
||||
return useReducedMotion();
|
||||
}
|
||||
|
||||
const realMatchMedia = window.matchMedia;
|
||||
|
||||
beforeEach(() => {
|
||||
store = makeStorage();
|
||||
vi.stubGlobal("localStorage", store);
|
||||
Object.defineProperty(window, "localStorage", {
|
||||
value: store,
|
||||
configurable: true,
|
||||
writable: true,
|
||||
});
|
||||
stubReducedMotion(false);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.unstubAllGlobals();
|
||||
window.matchMedia = realMatchMedia;
|
||||
});
|
||||
|
||||
describe("useReducedMotion", () => {
|
||||
it("defaults to the system prefers-reduced-motion setting when unset", async () => {
|
||||
stubReducedMotion(true);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { mount } from "@vue/test-utils";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { beforeEach, describe, expect, it } from "vitest";
|
||||
import { defineComponent, h, nextTick, ref } from "vue";
|
||||
import { stubResizeObserver } from "@/test-utils/resizeObserver";
|
||||
import { useResponsiveColumns } from "./index";
|
||||
@@ -29,7 +29,6 @@ describe("useResponsiveColumns", () => {
|
||||
observer = stubResizeObserver();
|
||||
cardWidth.value = 158;
|
||||
});
|
||||
afterEach(() => vi.unstubAllGlobals());
|
||||
|
||||
it("derives the column count from the observed width", async () => {
|
||||
const wrapper = await mountHost();
|
||||
|
||||
@@ -14,9 +14,7 @@ const { uploadRoms, refetchRom, confirmFn, snackbar } = vi.hoisted(() => ({
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
vi.mock("vue-i18n");
|
||||
vi.mock("@/services/api/rom", () => ({
|
||||
default: { uploadRoms },
|
||||
}));
|
||||
@@ -37,7 +35,6 @@ const exists = { isAxiosError: true, response: { status: 409 } };
|
||||
|
||||
describe("useRomFileUpload", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
uploadRoms.mockResolvedValue([{ status: "fulfilled", value: null }]);
|
||||
confirmFn.mockResolvedValue(true);
|
||||
});
|
||||
|
||||
@@ -48,7 +48,6 @@ async function install(path: string) {
|
||||
describe("useRomScanRefresh", () => {
|
||||
beforeEach(() => {
|
||||
handlers.clear();
|
||||
refetchRom.mockClear();
|
||||
});
|
||||
|
||||
it("refetches the open rom when a scan finishes", async () => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { mount } from "@vue/test-utils";
|
||||
import { flushPromises, mount } from "@vue/test-utils";
|
||||
import mitt from "mitt";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { defineComponent, reactive } from "vue";
|
||||
@@ -54,9 +54,6 @@ vi.mock("@/stores/auth", () => ({
|
||||
|
||||
const getTaskStatus = vi.mocked(taskApi.getTaskStatus);
|
||||
|
||||
/** Drain pending microtasks so the reconcile's promise chain has settled. */
|
||||
const flushPromises = () => new Promise((resolve) => setTimeout(resolve, 0));
|
||||
|
||||
/** Outlast the handler's 100ms batching debounce for `scan:scanning_rom`. */
|
||||
const drainRomBatch = () => new Promise((resolve) => setTimeout(resolve, 150));
|
||||
|
||||
|
||||
@@ -24,9 +24,7 @@ const heartbeat = {
|
||||
};
|
||||
const config = ref({ SKIP_HASH_CALCULATION: false });
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
vi.mock("vue-i18n");
|
||||
vi.mock("pinia", () => ({
|
||||
storeToRefs: () => ({ config }),
|
||||
}));
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import storeScanning from "@/stores/scanning";
|
||||
import { useScanTrigger } from "./index";
|
||||
|
||||
@@ -8,9 +8,7 @@ const { emit, connect, warning } = vi.hoisted(() => ({
|
||||
warning: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
vi.mock("vue-i18n");
|
||||
vi.mock("@/services/socket", () => ({
|
||||
default: { connected: false, connect, emit },
|
||||
}));
|
||||
@@ -19,12 +17,6 @@ vi.mock("@/v2/composables/useSnackbar", () => ({
|
||||
}));
|
||||
|
||||
describe("useScanTrigger", () => {
|
||||
beforeEach(() => {
|
||||
emit.mockClear();
|
||||
connect.mockClear();
|
||||
warning.mockClear();
|
||||
});
|
||||
|
||||
it("flips the store, connects and emits one event per payload", () => {
|
||||
const { startScan } = useScanTrigger();
|
||||
|
||||
|
||||
@@ -1,13 +1,4 @@
|
||||
import {
|
||||
afterAll,
|
||||
afterEach,
|
||||
beforeAll,
|
||||
beforeEach,
|
||||
describe,
|
||||
expect,
|
||||
it,
|
||||
vi,
|
||||
} from "vitest";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { nextTick, reactive } from "vue";
|
||||
import { shouldRefreshOnReconnect } from "./index";
|
||||
|
||||
@@ -30,7 +21,6 @@ vi.mock("@/stores/heartbeat", () => ({ default: () => heartbeatStore }));
|
||||
vi.mock("@/stores/playing", () => ({ default: () => playingStore }));
|
||||
|
||||
const reload = vi.fn();
|
||||
let originalLocation: Location;
|
||||
|
||||
// `installed` is module state, so each test needs a fresh module to install
|
||||
// its own watchers.
|
||||
@@ -61,24 +51,9 @@ function quiesce() {
|
||||
document.dispatchEvent(new CustomEvent("network-quiesced"));
|
||||
}
|
||||
|
||||
beforeAll(() => {
|
||||
originalLocation = window.location;
|
||||
Object.defineProperty(window, "location", {
|
||||
configurable: true,
|
||||
value: { ...originalLocation, reload },
|
||||
});
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
Object.defineProperty(window, "location", {
|
||||
configurable: true,
|
||||
value: originalLocation,
|
||||
});
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
vi.stubGlobal("location", { ...window.location, reload });
|
||||
vi.useFakeTimers();
|
||||
reload.mockClear();
|
||||
heartbeatStore = makeHeartbeatStore();
|
||||
playingStore = reactive({ playing: false });
|
||||
});
|
||||
|
||||
@@ -112,7 +112,6 @@ describe("useSpatialNav", () => {
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
scrollIntoView.mockClear();
|
||||
stub("getBoundingClientRect", {
|
||||
value(this: HTMLElement) {
|
||||
if (this.dataset.x === undefined) return new DOMRect(0, 0, 0, 0);
|
||||
@@ -203,7 +202,6 @@ describe("useSpatialNav", () => {
|
||||
expect(scrollIntoView).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ block: "center" }),
|
||||
);
|
||||
vi.unstubAllGlobals();
|
||||
});
|
||||
|
||||
it("skips controls a roving tabindex has taken out of the tab order", () => {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { flushPromises } from "@vue/test-utils";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import type { MusicTrackSchema } from "@/__generated__";
|
||||
import { TRACK_PAGE_SIZE, useTrackPager } from "./index";
|
||||
@@ -56,7 +57,7 @@ describe("useTrackPager", () => {
|
||||
expect(calls).toEqual([0]);
|
||||
|
||||
pager.loadMoreIfNear(TRACK_PAGE_SIZE - 1);
|
||||
await new Promise((r) => setTimeout(r, 0));
|
||||
await flushPromises();
|
||||
expect(calls).toEqual([0, TRACK_PAGE_SIZE]);
|
||||
});
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { flushPromises } from "@vue/test-utils";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { createMemoryHistory, createRouter } from "vue-router";
|
||||
import { expectNoUnhandledRejection } from "@/test-utils/unhandledRejection";
|
||||
@@ -65,7 +66,7 @@ describe("morphTransition", () => {
|
||||
morphTransition({ el, name: "rom-cover-1" }, () => {});
|
||||
expect(el.style.viewTransitionName).toBe("rom-cover-1");
|
||||
await finished;
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
await flushPromises();
|
||||
|
||||
expect(el.style.viewTransitionName).toBe("");
|
||||
el.remove();
|
||||
|
||||
@@ -72,7 +72,6 @@ describe("useWrapGridNav", () => {
|
||||
|
||||
beforeEach(() => {
|
||||
setModality("mouse");
|
||||
scrollIntoView.mockClear();
|
||||
stub("offsetParent", {
|
||||
get(this: HTMLElement) {
|
||||
return this.parentElement;
|
||||
|
||||
@@ -5,9 +5,7 @@ import { nextTick } from "vue";
|
||||
import type { Events } from "@/types/emitter";
|
||||
import AuthLayout from "./AuthLayout.vue";
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
vi.mock("vue-i18n");
|
||||
|
||||
vi.mock("@/v2/composables/useBreakpoint", () => ({
|
||||
installBreakpointAttribute: vi.fn(),
|
||||
|
||||
@@ -46,7 +46,6 @@ describe("RComboboxField inside an overlay", () => {
|
||||
|
||||
afterEach(() => {
|
||||
popEscapable(dialog);
|
||||
vi.mocked(dialog.close).mockClear();
|
||||
});
|
||||
|
||||
function pressEscape(el: Element) {
|
||||
|
||||
@@ -207,7 +207,6 @@ describe("RSelect inside an overlay", () => {
|
||||
|
||||
afterEach(() => {
|
||||
popEscapable(dialog);
|
||||
vi.mocked(dialog.close).mockClear();
|
||||
});
|
||||
|
||||
it("closes only its own menu on Escape, leaving the dialog open", async () => {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user