create-and-compile-project.spec.ts 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. import { ensureUserExists, login } from './helpers/login'
  2. import {
  3. createProject,
  4. openProjectViaInviteNotification,
  5. } from './helpers/project'
  6. import { isExcludedBySharding, startWith } from './helpers/config'
  7. import { throttledRecompile } from './helpers/compile'
  8. const USER = 'user@example.com'
  9. const COLLABORATOR = 'collaborator@example.com'
  10. describe('Project creation and compilation', function () {
  11. if (isExcludedBySharding('CE_DEFAULT')) return
  12. startWith({})
  13. ensureUserExists({ email: USER })
  14. ensureUserExists({ email: COLLABORATOR })
  15. it('users can create project and compile it', function () {
  16. login(USER)
  17. createProject('test-project')
  18. const recompile = throttledRecompile()
  19. cy.findByRole('textbox', { name: 'Source Editor editing' }).within(() => {
  20. cy.findByText('\\maketitle').parent().click()
  21. cy.findByText('\\maketitle').parent().type('\n\\section{{}Test Section}')
  22. })
  23. recompile()
  24. cy.findByRole('region', { name: 'PDF preview and logs' }).within(() => {
  25. cy.findByLabelText(/Page.*1/i).should('be.visible')
  26. cy.findByText('Test Section').should('be.visible')
  27. })
  28. })
  29. it('create and edit markdown file', function () {
  30. const fileName = `test-${Date.now()}.md`
  31. const markdownContent = '# Markdown title'
  32. login(USER)
  33. createProject('test-project')
  34. cy.findByRole('navigation', { name: 'Project files and outline' })
  35. .findByRole('button', { name: 'New file' })
  36. .click()
  37. cy.findByRole('dialog').within(() => {
  38. cy.findByLabelText('File Name').clear().type(fileName)
  39. cy.findByRole('button', { name: 'Create' }).click()
  40. })
  41. cy.findByRole('button', { name: fileName }).click()
  42. // wait until we've switched to the newly created empty file
  43. cy.findByRole('textbox', { name: 'Source Editor editing' }).should(
  44. 'have.length',
  45. 1
  46. )
  47. cy.findByRole('textbox', { name: 'Source Editor editing' }).type(
  48. markdownContent
  49. )
  50. cy.findByRole('button', { name: 'main.tex' }).click()
  51. cy.findByRole('textbox', { name: 'Source Editor editing' }).should(
  52. 'contain.text',
  53. '\\maketitle'
  54. )
  55. cy.findByRole('button', { name: fileName }).click()
  56. cy.findByRole('textbox', { name: 'Source Editor editing' }).should(
  57. 'contain.text',
  58. markdownContent
  59. )
  60. })
  61. it('can link and display linked image from other project', function () {
  62. const sourceProjectName = `test-project-${Date.now()}`
  63. const targetProjectName = `${sourceProjectName}-target`
  64. login(USER)
  65. createProject(sourceProjectName, {
  66. type: 'Example project',
  67. open: false,
  68. }).as('sourceProjectId')
  69. createProject(targetProjectName)
  70. // link the image from `projectName` into this project
  71. cy.findByRole('button', { name: 'New file' }).click()
  72. cy.findByRole('dialog').within(() => {
  73. cy.findByRole('button', { name: 'From another project' }).click()
  74. cy.findByLabelText('Select a Project').select(sourceProjectName)
  75. cy.findByLabelText('Select a File').select('frog.jpg')
  76. cy.findByRole('button', { name: 'Create' }).click()
  77. })
  78. cy.findByRole('navigation', { name: 'Project files and outline' })
  79. .findByRole('treeitem', { name: 'frog.jpg' })
  80. .click()
  81. cy.findByRole('link', { name: 'Another project' })
  82. .should('have.attr', 'href')
  83. .then(href => {
  84. cy.get('@sourceProjectId').then(sourceProjectId => {
  85. expect(href).to.equal(`/project/${sourceProjectId}`)
  86. })
  87. })
  88. })
  89. it('can refresh linked files as collaborator', function () {
  90. const sourceProjectName = `test-project-${Date.now()}`
  91. const targetProjectName = `${sourceProjectName}-target`
  92. login(USER)
  93. createProject(sourceProjectName, {
  94. type: 'Example project',
  95. open: false,
  96. }).as('sourceProjectId')
  97. createProject(targetProjectName).as('targetProjectId')
  98. // link the image from `projectName` into this project
  99. cy.findByRole('navigation', { name: 'Project files and outline' })
  100. .findByRole('button', { name: 'New file' })
  101. .click()
  102. cy.findByRole('dialog').within(() => {
  103. cy.findByRole('button', { name: 'From another project' }).click()
  104. cy.findByLabelText('Select a Project').select(sourceProjectName)
  105. cy.findByLabelText('Select a File').select('frog.jpg')
  106. cy.findByRole('button', { name: 'Create' }).click()
  107. })
  108. cy.findByRole('navigation', { name: 'Project actions' }).within(() => {
  109. cy.findByRole('button', { name: 'Share' }).click()
  110. })
  111. cy.findByRole('dialog').within(() => {
  112. cy.findByTestId('collaborator-email-input').type(COLLABORATOR + ',')
  113. cy.findByRole('button', { name: 'Invite' }).click()
  114. cy.findByText('Invite not yet accepted.')
  115. })
  116. login(COLLABORATOR)
  117. openProjectViaInviteNotification(targetProjectName)
  118. cy.get('@targetProjectId').then(targetProjectId => {
  119. cy.url().should('include', targetProjectId)
  120. })
  121. cy.findByRole('navigation', { name: 'Project files and outline' })
  122. .findByRole('treeitem', { name: 'frog.jpg' })
  123. .click()
  124. cy.findByRole('link', { name: 'Another project' })
  125. .should('have.attr', 'href')
  126. .then(href => {
  127. cy.get('@sourceProjectId').then(sourceProjectId => {
  128. expect(href).to.equal(`/project/${sourceProjectId}`)
  129. })
  130. })
  131. })
  132. })