Files
overleaf-cep/services/web/test/frontend/features/ide-react/helpers/editor-manager-provider-with-stale-docs.tsx
T
Mathias JakobsenandDavinder Singh 1acb00407e [web] Disable various editor buttons during network stall (#34247)
Co-authored-by: Davinder Singh <davibaweja@gmail.com>
GitOrigin-RevId: 9e169f3591cfff2fdae63b461b946fde4611f2d7
2026-09-17 11:25:49 +00:00

55 lines
1.5 KiB
TypeScript

import React, { type FC, type PropsWithChildren } from 'react'
import {
EditorManager,
EditorManagerContext,
} from '@/features/ide-react/context/editor-manager-context'
export function makeEditorManagerProviderWithStaleDocs(
pendingAt: number,
stubs?: {
openDocWithId?: any
openDoc?: any
openFileWithId?: any
}
) {
const staleDocs = [
{
doc_id: 'stale-doc',
getInflightOpCreatedAt: () => undefined,
getPendingOpCreatedAt: () => pendingAt,
},
]
const EditorManagerProviderWithStaleDocs: FC<PropsWithChildren> = ({
children,
}) => {
const value = {
getEditorType: () => null,
getCurrentDocValue: () => null,
getCurrentDocumentId: () => null,
setIgnoringExternalUpdates: () => {},
openDocWithId: stubs?.openDocWithId ?? cy.stub().resolves(),
openDoc: stubs?.openDoc ?? cy.stub().resolves(),
openDocs: {
awaitBufferedOps: cy.stub().resolves(),
unsavedDocs: () => staleDocs,
hasUnsavedChanges: () => true,
getUnsavedOpsSize: () => ({
pendingOpsLength: 0,
inflightOpsLength: 0,
}),
} as any,
openFileWithId: stubs?.openFileWithId ?? cy.stub(),
openInitialDoc: cy.stub().resolves(),
isLoading: false,
jumpToLine: () => {},
debugTimers: { current: {} },
} as unknown as EditorManager
return (
<EditorManagerContext.Provider value={value}>
{children}
</EditorManagerContext.Provider>
)
}
return EditorManagerProviderWithStaleDocs
}