history.spec.ts 4.3 KB

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