Răsfoiți Sursa

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
Alf Eaton 1 an în urmă
părinte
comite
bdcf1d3a83

+ 0 - 1
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": "",

+ 11 - 27
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<boolean>(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<number | null>(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,

+ 3 - 3
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<string>
-      indexAllReferences: (shouldBroadcast: boolean) => void
+      indexAllReferences: (shouldBroadcast: boolean) => Promise<void>
     }
   | 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,
         },

+ 1 - 2
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)
 

+ 0 - 3
services/web/frontend/js/utils/window.ts

@@ -1,3 +0,0 @@
-// Allows easy mocking of `window` methods in tests
-
-export const setTimeout = window.setTimeout

+ 0 - 1
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.",