Просмотр исходного кода

Merge pull request #13605 from overleaf/ae-meta-tests

[cypress] Set/reset window.metaAttributesCache globally

GitOrigin-RevId: 5aa1d5e37780b53f6ddf7d34587e2119ba328003
Alf Eaton 3 лет назад
Родитель
Сommit
283c1d7282
23 измененных файлов с 13 добавлено и 114 удалено
  1. 8 0
      services/web/cypress/support/component.ts
  2. 0 16
      services/web/test/frontend/components/editor-left-menu/editor-left-menu.spec.tsx
  3. 0 5
      services/web/test/frontend/components/pdf-preview/detach-compile-button.spec.tsx
  4. 0 5
      services/web/test/frontend/components/pdf-preview/pdf-logs-entries.spec.tsx
  5. 5 11
      services/web/test/frontend/components/pdf-preview/pdf-preview-detached-root.spec.tsx
  6. 0 5
      services/web/test/frontend/components/pdf-preview/pdf-preview-hybrid-toolbar.spec.tsx
  7. 0 4
      services/web/test/frontend/components/pdf-preview/pdf-preview.spec.tsx
  8. 0 5
      services/web/test/frontend/components/pdf-preview/pdf-synctex-controls.spec.tsx
  9. 0 4
      services/web/test/frontend/components/shared/split-test-badge.spec.tsx
  10. 0 1
      services/web/test/frontend/features/group-management/components/group-managers.spec.tsx
  11. 0 1
      services/web/test/frontend/features/group-management/components/group-members.spec.tsx
  12. 0 1
      services/web/test/frontend/features/group-management/components/institution-managers.spec.tsx
  13. 0 1
      services/web/test/frontend/features/group-management/components/publisher-managers.spec.tsx
  14. 0 2
      services/web/test/frontend/features/project-list/components/table/cells/inline-tags.test.tsx
  15. 0 4
      services/web/test/frontend/features/source-editor/components/codemirror-editor-autocomplete.spec.tsx
  16. 0 4
      services/web/test/frontend/features/source-editor/components/codemirror-editor-close-brackets.spec.tsx
  17. 0 12
      services/web/test/frontend/features/source-editor/components/codemirror-editor-shortcuts.spec.tsx
  18. 0 4
      services/web/test/frontend/features/source-editor/components/codemirror-editor-spellchecker.spec.tsx
  19. 0 4
      services/web/test/frontend/features/source-editor/components/codemirror-editor-visual-floats.spec.tsx
  20. 0 4
      services/web/test/frontend/features/source-editor/components/codemirror-editor.spec.tsx
  21. 0 8
      services/web/test/frontend/shared/hooks/use-detach-action.spec.tsx
  22. 0 5
      services/web/test/frontend/shared/hooks/use-detach-layout.spec.tsx
  23. 0 8
      services/web/test/frontend/shared/hooks/use-detach-state.spec.tsx

+ 8 - 0
services/web/cypress/support/component.ts

@@ -5,3 +5,11 @@ import '../../frontend/js/i18n'
 import './shared/commands'
 import './shared/exceptions'
 import './ct/commands'
+
+beforeEach(function () {
+  window.metaAttributesCache = new Map()
+})
+
+afterEach(function () {
+  window.metaAttributesCache.clear()
+})

+ 0 - 16
services/web/test/frontend/components/editor-left-menu/editor-left-menu.spec.tsx

