history.spec.ts 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. import { createProject } from './helpers/project'
  2. import { throttledRecompile } 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', () => {
  60. createProject('labels')
  61. const recompile = throttledRecompile()
  62. cy.log('add content, including a line that will get removed soon')
  63. cy.findByRole('textbox', { name: 'Source Editor editing' }).within(() => {
  64. cy.findByText('\\maketitle').parent().click()
  65. cy.findByText('\\maketitle').parent().type('\n% added')
  66. cy.findByText('\\maketitle').parent().type('\n% to be removed')
  67. })
  68. recompile()
  69. cy.findByRole('button', { name: 'History' }).click()
  70. cy.log('expect to see additions in history')
  71. cy.get('.document-diff-container').within(() => {
  72. cy.findByText('% to be removed').should('have.class', CLASS_ADDITION)
  73. cy.findByText('% added').should('have.class', CLASS_ADDITION)
  74. })
  75. addLabel('Before removal')
  76. cy.log('remove content')
  77. cy.findByRole('button', { name: 'Back to editor' }).click()
  78. cy.findByText('% to be removed').parent().type('{end}{shift}{upArrow}{del}')
  79. recompile()
  80. cy.findByRole('button', { name: 'History' }).click()
  81. cy.log('expect to see annotation for newly removed content in history')
  82. cy.get('.document-diff-container').within(() => {
  83. cy.findByText('% to be removed').should('have.class', CLASS_DELETION)
  84. cy.findByText('% added').should('not.have.class', CLASS_ADDITION)
  85. })
  86. addLabel('After removal')
  87. cy.log('add more content after labeling')
  88. cy.findByRole('button', { name: 'Back to editor' }).click()
  89. cy.findByRole('textbox', { name: 'Source Editor editing' }).within(() => {
  90. cy.findByText('\\maketitle').parent().click()
  91. cy.findByText('\\maketitle').parent().type('\n% more')
  92. })
  93. recompile()
  94. cy.log('compare non current versions')
  95. cy.findByRole('button', { name: 'History' }).click()
  96. // The input is not clickable due to being visually hidden, click its label instead
  97. cy.findByRole('complementary', {
  98. name: 'Project history and labels',
  99. }).within(() => {
  100. cy.findByRole('group', {
  101. name: 'Show all of the project history or only labelled versions.',
  102. }).within(() => {
  103. cy.findByText('Labels').click()
  104. })
  105. cy.findByRole('radio', { name: 'Labels' }).should('be.checked')
  106. cy.findByRole('radio', { name: 'All history' }).should('not.be.checked')
  107. cy.findAllByTestId('compare-icon-version').last().click()
  108. cy.findAllByTestId('compare-icon-version').filter(':visible').click()
  109. cy.findByRole('menuitem', {
  110. name: 'Compare up to this version',
  111. }).click()
  112. })
  113. cy.log(
  114. 'expect to see annotation for removed content between the two versions'
  115. )
  116. cy.get('.document-diff-container').within(() => {
  117. cy.findByText('% to be removed').should('have.class', CLASS_DELETION)
  118. cy.findByText('% added').should('not.have.class', CLASS_ADDITION)
  119. cy.findByText('% more').should('not.exist')
  120. })
  121. downloadVersion('Before removal')
  122. cy.task('readFileInZip', {
  123. pathToZip: `cypress/downloads/labels (Version 2).zip`,
  124. fileToRead: 'main.tex',
  125. })
  126. .should('contain', '% added')
  127. .should('contain', '% to be removed')
  128. .should('not.contain', '% more')
  129. downloadVersion('After removal')
  130. cy.task('readFileInZip', {
  131. pathToZip: `cypress/downloads/labels (Version 3).zip`,
  132. fileToRead: 'main.tex',
  133. })
  134. .should('contain', '% added')
  135. .should('not.contain', '% to be removed')
  136. .should('not.contain', '% more')
  137. downloadVersion('Current state')
  138. cy.task('readFileInZip', {
  139. pathToZip: `cypress/downloads/labels (Version 4).zip`,
  140. fileToRead: 'main.tex',
  141. })
  142. .should('contain', '% added')
  143. .should('not.contain', '% to be removed')
  144. .should('contain', '% more')
  145. })
  146. })