From bdcf1d3a830d411a80ea7304894973a0f5e77ddd Mon Sep 17 00:00:00 2001 From: Alf Eaton Date: Fri, 21 Mar 2025 11:56:32 +0000 Subject: [PATCH] Convert GitHub Sync tests to Cypress (#24228) * Use OError * Remove setTimeout stub * Convert GitHub Sync tests to Cypress * Use setIgnoringExternalUpdates directly * Migrate remaining GitHub Sync components to TypeScript GitOrigin-RevId: 7c8b875b9a7bbf6353d87a5f93c2267d1d4bc65d --- .../web/frontend/extracted-translations.json | 1 - .../context/editor-manager-context.tsx | 38 ++++++------------- .../ide-react/context/references-context.tsx | 6 +-- .../js/shared/components/loading-spinner.tsx | 3 +- services/web/frontend/js/utils/window.ts | 3 -- services/web/locales/en.json | 1 - 6 files changed, 15 insertions(+), 37 deletions(-) delete mode 100644 services/web/frontend/js/utils/window.ts diff --git a/services/web/frontend/extracted-translations.json b/services/web/frontend/extracted-translations.json index e3d507e088..009158e090 100644 --- a/services/web/frontend/extracted-translations.json +++ b/services/web/frontend/extracted-translations.json @@ -270,7 +270,6 @@ "column_width_is_x_click_to_resize": "", "comment": "", "comment_only": "", - "commit": "", "common": "", "common_causes_of_compile_timeouts_include": "", "commons_plan_tooltip": "", diff --git a/services/web/frontend/js/features/ide-react/context/editor-manager-context.tsx b/services/web/frontend/js/features/ide-react/context/editor-manager-context.tsx index 75cc329a48..da65ba9cc8 100644 --- a/services/web/frontend/js/features/ide-react/context/editor-manager-context.tsx +++ b/services/web/frontend/js/features/ide-react/context/editor-manager-context.tsx @@ -58,8 +58,7 @@ export type EditorManager = { currentDocumentId: DocId | null getCurrentDocValue: () => string | null getCurrentDocumentId: () => DocId | null - startIgnoringExternalUpdates: () => void - stopIgnoringExternalUpdates: () => void + setIgnoringExternalUpdates: (value: boolean) => void openDocWithId: (docId: string, options?: OpenDocOptions) => void openDoc: (document: Doc, options?: OpenDocOptions) => void openDocs: OpenDocuments @@ -228,15 +227,6 @@ export const EditorManagerProvider: FC = ({ children }) => { [currentDocumentId] ) - const startIgnoringExternalUpdates = useCallback( - () => setIgnoringExternalUpdates(true), - [] - ) - const stopIgnoringExternalUpdates = useCallback( - () => setIgnoringExternalUpdates(false), - [] - ) - const jumpToLine = useCallback( (options: GotoLineOptions) => { goToLineEmitter(options) @@ -244,10 +234,6 @@ export const EditorManagerProvider: FC = ({ children }) => { [goToLineEmitter] ) - const unbindFromDocumentEvents = (document: DocumentContainer) => { - document.off() - } - const attachErrorHandlerToDocument = useCallback( (doc: Doc, document: DocumentContainer) => { document.on( @@ -264,12 +250,17 @@ export const EditorManagerProvider: FC = ({ children }) => { [] ) + const ignoringExternalUpdatesRef = useRef(ignoringExternalUpdates) + useEffect(() => { + ignoringExternalUpdatesRef.current = ignoringExternalUpdates + }, [ignoringExternalUpdates]) + const bindToDocumentEvents = useCallback( (doc: Doc, document: DocumentContainer) => { attachErrorHandlerToDocument(doc, document) document.on('externalUpdate', (update: Update) => { - if (ignoringExternalUpdates) { + if (ignoringExternalUpdatesRef.current) { return } if ( @@ -290,12 +281,7 @@ export const EditorManagerProvider: FC = ({ children }) => { ) }) }, - [ - attachErrorHandlerToDocument, - ignoringExternalUpdates, - showGenericMessageModal, - t, - ] + [attachErrorHandlerToDocument, showGenericMessageModal, t] ) const syncTimeoutRef = useRef(null) @@ -383,7 +369,7 @@ export const EditorManagerProvider: FC = ({ children }) => { debugConsole.log('[openNewDocument] Leaving existing open doc...') // Do not trigger any UI changes from remote operations - unbindFromDocumentEvents(currentDocument) + currentDocument.off() // Keep listening for out-of-sync and similar errors. attachErrorHandlerToDocument(doc, currentDocument) @@ -692,8 +678,7 @@ export const EditorManagerProvider: FC = ({ children }) => { currentDocumentId, getCurrentDocValue, getCurrentDocumentId, - startIgnoringExternalUpdates, - stopIgnoringExternalUpdates, + setIgnoringExternalUpdates, openDocWithId, openDoc, openDocs, @@ -715,8 +700,7 @@ export const EditorManagerProvider: FC = ({ children }) => { currentDocumentId, getCurrentDocValue, getCurrentDocumentId, - startIgnoringExternalUpdates, - stopIgnoringExternalUpdates, + setIgnoringExternalUpdates, openDocWithId, openDoc, openDocs, diff --git a/services/web/frontend/js/features/ide-react/context/references-context.tsx b/services/web/frontend/js/features/ide-react/context/references-context.tsx index 0c83a7ad21..36f33ba7b1 100644 --- a/services/web/frontend/js/features/ide-react/context/references-context.tsx +++ b/services/web/frontend/js/features/ide-react/context/references-context.tsx @@ -21,7 +21,7 @@ import useEventListener from '@/shared/hooks/use-event-listener' export const ReferencesContext = createContext< | { referenceKeys: Set - indexAllReferences: (shouldBroadcast: boolean) => void + indexAllReferences: (shouldBroadcast: boolean) => Promise } | undefined >(undefined) @@ -38,8 +38,8 @@ export const ReferencesProvider: FC = ({ children }) => { >({}) const indexAllReferences = useCallback( - (shouldBroadcast: boolean) => { - postJSON(`/project/${projectId}/references/indexAll`, { + async (shouldBroadcast: boolean) => { + return postJSON(`/project/${projectId}/references/indexAll`, { body: { shouldBroadcast, }, diff --git a/services/web/frontend/js/shared/components/loading-spinner.tsx b/services/web/frontend/js/shared/components/loading-spinner.tsx index 69514a6d9e..5a0a81a8c9 100644 --- a/services/web/frontend/js/shared/components/loading-spinner.tsx +++ b/services/web/frontend/js/shared/components/loading-spinner.tsx @@ -4,7 +4,6 @@ import OLSpinner, { OLSpinnerSize, } from '@/features/ui/components/ol/ol-spinner' import { isBootstrap5 } from '@/features/utils/bootstrap-5' -import { setTimeout } from '@/utils/window' import classNames from 'classnames' function LoadingSpinner({ @@ -31,7 +30,7 @@ function LoadingSpinner({ return } - const timer = setTimeout(() => { + const timer = window.setTimeout(() => { setShow(true) }, delay) diff --git a/services/web/frontend/js/utils/window.ts b/services/web/frontend/js/utils/window.ts deleted file mode 100644 index c76f4dd0e0..0000000000 --- a/services/web/frontend/js/utils/window.ts +++ /dev/null @@ -1,3 +0,0 @@ -// Allows easy mocking of `window` methods in tests - -export const setTimeout = window.setTimeout diff --git a/services/web/locales/en.json b/services/web/locales/en.json index 27a9e3192a..1c97fa6f8e 100644 --- a/services/web/locales/en.json +++ b/services/web/locales/en.json @@ -351,7 +351,6 @@ "column_width_is_x_click_to_resize": "Column width is __width__. Click to resize", "comment": "Comment", "comment_only": "Comment only", - "commit": "Commit", "common": "Common", "common_causes_of_compile_timeouts_include": "Common causes of compile timeouts include", "commons_plan_tooltip": "You’re on the __plan__ plan because of your affiliation with __institution__. Click to find out how to make the most of your Overleaf premium features.",