editor.spec.ts 9.3 KB

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