toolbar.spec.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. describe('history toolbar', function () {
  7. const editorProvidersScope = {
  8. ui: { view: 'history', pdfLayout: 'sideBySide', chatOpen: true },
  9. }
  10. const diff: Diff = {
  11. binary: false,
  12. docDiff: {
  13. highlights: [
  14. {
  15. range: {
  16. from: 0,
  17. to: 3,
  18. },
  19. hue: 1,
  20. type: 'addition',
  21. label: 'label',
  22. },
  23. ],
  24. doc: 'doc',
  25. },
  26. }
  27. it('renders viewing mode', function () {
  28. const selection: HistoryContextValue['selection'] = {
  29. updateRange: {
  30. fromV: 3,
  31. toV: 6,
  32. fromVTimestamp: 1681413775958,
  33. toVTimestamp: 1681413775958,
  34. },
  35. comparing: false,
  36. files: [
  37. {
  38. pathname: 'main.tex',
  39. operation: 'edited',
  40. },
  41. {
  42. pathname: 'sample.bib',
  43. editable: true,
  44. },
  45. {
  46. pathname: 'frog.jpg',
  47. editable: false,
  48. },
  49. ],
  50. selectedFile: {
  51. pathname: 'main.tex',
  52. editable: true,
  53. },
  54. previouslySelectedPathname: null,
  55. }
  56. cy.mount(
  57. <EditorProviders scope={editorProvidersScope}>
  58. <HistoryProvider>
  59. <div className="history-react">
  60. <Toolbar diff={diff} selection={selection} />
  61. </div>
  62. </HistoryProvider>
  63. </EditorProviders>
  64. )
  65. cy.get('.history-react-toolbar').within(() => {
  66. cy.get('div:first-child').contains('Viewing 13th April')
  67. })
  68. cy.get('.history-react-toolbar-file-info').contains('1 change in main.tex')
  69. })
  70. it('renders comparing mode', function () {
  71. const selection: HistoryContextValue['selection'] = {
  72. updateRange: {
  73. fromV: 0,
  74. toV: 6,
  75. fromVTimestamp: 1681313775958,
  76. toVTimestamp: 1681413775958,
  77. },
  78. comparing: true,
  79. files: [
  80. {
  81. pathname: 'main.tex',
  82. operation: 'added',
  83. editable: true,
  84. },
  85. {
  86. pathname: 'sample.bib',
  87. operation: 'added',
  88. editable: true,
  89. },
  90. {
  91. pathname: 'frog.jpg',
  92. operation: 'added',
  93. editable: false,
  94. },
  95. ],
  96. selectedFile: {
  97. pathname: 'main.tex',
  98. editable: true,
  99. },
  100. previouslySelectedPathname: null,
  101. }
  102. cy.mount(
  103. <EditorProviders scope={editorProvidersScope}>
  104. <HistoryProvider>
  105. <div className="history-react">
  106. <Toolbar diff={diff} selection={selection} />
  107. </div>
  108. </HistoryProvider>
  109. </EditorProviders>
  110. )
  111. cy.get('.history-react-toolbar').within(() => {
  112. cy.get('div:first-child').contains('Comparing from 12th April')
  113. cy.get('div:first-child').contains('to 13th April')
  114. })
  115. })
  116. })