full-project-search.spec.tsx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. import { EditorProviders } from '../../../helpers/editor-providers'
  2. import FullProjectSearch from '../../../../../modules/full-project-search/frontend/js/components/full-project-search'
  3. import {
  4. LayoutContext,
  5. LayoutContextValue,
  6. } from '@/shared/context/layout-context'
  7. import { FC, useState } from 'react'
  8. describe('<FullProjectSearch/>', function () {
  9. beforeEach(function () {
  10. cy.interceptCompile()
  11. cy.intercept('/project/*/flush', {
  12. statusCode: 204,
  13. }).as('project-history-flush')
  14. cy.intercept('/project/*/changes?*', {
  15. body: [],
  16. }).as('project-history-changes')
  17. cy.intercept('/project/*/latest/history', {
  18. body: { chunk: mockHistoryChunk },
  19. }).as('project-history-snapshot')
  20. cy.intercept('get', '/project/*/blob/*', req => {
  21. const blobId = req.url.split('/').pop() as string
  22. req.reply({
  23. fixture: `blobs/${blobId}`,
  24. })
  25. }).as('project-history-blob')
  26. })
  27. it('displays the search form', function () {
  28. cy.mount(
  29. <EditorProviders providers={{ LayoutProvider }}>
  30. <FullProjectSearch />
  31. </EditorProviders>
  32. )
  33. cy.findByRole('button', { name: 'Search' })
  34. })
  35. it('displays a close button', function () {
  36. cy.mount(
  37. <EditorProviders providers={{ LayoutProvider }}>
  38. <FullProjectSearch />
  39. </EditorProviders>
  40. )
  41. cy.findByRole('button', { name: 'Close' })
  42. })
  43. it('displays matched content', function () {
  44. cy.mount(
  45. <EditorProviders providers={{ LayoutProvider }}>
  46. <FullProjectSearch />
  47. </EditorProviders>
  48. )
  49. cy.findByRole('searchbox', { name: 'Search' }).type('and{enter}')
  50. cy.findByRole('button', { name: 'main.tex 5' }) // TODO: remove count from name?
  51. cy.get('.matched-file-hit').as('matches')
  52. cy.get('@matches').should('have.length', 5)
  53. cy.get('@matches').first().click()
  54. cy.get('@matches').first().should('have.class', 'matched-file-hit-selected')
  55. })
  56. })
  57. const createInitialValue = () =>
  58. ({
  59. reattach: cy.stub(),
  60. detach: cy.stub(),
  61. detachIsLinked: false,
  62. detachRole: null,
  63. changeLayout: cy.stub(),
  64. view: 'editor',
  65. setView: cy.stub(),
  66. chatIsOpen: false,
  67. setChatIsOpen: cy.stub(),
  68. reviewPanelOpen: false,
  69. setReviewPanelOpen: cy.stub(),
  70. miniReviewPanelVisible: false,
  71. setMiniReviewPanelVisible: cy.stub(),
  72. settingsShown: false,
  73. setSettingsShown: cy.stub(),
  74. loadingStyleSheet: false,
  75. setLoadingStyleSheet: cy.stub(),
  76. pdfLayout: 'flat',
  77. pdfPreviewOpen: false,
  78. projectSearchIsOpen: true,
  79. setProjectSearchIsOpen: cy.stub(),
  80. openFile: null,
  81. setOpenFile: cy.stub(),
  82. restoreView: cy.stub(),
  83. handleChangeLayout: cy.stub(),
  84. handleDetach: cy.stub(),
  85. focusMode: false,
  86. setFocusMode: cy.stub(),
  87. }) satisfies LayoutContextValue
  88. const LayoutProvider: FC<React.PropsWithChildren> = ({ children }) => {
  89. const [value] = useState(createInitialValue)
  90. return (
  91. <LayoutContext.Provider value={value}>{children}</LayoutContext.Provider>
  92. )
  93. }
  94. const mockHistoryChunk = {
  95. history: {
  96. snapshot: {
  97. files: {},
  98. },
  99. changes: [
  100. {
  101. operations: [
  102. {
  103. pathname: 'main.tex',
  104. file: {
  105. hash: '5199b66d9d1226551be436c66bad9d962cc05537',
  106. stringLength: 7066,
  107. },
  108. },
  109. ],
  110. timestamp: '2025-01-03T10:10:40.840Z',
  111. authors: [],
  112. v2Authors: ['66e040e0da7136ec75ffe8a3'],
  113. projectVersion: '1.0',
  114. },
  115. {
  116. operations: [
  117. {
  118. pathname: 'sample.bib',
  119. file: {
  120. hash: 'a0e21c740cf81e868f158e30e88985b5ea1d6c19',
  121. stringLength: 244,
  122. },
  123. },
  124. ],
  125. timestamp: '2025-01-03T10:10:40.856Z',
  126. authors: [],
  127. v2Authors: ['66e040e0da7136ec75ffe8a3'],
  128. projectVersion: '2.0',
  129. },
  130. {
  131. operations: [
  132. {
  133. pathname: 'frog.jpg',
  134. file: {
  135. hash: '5b889ef3cf71c83a4c027c4e4dc3d1a106b27809',
  136. byteLength: 97080,
  137. },
  138. },
  139. ],
  140. timestamp: '2025-01-03T10:10:40.890Z',
  141. authors: [],
  142. v2Authors: ['66e040e0da7136ec75ffe8a3'],
  143. projectVersion: '3.0',
  144. },
  145. ],
  146. },
  147. startVersion: 0,
  148. }