FN-6078: fix dashboard tests to use constructable mocks
Update dashboard tests to mirror constructor-based browser APIs and xterm addons. - rewrite SessionTerminal mobile test doubles as constructable function mocks so xterm and addon instances initialize like real classes - replace the useDocuments AbortController stub with a class-based mock to preserve constructor semantics during fetch cancellation tests Files changed: .../__tests__/SessionTerminal.mobile.test.tsx | 21 +++++++++++++++++---- .../app/hooks/__tests__/useDocuments.test.ts | 8 ++++---- 2 files changed, 21 insertions(+), 8 deletions(-) Fusion-Task-Id: FN-6078 Fusion-Task-Lineage: d8e0a9aa-6c7c-44c1-b9d4-5196924531c1
This commit is contained in:
@@ -13,11 +13,24 @@ const mockTerm = {
|
||||
cols: 80,
|
||||
rows: 24,
|
||||
};
|
||||
vi.mock("@xterm/xterm", () => ({ Terminal: vi.fn(() => mockTerm) }));
|
||||
vi.mock("@xterm/addon-fit", () => ({ FitAddon: vi.fn(() => ({ fit: vi.fn() })) }));
|
||||
vi.mock("@xterm/addon-unicode11", () => ({ Unicode11Addon: vi.fn(() => ({})) }));
|
||||
vi.mock("@xterm/xterm", () => ({
|
||||
Terminal: vi.fn(function (this: typeof mockTerm) {
|
||||
Object.assign(this, mockTerm);
|
||||
}),
|
||||
}));
|
||||
vi.mock("@xterm/addon-fit", () => ({
|
||||
FitAddon: vi.fn(function (this: { fit: ReturnType<typeof vi.fn> }) {
|
||||
this.fit = vi.fn();
|
||||
}),
|
||||
}));
|
||||
vi.mock("@xterm/addon-unicode11", () => ({
|
||||
Unicode11Addon: vi.fn(function () {}),
|
||||
}));
|
||||
vi.mock("@xterm/addon-webgl", () => ({
|
||||
WebglAddon: vi.fn(() => ({ onContextLoss: vi.fn(), dispose: vi.fn() })),
|
||||
WebglAddon: vi.fn(function (this: { onContextLoss: ReturnType<typeof vi.fn>; dispose: ReturnType<typeof vi.fn> }) {
|
||||
this.onContextLoss = vi.fn();
|
||||
this.dispose = vi.fn();
|
||||
}),
|
||||
}));
|
||||
|
||||
const apiMock = vi.fn();
|
||||
|
||||
@@ -228,10 +228,10 @@ describe("useDocuments", () => {
|
||||
const abortMock = vi.fn();
|
||||
const originalAbortController = globalThis.AbortController;
|
||||
|
||||
globalThis.AbortController = vi.fn().mockImplementation(() => ({
|
||||
signal: {},
|
||||
abort: abortMock,
|
||||
})) as unknown as typeof AbortController;
|
||||
globalThis.AbortController = class {
|
||||
signal = {};
|
||||
abort = abortMock;
|
||||
} as unknown as typeof AbortController;
|
||||
|
||||
globalThis.fetch = vi.fn().mockReturnValue(
|
||||
new Promise(() => {
|
||||
|
||||
Reference in New Issue
Block a user