@@ -9,19 +9,11 @@ import { EditorProviders } from '../../helpers/editor-providers'
 import { mockScope } from './scope'
 
 describe('<EditorLeftMenu />', function () {
-  before(function () {
-    window.metaAttributesCache = new Map()
-  })
-
   beforeEach(function () {
     cy.viewport(800, 800)
     cy.interceptCompile()
   })
 
-  afterEach(function () {
-    window.metaAttributesCache = new Map()
-  })
-
   // eslint-disable-next-line mocha/no-skipped-tests
   describe.skip('for non-anonymous users', function () {
     const overallThemes: OverallThemeMeta[] = [
@@ -60,10 +52,6 @@ describe('<EditorLeftMenu />', function () {
       })
     })
 
-    afterEach(function () {
-      window.metaAttributesCache = new Map()
-    })
-
     it('render full menu', function () {
       const scope = mockScope({
         ui: {
@@ -297,10 +285,6 @@ describe('<EditorLeftMenu />', function () {
     })
 
     describe('settings menu', function () {
-      afterEach(function () {
-        window.metaAttributesCache = new Map()
-      })
-
       it('shows compiler menu correctly', function () {
         const scope = mockScope({
           ui: {

+ 0 - 5
services/web/test/frontend/components/pdf-preview/detach-compile-button.spec.tsx

@@ -5,14 +5,9 @@ import { testDetachChannel } from '../../helpers/detach-channel'
 
 describe('<DetachCompileButtonWrapper />', function () {
   beforeEach(function () {
-    window.metaAttributesCache = new Map()
     cy.interceptEvents()
   })
 
-  afterEach(function () {
-    window.metaAttributesCache = new Map()
-  })
-
   it('detacher mode and not linked: does not show button ', function () {
     cy.interceptCompile()
 

+ 0 - 5
services/web/test/frontend/components/pdf-preview/pdf-logs-entries.spec.tsx

@@ -1,7 +1,6 @@
 import { EditorProviders } from '../../helpers/editor-providers'
 import PdfLogsEntries from '../../../../frontend/js/features/pdf-preview/components/pdf-logs-entries'
 import { detachChannel, testDetachChannel } from '../../helpers/detach-channel'
-window.metaAttributesCache = new Map([['ol-debugPdfDetach', true]])
 
 describe('<PdfLogsEntries/>', function () {
   const fakeEntity = { type: 'doc' }
@@ -36,10 +35,6 @@ describe('<PdfLogsEntries/>', function () {
     cy.interceptEvents()
   })
 
-  afterEach(function () {
-    window.metaAttributesCache = new Map()
-  })
-
   it('displays human readable hint', function () {
     cy.mount(
       <EditorProviders {...props}>

+ 5 - 11
services/web/test/frontend/components/pdf-preview/pdf-preview-detached-root.spec.tsx

@@ -6,21 +6,15 @@ describe('<PdfPreviewDetachedRoot/>', function () {
   beforeEach(function () {
     window.user = { id: 'user1' } as User
 
-    window.metaAttributesCache = new Map<string, unknown>([
-      ['ol-user', window.user],
-      ['ol-project_id', 'project1'],
-      ['ol-detachRole', 'detached'],
-      ['ol-projectName', 'Project Name'],
-      ['ol-preventCompileOnLoad', true],
-    ])
+    window.metaAttributesCache.set('ol-user', window.user)
+    window.metaAttributesCache.set('ol-project_id', 'project1')
+    window.metaAttributesCache.set('ol-detachRole', 'detached')
+    window.metaAttributesCache.set('ol-projectName', 'Project Name')
+    window.metaAttributesCache.set('ol-preventCompileOnLoad', true)
 
     cy.interceptEvents()
   })
 
-  afterEach(function () {
-    window.metaAttributesCache = new Map()
-  })
-
   it('syncs compiling state', function () {
     cy.interceptCompile()
 

+ 0 - 5
services/web/test/frontend/components/pdf-preview/pdf-preview-hybrid-toolbar.spec.tsx

@@ -4,15 +4,10 @@ import { testDetachChannel } from '../../helpers/detach-channel'
 
 describe('<PdfPreviewHybridToolbar/>', function () {
   beforeEach(function () {
-    window.metaAttributesCache = new Map()
     window.metaAttributesCache.set('ol-preventCompileOnLoad', true)
     cy.interceptEvents()
   })
 
-  afterEach(function () {
-    window.metaAttributesCache = new Map()
-  })
-
   it('shows normal mode', function () {
     cy.mount(
       <EditorProviders>

+ 0 - 4
services/web/test/frontend/components/pdf-preview/pdf-preview.spec.tsx

@@ -30,10 +30,6 @@ describe('<PdfPreview/>', function () {
     cy.interceptEvents()
   })
 
-  afterEach(function () {
-    window.metaAttributesCache = new Map()
-  })
-
   it('renders the PDF preview', function () {
     window.metaAttributesCache.set('ol-preventCompileOnLoad', false)
     cy.interceptCompile('compile')

+ 0 - 5
services/web/test/frontend/components/pdf-preview/pdf-synctex-controls.spec.tsx

@@ -78,16 +78,11 @@ const WithSelectedEntities = ({
 
 describe('<PdfSynctexControls/>', function () {
   beforeEach(function () {
-    window.metaAttributesCache = new Map()
     window.metaAttributesCache.set('ol-project_id', 'test-project')
     window.metaAttributesCache.set('ol-preventCompileOnLoad', false)
     cy.interceptEvents()
   })
 
-  afterEach(function () {
-    window.metaAttributesCache = new Map()
-  })
-
   // eslint-disable-next-line mocha/no-skipped-tests
   it.skip('handles clicks on sync buttons', function () {
     cy.interceptCompile()

+ 0 - 4
services/web/test/frontend/components/shared/split-test-badge.spec.tsx

@@ -2,10 +2,6 @@ import SplitTestBadge from '../../../../frontend/js/shared/components/split-test
 import { EditorProviders } from '../../helpers/editor-providers'
 
 describe('split test badge', function () {
-  beforeEach(function () {
-    window.metaAttributesCache = new Map()
-  })
-
   it('renders an alpha badge with the url and tooltip text', function () {
     cy.window().then(win => {
       win.metaAttributesCache.set('ol-splitTestVariants', {

+ 0 - 1
services/web/test/frontend/features/group-management/components/group-managers.spec.tsx

@@ -25,7 +25,6 @@ const PATHS = {
 describe('group managers', function () {
   beforeEach(function () {
     cy.window().then(win => {
-      win.metaAttributesCache = new Map()
       win.metaAttributesCache.set('ol-users', [JOHN_DOE, BOBBY_LAPOINTE])
       win.metaAttributesCache.set('ol-groupId', GROUP_ID)
       win.metaAttributesCache.set('ol-groupName', 'My Awesome Team')

+ 0 - 1
services/web/test/frontend/features/group-management/components/group-members.spec.tsx

@@ -27,7 +27,6 @@ const PATHS = {
 describe('group members, without managed users', function () {
   beforeEach(function () {
     cy.window().then(win => {
-      win.metaAttributesCache = new Map()
       win.metaAttributesCache.set('ol-users', [JOHN_DOE, BOBBY_LAPOINTE])
       win.metaAttributesCache.set('ol-groupId', GROUP_ID)
       win.metaAttributesCache.set('ol-groupName', 'My Awesome Team')

+ 0 - 1
services/web/test/frontend/features/group-management/components/institution-managers.spec.tsx

@@ -25,7 +25,6 @@ const PATHS = {
 describe('institution managers', function () {
   beforeEach(function () {
     cy.window().then(win => {
-      win.metaAttributesCache = new Map()
       win.metaAttributesCache.set('ol-users', [JOHN_DOE, BOBBY_LAPOINTE])
       win.metaAttributesCache.set('ol-groupId', GROUP_ID)
       win.metaAttributesCache.set('ol-groupName', 'My Awesome Institution')

+ 0 - 1
services/web/test/frontend/features/group-management/components/publisher-managers.spec.tsx

@@ -25,7 +25,6 @@ const PATHS = {
 describe('publisher managers', function () {
   beforeEach(function () {
     cy.window().then(win => {
-      win.metaAttributesCache = new Map()
       win.metaAttributesCache.set('ol-users', [JOHN_DOE, BOBBY_LAPOINTE])
       win.metaAttributesCache.set('ol-groupId', GROUP_ID)
       win.metaAttributesCache.set('ol-groupName', 'My Awesome Publisher')

+ 0 - 2
services/web/test/frontend/features/project-list/components/table/cells/inline-tags.test.tsx

@@ -13,7 +13,6 @@ import {
 
 describe('<InlineTags />', function () {
   beforeEach(function () {
-    window.metaAttributesCache = new Map()
     window.metaAttributesCache.set('ol-tags', [
       {
         _id: '789fff789fff',
@@ -36,7 +35,6 @@ describe('<InlineTags />', function () {
 
   afterEach(function () {
     resetProjectListContextFetch()
-    window.metaAttributesCache.clear()
   })
 
   it('renders tags list for a project', function () {

+ 0 - 4
services/web/test/frontend/features/source-editor/components/codemirror-editor-autocomplete.spec.tsx

@@ -19,10 +19,6 @@ describe('autocomplete', { scrollBehavior: false }, function () {
     cy.interceptSpelling()
   })
 
-  afterEach(function () {
-    window.metaAttributesCache = new Map()
-  })
-
   it('opens autocomplete on matched text', function () {
     const rootFolder: Folder[] = [
       {

+ 0 - 4
services/web/test/frontend/features/source-editor/components/codemirror-editor-close-brackets.spec.tsx

@@ -27,10 +27,6 @@ describe('close brackets', { scrollBehavior: false }, function () {
     cy.get('@active-line').click()
   })
 
-  afterEach(function () {
-    window.metaAttributesCache = new Map()
-  })
-
   describe('unprefixed characters', function () {
     it('auto-closes a curly bracket', function () {
       cy.get('@active-line').type('{{}')

+ 0 - 12
services/web/test/frontend/features/source-editor/components/codemirror-editor-shortcuts.spec.tsx

@@ -33,10 +33,6 @@ describe('keyboard shortcuts', { scrollBehavior: false }, function () {
     cy.get('.cm-editor').as('editor')
   })
 
-  afterEach(function () {
-    window.metaAttributesCache = new Map()
-  })
-
   it('comment line with {meta+/}', function () {
     cy.get('@line').type('text')
     cy.get('@line').type(`{${metaKey}+/}`)
@@ -160,10 +156,6 @@ contentLine3
     cy.get('.cm-editor').as('editor')
   })
 
-  afterEach(function () {
-    window.metaAttributesCache = new Map()
-  })
-
   it('emulates search behaviour', function () {
     activeEditorLine().should('have.text', '\\documentclass{article}')
 
@@ -268,10 +260,6 @@ contentLine3
     cy.get('.cm-editor').as('editor')
   })
 
-  afterEach(function () {
-    window.metaAttributesCache = new Map()
-  })
-
   it('can enter characters', function () {
     cy.get('.cm-line').eq(0).as('line')
     cy.get('@line').scrollIntoView()

+ 0 - 4
services/web/test/frontend/features/source-editor/components/codemirror-editor-spellchecker.spec.tsx

@@ -42,10 +42,6 @@ describe('Spellchecker', function () {
     cy.get('@line').click()
   })
 
-  afterEach(function () {
-    window.metaAttributesCache = new Map()
-  })
-
   it('makes initial spellcheck request', function () {
     cy.intercept('POST', '/spelling/check').as('spellCheckRequest')
     cy.get('@line').type('wombat')

+ 0 - 4
services/web/test/frontend/features/source-editor/components/codemirror-editor-visual-floats.spec.tsx

@@ -30,10 +30,6 @@ describe('<CodeMirrorEditor/> floats', function () {
     cy.interceptSpelling()
   })
 
-  afterEach(function () {
-    window.metaAttributesCache.clear()
-  })
-
   it('decorates a caption', function () {
     mountEditor('\n\\caption{Foo}\n')
     cy.get('.cm-line').eq(2).click()

+ 0 - 4
services/web/test/frontend/features/source-editor/components/codemirror-editor.spec.tsx

@@ -17,10 +17,6 @@ describe('<CodeMirrorEditor/>', { scrollBehavior: false }, function () {
     cy.interceptSpelling()
   })
 
-  afterEach(function () {
-    window.metaAttributesCache = new Map()
-  })
-
   it('deletes selected text on Backspace', function () {
     const scope = mockScope()
 

+ 0 - 8
services/web/test/frontend/shared/hooks/use-detach-action.spec.tsx

@@ -23,14 +23,6 @@ const DetachActionTest: FC<{
 }
 
 describe('useDetachAction', function () {
-  beforeEach(function () {
-    window.metaAttributesCache = new Map()
-  })
-
-  afterEach(function () {
-    window.metaAttributesCache = new Map()
-  })
-
   it('broadcast message as sender', function () {
     window.metaAttributesCache.set('ol-detachRole', 'detacher')
 

+ 0 - 5
services/web/test/frontend/shared/hooks/use-detach-layout.spec.tsx

@@ -36,17 +36,12 @@ const DetachLayoutTest = () => {
 
 describe('useDetachLayout', function () {
   beforeEach(function () {
-    window.metaAttributesCache = new Map()
     window.metaAttributesCache.set('ol-preventCompileOnLoad', true)
     cy.stub(window, 'open').as('openWindow')
     cy.stub(window, 'close').as('closeWindow')
     cy.interceptEvents()
   })
 
-  afterEach(function () {
-    window.metaAttributesCache = new Map()
-  })
-
   it('detaching', function () {
     // 1. create hook in normal mode
     cy.mount(

+ 0 - 8
services/web/test/frontend/shared/hooks/use-detach-state.spec.tsx

@@ -28,14 +28,6 @@ const DetachStateTest: FC<{
 }
 
 describe('useDetachState', function () {
-  beforeEach(function () {
-    window.metaAttributesCache = new Map()
-  })
-
-  afterEach(function () {
-    window.metaAttributesCache = new Map()
-  })
-
   it('create and update state', function () {
     cy.mount(
       <EditorProviders>