history.spec.ts 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. import { createProjectAndOpenInNewEditor } from './helpers/project'
  2. import { prepareWaitForNextCompileSlot } from './helpers/compile'
  3. import { ensureUserExists, login } from './helpers/login'
  4. import { isExcludedBySharding, startWith } from './helpers/config'
  5. describe('History', function () {
  6. if (isExcludedBySharding('CE_DEFAULT')) return
  7. startWith({})
  8. ensureUserExists({ email: 'user@example.com' })
  9. beforeEach(function () {
  10. login('user@example.com')
  11. })
  12. function addLabel(name: string) {
  13. cy.log(`add label ${JSON.stringify(name)}`)
  14. // The input is not clickable due to being visually hidden, click its label instead
  15. cy.findByRole('complementary', {
  16. name: 'Project history and labels',
  17. }).within(() => {
  18. cy.findByRole('group', {
  19. name: 'Show all of the project history or only labelled versions.',
  20. }).within(() => {
  21. cy.findByText('Labels').click()
  22. })
  23. cy.findByRole('radio', { name: 'Labels' }).should('be.checked')
  24. cy.findByRole('radio', { name: 'All history' }).should('not.be.checked')
  25. cy.findAllByTestId('history-version-details')
  26. .first()
  27. .within(() => {
  28. cy.findByRole('button', { name: 'More actions' }).click()
  29. cy.findByRole('menuitem', { name: 'Label this version' }).click()
  30. })
  31. })
  32. cy.findByRole('dialog').within(() => {
  33. cy.findByLabelText('New label name').type(`${name}{enter}`)
  34. })
  35. }
  36. function downloadVersion(name: string) {
  37. cy.log(`download version ${JSON.stringify(name)}`)
  38. // The input is not clickable due to being visually hidden, click its label instead
  39. cy.findByRole('complementary', {
  40. name: 'Project history and labels',
  41. }).within(() => {
  42. cy.findByRole('group', {
  43. name: 'Show all of the project history or only labelled versions.',
  44. }).within(() => {
  45. cy.findByText('Labels').click()
  46. })
  47. cy.findByRole('radio', { name: 'Labels' }).should('be.checked')
  48. cy.findByRole('radio', { name: 'All history' }).should('not.be.checked')
  49. cy.findByText(name)
  50. .closest('[data-testid="history-version-details"]')
  51. .within(() => {
  52. cy.findByRole('button', { name: 'More actions' }).click()
  53. cy.findByRole('menuitem', { name: 'Download this version' }).click()
  54. })
  55. })
  56. }
  57. const CLASS_ADDITION = 'ol-cm-addition-marker'
  58. const CLASS_DELETION = 'ol-cm-deletion-marker'
  59. it('should support labels, comparison and download', function () {
  60. const { recompile, waitForCompile } = prepareWaitForNextCompileSlot()
  61. waitForCompile(() => {
  62. createProjectAndOpenInNewEditor('labels')
  63. })
  64. cy.log('add content, including a line that will get removed soon')
  65. cy.findByRole('textbox', { name: 'Source Editor editing' }).within(() => {
  66. cy.findByText('\\maketitle').parent().click()
  67. cy.findByText('\\maketitle').parent().type('\n% added')
  68. cy.findByText('\\maketitle').parent().type('\n% to be removed')
  69. })
  70. recompile()
  71. cy.findByRole('button', { name: 'History' }).click()
  72. cy.log('expect to see additions in history')
  73. cy.get('.document-diff-container').within(() => {
  74. cy.findByText('% to be removed').should('have.class', CLASS_ADDITION)
  75. cy.findByText('% added').should('have.class', CLASS_ADDITION)
  76. })
  77. addLabel('Before removal')
  78. cy.log('remove content')
  79. cy.findByRole('button', { name: 'Back to editor' }).click()
  80. cy.findByText('% to be removed').parent().type('{end}{shift}{upArrow}{del}')
  81. recompile()
  82. cy.findByRole('button', { name: 'History' }).click()
  83. cy.log('expect to see annotation for newly removed content in history')
  84. cy.get('.document-diff-container').within(() => {
  85. cy.findByText('% to be removed').should('have.class', CLASS_DELETION)
  86. cy.findByText('% added').should('not.have.class', CLASS_ADDITION)
  87. })
  88. addLabel('After removal')
  89. cy.log('add more content after labeling')
  90. cy.findByRole('button', { name: 'Back to editor' }).click()
  91. cy.findByRole('textbox', { name: 'Source Editor editing' }).within(() => {
  92. cy.findByText('\\maketitle').parent().click()
  93. cy.findByText('\\maketitle').parent().type('\n% more')
  94. })
  95. recompile()
  96. cy.log('compare non current versions')
  97. cy.findByRole('button', { name: 'History' }).click()
  98. // The input is not clickable due to being visually hidden, click its label instead
  99. cy.findByRole('complementary', {
  100. name: 'Project history and labels',
  101. }).within(() => {
  102. cy.findByRole('group', {
  103. name: 'Show all of the project history or only labelled versions.',
  104. }).within(() => {
  105. cy.findByText('Labels').click()
  106. })
  107. cy.findByRole('radio', { name: 'Labels' }).should('be.checked')
  108. cy.findByRole('radio', { name: 'All history' }).should('not.be.checked')
  109. cy.findAllByTestId('compare-icon-version').last().click()
  110. cy.findAllByTestId('compare-icon-version').filter(':visible').click()
  111. cy.findByRole('menuitem', {
  112. name: 'Compare up to this version',
  113. }).click()
  114. })
  115. cy.log(
  116. 'expect to see annotation for removed content between the two versions'
  117. )
  118. cy.get('.document-diff-container').within(() => {
  119. cy.findByText('% to be removed').should('have.class', CLASS_DELETION)
  120. cy.findByText('% added').should('not.have.class', CLASS_ADDITION)
  121. cy.findByText('% more').should('not.exist')
  122. })
  123. downloadVersion('Before removal')
  124. cy.task('readFileInZip', {
  125. pathToZip: `cypress/downloads/labels (Version 2).zip`,
  126. fileToRead: 'main.tex',
  127. })
  128. .should('contain', '% added')
  129. .should('contain', '% to be removed')
  130. .should('not.contain', '% more')
  131. downloadVersion('After removal')
  132. cy.task('readFileInZip', {
  133. pathToZip: `cypress/downloads/labels (Version 3).zip`,
  134. fileToRead: 'main.tex',
  135. })
  136. .should('contain', '% added')
  137. .should('not.contain', '% to be removed')
  138. .should('not.contain', '% more')
  139. downloadVersion('Current state')
  140. cy.task('readFileInZip', {
  141. pathToZip: `cypress/downloads/labels (Version 4).zip`,
  142. fileToRead: 'main.tex',
  143. })
  144. .should('contain', '% added')
  145. .should('not.contain', '% to be removed')
  146. .should('contain', '% more')
  147. })
  148. })