editor.spec.ts 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. import { createProject } from './helpers/project'
  2. import { startWith } from './helpers/config'
  3. import { ensureUserExists, login } from './helpers/login'
  4. import { v4 as uuid } from 'uuid'
  5. import { beforeWithReRunOnTestRetry } from './helpers/beforeWithReRunOnTestRetry'
  6. describe('editor', () => {
  7. startWith({ pro: true })
  8. ensureUserExists({ email: 'user@example.com' })
  9. ensureUserExists({ email: 'collaborator@example.com' })
  10. it('word dictionary and spelling', () => {
  11. const fileName = 'test.tex'
  12. const word = createRandomLetterString()
  13. login('user@example.com')
  14. cy.visit('/project')
  15. createProject('test-project')
  16. cy.log('create new project file')
  17. cy.get('button').contains('New file').click({ force: true })
  18. cy.findByRole('dialog').within(() => {
  19. cy.get('input').clear()
  20. cy.get('input').type(fileName)
  21. cy.findByText('Create').click()
  22. })
  23. cy.findByText(fileName).click()
  24. cy.log('edit project file')
  25. // wait until we've switched to the newly created empty file
  26. cy.get('.cm-line').should('have.length', 1)
  27. cy.get('.cm-line').type(word)
  28. cy.get('.ol-cm-spelling-error').should('exist')
  29. cy.log('change project language')
  30. cy.get('button').contains('Menu').click()
  31. cy.get('select[id=settings-menu-spellCheckLanguage]').select('Spanish')
  32. cy.get('[id="left-menu"]').type('{esc}') // close left menu
  33. cy.log('add word to dictionary')
  34. cy.get('.ol-cm-spelling-error').contains(word).rightclick()
  35. cy.findByText('Add to Dictionary').click()
  36. cy.get('.ol-cm-spelling-error').should('not.exist')
  37. cy.log('remove word from dictionary')
  38. cy.get('button').contains('Menu').click()
  39. cy.get('button').contains('Edit').click()
  40. cy.get('[id="dictionary-modal"').within(() => {
  41. cy.findByText(word)
  42. .parent()
  43. .within(() => cy.get('button').click())
  44. })
  45. cy.get('button').contains('Close').click({ force: true })
  46. cy.log('close left panel')
  47. cy.get('[id="left-menu"]').type('{esc}')
  48. cy.log('rewrite word to force spelling error')
  49. cy.get('.cm-line').type('{selectAll}{del}' + word + '{enter}')
  50. cy.get('.ol-cm-spelling-error').should('contain.text', word)
  51. })
  52. describe('collaboration', () => {
  53. let projectName: string
  54. let projectId: string
  55. let resumeUserSession: () => void
  56. let resumeCollaboratorSession: () => void
  57. beforeEach(() => {
  58. projectName = `project-${uuid()}`
  59. resumeUserSession = login('user@example.com')
  60. cy.visit(`/project`)
  61. createProject('test-editor', { type: 'Example Project' }).then(
  62. (id: string) => {
  63. projectId = id
  64. cy.log('make project shareable')
  65. cy.visit(`/project/${projectId}`)
  66. cy.findByText('Share').click()
  67. cy.findByText('Turn on link sharing').click()
  68. cy.log('accept project invitation')
  69. cy.findByText('Anyone with this link can edit this project')
  70. .next()
  71. .should('contain.text', 'http://') // wait for the link to appear
  72. .then(el => {
  73. const linkSharingReadAndWrite = el.text()
  74. resumeCollaboratorSession = login('collaborator@example.com')
  75. cy.visit(linkSharingReadAndWrite)
  76. cy.get('button').contains('Join Project').click()
  77. })
  78. resumeUserSession()
  79. cy.visit(`/project/${projectId}`)
  80. }
  81. )
  82. })
  83. it('track-changes', () => {
  84. cy.log('enable track-changes for everyone')
  85. cy.findByText('Review').click()
  86. cy.get('.review-panel-toolbar-collapse-button').click() // make track-changes switches visible
  87. cy.intercept('POST', '**/track_changes').as('enableTrackChanges')
  88. cy.findByText('Everyone')
  89. .parent()
  90. .within(() => cy.get('.input-switch').click())
  91. cy.wait('@enableTrackChanges')
  92. resumeCollaboratorSession()
  93. cy.visit(`/project/${projectId}`)
  94. cy.log('make changes in main file')
  95. cy.contains('\\maketitle').dblclick()
  96. cy.contains('\\maketitle').type('{del}{enter}{enter}')
  97. cy.log('recompile to force flush')
  98. cy.findByText('Recompile').click()
  99. resumeUserSession()
  100. cy.visit(`/project/${projectId}`)
  101. cy.log('accept changes')
  102. cy.findByText('Review').click()
  103. cy.findByText('Accept').click()
  104. cy.log('verify the changes are applied')
  105. cy.get('.cm-content').should('not.contain.text', '\\maketitle')
  106. })
  107. it('track-changes rich text', () => {
  108. cy.log('enable track-changes for everyone')
  109. cy.findByText('Visual Editor').click()
  110. cy.findByText('Review').click()
  111. cy.get('.review-panel-toolbar-collapse-button').click() // make track-changes switches visible
  112. cy.intercept('POST', '**/track_changes').as('enableTrackChanges')
  113. cy.findByText('Everyone')
  114. .parent()
  115. .within(() => cy.get('.input-switch').click())
  116. cy.wait('@enableTrackChanges')
  117. resumeCollaboratorSession()
  118. cy.visit(`/project/${projectId}`)
  119. cy.log('enable visual editor and make changes in main file')
  120. cy.findByText('Visual Editor').click()
  121. cy.contains('Introduction').dblclick()
  122. cy.contains('Introduction').type('{del}{enter}{enter}')
  123. cy.log('recompile to force flush')
  124. cy.findByText('Recompile').click()
  125. resumeUserSession()
  126. cy.visit(`/project/${projectId}`)
  127. cy.log('accept changes')
  128. cy.findByText('Review').click()
  129. cy.get('.cm-content').should('not.contain.text', 'Introduction')
  130. cy.findAllByText('Reject').first().click({ force: true })
  131. cy.log('verify the changes are applied in the visual editor')
  132. cy.findByText('Visual Editor').click()
  133. cy.get('.cm-content').should('contain.text', 'Introduction')
  134. })
  135. })
  136. describe('editor', () => {
  137. let projectId: string
  138. beforeWithReRunOnTestRetry(() => {
  139. login('user@example.com')
  140. cy.visit(`/project`)
  141. createProject(`project-${uuid()}`, { type: 'Example Project' }).then(
  142. (id: string) => (projectId = id)
  143. )
  144. })
  145. beforeEach(() => {
  146. login('user@example.com')
  147. cy.visit(`/project/${projectId}`)
  148. // wait until the main document is rendered
  149. cy.findByText(/Loading/).should('not.exist')
  150. })
  151. it('renders jpg', () => {
  152. cy.findByTestId('file-tree').findByText('frog.jpg').click()
  153. cy.get('[alt="frog.jpg"]')
  154. .should('be.visible')
  155. .and('have.prop', 'naturalWidth')
  156. .should('be.greaterThan', 0)
  157. })
  158. it('symbol palette', () => {
  159. cy.get('button[aria-label="Toggle Symbol Palette"]').click({
  160. force: true,
  161. })
  162. cy.get('button').contains('𝜉').click()
  163. cy.get('.cm-content').should('contain.text', '\\xi')
  164. })
  165. })
  166. describe('add new file to project', () => {
  167. let projectName: string
  168. beforeEach(() => {
  169. projectName = `project-${uuid()}`
  170. login('user@example.com')
  171. cy.visit(`/project`)
  172. createProject(projectName, { type: 'Example Project' }).then(
  173. (id: string) => {
  174. cy.visit(`/project/${id}`)
  175. cy.get('button').contains('New file').click({ force: true })
  176. }
  177. )
  178. })
  179. it('can upload file', () => {
  180. cy.get('button').contains('Upload').click({ force: true })
  181. cy.get('input[type=file]')
  182. .first()
  183. .selectFile(
  184. {
  185. contents: Cypress.Buffer.from('Test File Content'),
  186. fileName: 'file.txt',
  187. lastModified: Date.now(),
  188. },
  189. { force: true }
  190. )
  191. cy.findByTestId('file-tree').findByText('file.txt').click({ force: true })
  192. cy.findByText('Test File Content')
  193. })
  194. it('should not display import from URL', () => {
  195. cy.findByText('From external URL').should('not.exist')
  196. })
  197. })
  198. describe('left menu', () => {
  199. let projectName: string
  200. beforeEach(() => {
  201. projectName = `project-${uuid()}`
  202. login('user@example.com')
  203. cy.visit(`/project`)
  204. createProject(projectName, { type: 'Example Project' }).then(
  205. (id: string) => {
  206. cy.visit(`/project/${id}`)
  207. cy.get('button').contains('Menu').click()
  208. }
  209. )
  210. })
  211. it('can download project sources', () => {
  212. cy.get('a').contains('Source').click()
  213. cy.task('readFileInZip', {
  214. pathToZip: `cypress/downloads/${projectName}.zip`,
  215. fileToRead: 'main.tex',
  216. }).should('contain', 'Your introduction goes here')
  217. })
  218. it('can download project PDF', () => {
  219. cy.log('ensure project is compiled')
  220. cy.get('.pdf-viewer').should('contain.text', 'Your Paper')
  221. cy.get('.nav-downloads').within(() => {
  222. cy.findByText('PDF').click()
  223. const pdfName = projectName.replaceAll('-', '_')
  224. cy.task('readPdf', `cypress/downloads/${pdfName}.pdf`).should(
  225. 'contain',
  226. 'Your introduction goes here'
  227. )
  228. })
  229. })
  230. it('word count', () => {
  231. cy.log('ensure project is compiled')
  232. cy.get('.pdf-viewer').should('contain.text', 'Your Paper')
  233. cy.findByText('Word Count').click()
  234. cy.get('#word-count-modal').within(() => {
  235. cy.findByText('Total Words:')
  236. cy.findByText('607')
  237. cy.findByText('Headers:')
  238. cy.findByText('14')
  239. cy.findByText('Math Inline:')
  240. cy.findByText('6')
  241. cy.findByText('Math Display:')
  242. cy.findByText('1')
  243. })
  244. })
  245. })
  246. })
  247. function createRandomLetterString() {
  248. const chars = 'abcdefghijklmnopqrstuvwxyz'
  249. let result = ''
  250. for (let i = 0; i < 12; i++) {
  251. result += chars.charAt(Math.floor(Math.random() * chars.length))
  252. }
  253. return result
  254. }