history.spec.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import { createProject } from './helpers/project'
  2. import { throttledRecompile } from './helpers/compile'
  3. import { ensureUserExists, login } from './helpers/login'
  4. describe('History', function () {
  5. ensureUserExists({ email: 'user@example.com' })
  6. beforeEach(function () {
  7. login('user@example.com')
  8. })
  9. function addLabel(name: string) {
  10. cy.log(`add label ${JSON.stringify(name)}`)
  11. cy.findByText('Labels').click()
  12. cy.findAllByTestId('history-version-details')
  13. .first()
  14. .within(() => {
  15. cy.get('button').click() // TODO: add test-id or aria-label
  16. cy.findByText('Label this version').click()
  17. })
  18. cy.findByRole('dialog').within(() => {
  19. cy.get('input[placeholder="New label name"]').type(`${name}{enter}`)
  20. })
  21. }
  22. const CLASS_ADDITION = 'ol-cm-addition-marker'
  23. const CLASS_DELETION = 'ol-cm-deletion-marker'
  24. it('should support labels and comparison', () => {
  25. cy.visit('/project')
  26. createProject('labels')
  27. const recompile = throttledRecompile()
  28. cy.log('add content, including a line that will get removed soon')
  29. cy.findByText('\\maketitle').parent().click()
  30. cy.findByText('\\maketitle').parent().type('\n% added')
  31. cy.findByText('\\maketitle').parent().type('\n% to be removed')
  32. recompile()
  33. cy.findByText('History').click()
  34. cy.log('expect to see additions in history')
  35. cy.get('.document-diff-container').within(() => {
  36. cy.findByText('% to be removed').should('have.class', CLASS_ADDITION)
  37. cy.findByText('% added').should('have.class', CLASS_ADDITION)
  38. })
  39. addLabel('Before removal')
  40. cy.log('remove content')
  41. cy.findByText('Back to editor').click()
  42. cy.findByText('% to be removed').parent().type('{end}{shift}{upArrow}{del}')
  43. recompile()
  44. cy.findByText('History').click()
  45. cy.log('expect to see annotation for newly removed content in history')
  46. cy.get('.document-diff-container').within(() => {
  47. cy.findByText('% to be removed').should('have.class', CLASS_DELETION)
  48. cy.findByText('% added').should('not.have.class', CLASS_ADDITION)
  49. })
  50. addLabel('After removal')
  51. cy.log('add more content after labeling')
  52. cy.findByText('Back to editor').click()
  53. cy.findByText('\\maketitle').parent().click()
  54. cy.findByText('\\maketitle').parent().type('\n% more')
  55. recompile()
  56. cy.log('compare non current versions')
  57. cy.findByText('History').click()
  58. cy.findByText('Labels').click()
  59. cy.findAllByTestId('compare-icon-version').last().click()
  60. cy.findAllByTestId('compare-icon-version').filter(':visible').click()
  61. cy.findByText('Compare up to this version').click()
  62. cy.log(
  63. 'expect to see annotation for removed content between the two versions'
  64. )
  65. cy.get('.document-diff-container').within(() => {
  66. cy.findByText('% to be removed').should('have.class', CLASS_DELETION)
  67. cy.findByText('% added').should('not.have.class', CLASS_ADDITION)
  68. cy.findByText('% more').should('not.exist')
  69. })
  70. })
  71. })