editor.spec.ts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  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. // the modal has 2 close buttons, this ensures the one with the visible label is
  45. // clicked, otherwise it would need `force: true`
  46. cy.get('.btn').contains('Close').click()
  47. })
  48. cy.log('close left panel')
  49. cy.get('[id="left-menu"]').type('{esc}')
  50. cy.log('rewrite word to force spelling error')
  51. cy.get('.cm-line').type('{selectAll}{del}' + word + '{enter}')
  52. cy.get('.ol-cm-spelling-error').should('contain.text', word)
  53. })
  54. describe('collaboration', () => {
  55. let projectName: string
  56. let projectId: string
  57. let resumeUserSession: () => void
  58. let resumeCollaboratorSession: () => void
  59. beforeEach(() => {
  60. projectName = `project-${uuid()}`
  61. resumeUserSession = login('user@example.com')
  62. cy.visit(`/project`)
  63. createProject('test-editor', { type: 'Example Project' }).then(
  64. (id: string) => {
  65. projectId = id
  66. cy.log('make project shareable')
  67. cy.visit(`/project/${projectId}`)
  68. cy.findByText('Share').click()
  69. cy.findByText('Turn on link sharing').click()
  70. cy.log('accept project invitation')
  71. cy.findByText('Anyone with this link can edit this project')
  72. .next()
  73. .should('contain.text', 'http://') // wait for the link to appear
  74. .then(el => {
  75. const linkSharingReadAndWrite = el.text()
  76. resumeCollaboratorSession = login('collaborator@example.com')
  77. cy.visit(linkSharingReadAndWrite)
  78. cy.get('button').contains('Join Project').click()
  79. })
  80. resumeUserSession()
  81. cy.visit(`/project/${projectId}`)
  82. }
  83. )
  84. })
  85. it('track-changes', () => {
  86. cy.log('enable track-changes for everyone')
  87. cy.findByText('Review').click()
  88. cy.get('.review-panel-toolbar-collapse-button').click() // make track-changes switches visible
  89. cy.intercept('POST', '**/track_changes').as('enableTrackChanges')
  90. cy.findByText('Everyone')
  91. .parent()
  92. .within(() => cy.get('.input-switch').click())
  93. cy.wait('@enableTrackChanges')
  94. resumeCollaboratorSession()
  95. cy.visit(`/project/${projectId}`)
  96. cy.log('make changes in main file')
  97. cy.contains('\\maketitle').dblclick()
  98. cy.contains('\\maketitle').type('{del}{enter}{enter}')
  99. cy.log('recompile to force flush')
  100. cy.findByText('Recompile').click()
  101. resumeUserSession()
  102. cy.visit(`/project/${projectId}`)
  103. cy.log('accept changes')
  104. cy.findByText('Review').click()
  105. cy.findByText('Accept').click()
  106. cy.log('verify the changes are applied')
  107. cy.get('.cm-content').should('not.contain.text', '\\maketitle')
  108. })
  109. it('track-changes rich text', () => {
  110. cy.log('enable track-changes for everyone')
  111. cy.findByText('Visual Editor').click()
  112. cy.findByText('Review').click()
  113. cy.get('.review-panel-toolbar-collapse-button').click() // make track-changes switches visible
  114. cy.intercept('POST', '**/track_changes').as('enableTrackChanges')
  115. cy.findByText('Everyone')
  116. .parent()
  117. .within(() => cy.get('.input-switch').click())
  118. cy.wait('@enableTrackChanges')
  119. resumeCollaboratorSession()
  120. cy.visit(`/project/${projectId}`)
  121. cy.log('enable visual editor and make changes in main file')
  122. cy.findByText('Visual Editor').click()
  123. cy.contains('Introduction').dblclick()
  124. cy.contains('Introduction').type('{del}{enter}{enter}')
  125. cy.log('recompile to force flush')
  126. cy.findByText('Recompile').click()
  127. resumeUserSession()
  128. cy.visit(`/project/${projectId}`)
  129. cy.log('accept changes')
  130. cy.findByText('Review').click()
  131. cy.get('.cm-content').should('not.contain.text', 'Introduction')
  132. cy.findAllByText('Reject').first().click({ force: true })
  133. cy.log('verify the changes are applied in the visual editor')
  134. cy.findByText('Visual Editor').click()
  135. cy.get('.cm-content').should('contain.text', 'Introduction')
  136. })
  137. })
  138. describe('editor', () => {
  139. let projectId: string
  140. beforeWithReRunOnTestRetry(() => {
  141. login('user@example.com')
  142. cy.visit(`/project`)
  143. createProject(`project-${uuid()}`, { type: 'Example Project' }).then(
  144. (id: string) => (projectId = id)
  145. )
  146. })
  147. beforeEach(() => {
  148. login('user@example.com')
  149. cy.visit(`/project/${projectId}`)
  150. // wait until the main document is rendered
  151. cy.findByText(/Loading/).should('not.exist')
  152. })
  153. it('renders jpg', () => {
  154. cy.findByTestId('file-tree').findByText('frog.jpg').click()
  155. cy.get('[alt="frog.jpg"]')
  156. .should('be.visible')
  157. .and('have.prop', 'naturalWidth')
  158. .should('be.greaterThan', 0)
  159. })
  160. it('symbol palette', () => {
  161. cy.get('button[aria-label="Toggle Symbol Palette"]').click({
  162. force: true,
  163. })
  164. cy.get('button').contains('𝜉').click()
  165. cy.get('.cm-content').should('contain.text', '\\xi')
  166. })
  167. })
  168. describe('add new file to project', () => {
  169. let projectName: string
  170. beforeEach(() => {
  171. projectName = `project-${uuid()}`
  172. login('user@example.com')
  173. cy.visit(`/project`)
  174. createProject(projectName, { type: 'Example Project' }).then(
  175. (id: string) => {
  176. cy.visit(`/project/${id}`)
  177. cy.get('button').contains('New file').click({ force: true })
  178. }
  179. )
  180. })
  181. it('can upload file', () => {
  182. cy.get('button').contains('Upload').click({ force: true })
  183. cy.get('input[type=file]')
  184. .first()
  185. .selectFile(
  186. {
  187. contents: Cypress.Buffer.from('Test File Content'),
  188. fileName: 'file.txt',
  189. lastModified: Date.now(),
  190. },
  191. { force: true }
  192. )
  193. cy.findByTestId('file-tree').findByText('file.txt').click({ force: true })
  194. cy.findByText('Test File Content')
  195. })
  196. it('should not display import from URL', () => {
  197. cy.findByText('From external URL').should('not.exist')
  198. })
  199. })
  200. describe('left menu', () => {
  201. let projectName: string
  202. beforeEach(() => {
  203. projectName = `project-${uuid()}`
  204. login('user@example.com')
  205. cy.visit(`/project`)
  206. createProject(projectName, { type: 'Example Project' }).then(
  207. (id: string) => {
  208. cy.visit(`/project/${id}`)
  209. cy.get('button').contains('Menu').click()
  210. }
  211. )
  212. })
  213. it('can download project sources', () => {
  214. cy.get('a').contains('Source').click()
  215. cy.task('readFileInZip', {
  216. pathToZip: `cypress/downloads/${projectName}.zip`,
  217. fileToRead: 'main.tex',
  218. }).should('contain', 'Your introduction goes here')
  219. })
  220. it('can download project PDF', () => {
  221. cy.log('ensure project is compiled')
  222. cy.get('.pdf-viewer').should('contain.text', 'Your Paper')
  223. cy.get('.nav-downloads').within(() => {
  224. cy.findByText('PDF').click()
  225. const pdfName = projectName.replaceAll('-', '_')
  226. cy.task('readPdf', `cypress/downloads/${pdfName}.pdf`).should(
  227. 'contain',
  228. 'Your introduction goes here'
  229. )
  230. })
  231. })
  232. it('word count', () => {
  233. cy.log('ensure project is compiled')
  234. cy.get('.pdf-viewer').should('contain.text', 'Your Paper')
  235. cy.findByText('Word Count').click()
  236. cy.get('#word-count-modal').within(() => {
  237. cy.findByText('Total Words:')
  238. cy.findByText('607')
  239. cy.findByText('Headers:')
  240. cy.findByText('14')
  241. cy.findByText('Math Inline:')
  242. cy.findByText('6')
  243. cy.findByText('Math Display:')
  244. cy.findByText('1')
  245. })
  246. })
  247. })
  248. describe('layout selector', () => {
  249. let projectId: string
  250. beforeEach(() => {
  251. login('user@example.com')
  252. cy.visit(`/project`)
  253. createProject(`project-${uuid()}`, { type: 'Example Project' })
  254. })
  255. it('show editor only and switch between editor and pdf', () => {
  256. cy.get('.pdf-viewer').should('be.visible')
  257. cy.get('.cm-editor').should('be.visible')
  258. cy.findByText('Layout').click()
  259. cy.findByText('Editor only').click()
  260. cy.get('.pdf-viewer').should('not.exist')
  261. cy.get('.cm-editor').should('be.visible')
  262. cy.findByText('Switch to PDF').click()
  263. cy.get('.pdf-viewer').should('be.visible')
  264. cy.get('.cm-editor').should('not.be.visible')
  265. cy.findByText('Switch to editor').click()
  266. cy.get('.pdf-viewer').should('not.exist')
  267. cy.get('.cm-editor').should('be.visible')
  268. })
  269. it('show PDF only and go back to Editor & PDF', () => {
  270. cy.get('.pdf-viewer').should('be.visible')
  271. cy.get('.cm-editor').should('be.visible')
  272. cy.findByText('Layout').click()
  273. cy.findByText('PDF only').click()
  274. cy.get('.pdf-viewer').should('be.visible')
  275. cy.get('.cm-editor').should('not.be.visible')
  276. cy.findByText('Layout').click()
  277. cy.findByText('Editor & PDF').click()
  278. cy.get('.pdf-viewer').should('be.visible')
  279. cy.get('.cm-editor').should('be.visible')
  280. })
  281. it('PDF in a separate tab (tests editor only)', () => {
  282. cy.get('.pdf-viewer').should('be.visible')
  283. cy.get('.cm-editor').should('be.visible')
  284. cy.findByText('Layout').click()
  285. cy.findByText('PDF in separate tab').click()
  286. cy.get('.pdf-viewer').should('not.exist')
  287. cy.get('.cm-editor').should('be.visible')
  288. })
  289. })
  290. })
  291. function createRandomLetterString() {
  292. const chars = 'abcdefghijklmnopqrstuvwxyz'
  293. let result = ''
  294. for (let i = 0; i < 12; i++) {
  295. result += chars.charAt(Math.floor(Math.random() * chars.length))
  296. }
  297. return result
  298. }