history.spec.ts 4.3 KB

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