history.spec.ts 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. cy.findByText('Labels').click()
  15. cy.findAllByTestId('history-version-details')
  16. .first()
  17. .within(() => {
  18. cy.get('button').click() // TODO: add test-id or aria-label
  19. cy.findByText('Label this version').click()
  20. })
  21. cy.findByRole('dialog').within(() => {
  22. cy.get('input[placeholder="New label name"]').type(`${name}{enter}`)
  23. })
  24. }
  25. function downloadVersion(name: string) {
  26. cy.log(`download version ${JSON.stringify(name)}`)
  27. cy.findByText('Labels').click()
  28. cy.findByText(name)
  29. .parent()
  30. .parent()
  31. .parent()
  32. .parent()
  33. .within(() => {
  34. cy.get('.history-version-dropdown-menu-btn').click()
  35. cy.findByText('Download this version').click()
  36. })
  37. }
  38. const CLASS_ADDITION = 'ol-cm-addition-marker'
  39. const CLASS_DELETION = 'ol-cm-deletion-marker'
  40. it('should support labels, comparison and download', () => {
  41. cy.visit('/project')
  42. createProject('labels')
  43. const recompile = throttledRecompile()
  44. cy.log('add content, including a line that will get removed soon')
  45. cy.findByText('\\maketitle').parent().click()
  46. cy.findByText('\\maketitle').parent().type('\n% added')
  47. cy.findByText('\\maketitle').parent().type('\n% to be removed')
  48. recompile()
  49. cy.findByText('History').click()
  50. cy.log('expect to see additions in history')
  51. cy.get('.document-diff-container').within(() => {
  52. cy.findByText('% to be removed').should('have.class', CLASS_ADDITION)
  53. cy.findByText('% added').should('have.class', CLASS_ADDITION)
  54. })
  55. addLabel('Before removal')
  56. cy.log('remove content')
  57. cy.findByText('Back to editor').click()
  58. cy.findByText('% to be removed').parent().type('{end}{shift}{upArrow}{del}')
  59. recompile()
  60. cy.findByText('History').click()
  61. cy.log('expect to see annotation for newly removed content in history')
  62. cy.get('.document-diff-container').within(() => {
  63. cy.findByText('% to be removed').should('have.class', CLASS_DELETION)
  64. cy.findByText('% added').should('not.have.class', CLASS_ADDITION)
  65. })
  66. addLabel('After removal')
  67. cy.log('add more content after labeling')
  68. cy.findByText('Back to editor').click()
  69. cy.findByText('\\maketitle').parent().click()
  70. cy.findByText('\\maketitle').parent().type('\n% more')
  71. recompile()
  72. cy.log('compare non current versions')
  73. cy.findByText('History').click()
  74. cy.findByText('Labels').click()
  75. cy.findAllByTestId('compare-icon-version').last().click()
  76. cy.findAllByTestId('compare-icon-version').filter(':visible').click()
  77. cy.findByText('Compare up to this version').click()
  78. cy.log(
  79. 'expect to see annotation for removed content between the two versions'
  80. )
  81. cy.get('.document-diff-container').within(() => {
  82. cy.findByText('% to be removed').should('have.class', CLASS_DELETION)
  83. cy.findByText('% added').should('not.have.class', CLASS_ADDITION)
  84. cy.findByText('% more').should('not.exist')
  85. })
  86. downloadVersion('Before removal')
  87. cy.task('readFileInZip', {
  88. pathToZip: `cypress/downloads/labels (Version 2).zip`,
  89. fileToRead: 'main.tex',
  90. })
  91. .should('contain', '% added')
  92. .should('contain', '% to be removed')
  93. .should('not.contain', '% more')
  94. downloadVersion('After removal')
  95. cy.task('readFileInZip', {
  96. pathToZip: `cypress/downloads/labels (Version 3).zip`,
  97. fileToRead: 'main.tex',
  98. })
  99. .should('contain', '% added')
  100. .should('not.contain', '% to be removed')
  101. .should('not.contain', '% more')
  102. downloadVersion('Current state')
  103. cy.task('readFileInZip', {
  104. pathToZip: `cypress/downloads/labels (Version 4).zip`,
  105. fileToRead: 'main.tex',
  106. })
  107. .should('contain', '% added')
  108. .should('not.contain', '% to be removed')
  109. .should('contain', '% more')
  110. })
  111. })