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

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