toolbar.spec.tsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. import Toolbar from '../../../../../frontend/js/features/history/components/diff-view/toolbar/toolbar'
  2. import { HistoryProvider } from '../../../../../frontend/js/features/history/context/history-context'
  3. import { HistoryContextValue } from '../../../../../frontend/js/features/history/context/types/history-context-value'
  4. import { Diff } from '../../../../../frontend/js/features/history/services/types/doc'
  5. import { EditorProviders } from '../../../helpers/editor-providers'
  6. import { FC } from 'react'
  7. import { withTestContainerErrorBoundary } from '../../../helpers/error-boundary'
  8. import { LayoutContextValue } from '@/shared/context/layout-context'
  9. const TestContainerWithoutErrorBoundary: FC<{
  10. layoutContext: LayoutContextValue
  11. diff: Diff
  12. selection: HistoryContextValue['selection']
  13. }> = ({ diff, selection, layoutContext }) => {
  14. return (
  15. <EditorProviders layoutContext={layoutContext}>
  16. <HistoryProvider>
  17. <div className="history-react">
  18. <Toolbar diff={diff} selection={selection} isCurrentVersion={false} />
  19. </div>
  20. </HistoryProvider>
  21. </EditorProviders>
  22. )
  23. }
  24. const TestContainer = withTestContainerErrorBoundary(
  25. TestContainerWithoutErrorBoundary
  26. )
  27. describe('history toolbar', function () {
  28. const diff: Diff = {
  29. binary: false,
  30. docDiff: {
  31. highlights: [
  32. {
  33. range: {
  34. from: 0,
  35. to: 3,
  36. },
  37. hue: 1,
  38. type: 'addition',
  39. label: 'label',
  40. },
  41. ],
  42. doc: 'doc',
  43. },
  44. }
  45. it('renders viewing mode', function () {
  46. const selection: HistoryContextValue['selection'] = {
  47. updateRange: {
  48. fromV: 3,
  49. toV: 6,
  50. fromVTimestamp: 1681413775958,
  51. toVTimestamp: 1681413775958,
  52. },
  53. comparing: false,
  54. files: [
  55. {
  56. pathname: 'main.tex',
  57. operation: 'edited',
  58. },
  59. {
  60. pathname: 'sample.bib',
  61. editable: true,
  62. },
  63. {
  64. pathname: 'frog.jpg',
  65. editable: false,
  66. },
  67. ],
  68. selectedFile: {
  69. pathname: 'main.tex',
  70. editable: true,
  71. },
  72. previouslySelectedPathname: null,
  73. }
  74. cy.mount(
  75. <TestContainer
  76. layoutContext={{ view: 'history' }}
  77. diff={diff}
  78. selection={selection}
  79. />
  80. )
  81. cy.get('.history-react-toolbar').within(() => {
  82. cy.get('div:first-child').contains('Viewing 13th April')
  83. })
  84. cy.get('.history-react-toolbar-file-info').contains('1 change in main.tex')
  85. })
  86. it('renders comparing mode', function () {
  87. const selection: HistoryContextValue['selection'] = {
  88. updateRange: {
  89. fromV: 0,
  90. toV: 6,
  91. fromVTimestamp: 1681313775958,
  92. toVTimestamp: 1681413775958,
  93. },
  94. comparing: true,
  95. files: [
  96. {
  97. pathname: 'main.tex',
  98. operation: 'added',
  99. editable: true,
  100. },
  101. {
  102. pathname: 'sample.bib',
  103. operation: 'added',
  104. editable: true,
  105. },
  106. {
  107. pathname: 'frog.jpg',
  108. operation: 'added',
  109. editable: false,
  110. },
  111. ],
  112. selectedFile: {
  113. pathname: 'main.tex',
  114. editable: true,
  115. },
  116. previouslySelectedPathname: null,
  117. }
  118. cy.mount(
  119. <TestContainer
  120. layoutContext={{ view: 'history' }}
  121. diff={diff}
  122. selection={selection}
  123. />
  124. )
  125. cy.get('.history-react-toolbar').within(() => {
  126. cy.get('div:first-child').contains('Comparing from 12th April')
  127. cy.get('div:first-child').contains('to 13th April')
  128. })
  129. })
  130. })