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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 { prepareWaitForNextCompileSlot } 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. const { recompile, waitForCompile } = prepareWaitForNextCompileSlot()
  18. waitForCompile(() => {
  19. createProject('test-project')
  20. })
  21. cy.findByRole('textbox', { name: 'Source Editor editing' }).within(() => {
  22. cy.findByText('\\maketitle').parent().click()
  23. cy.findByText('\\maketitle').parent().type('\n\\section{{}Test Section}')
  24. })
  25. recompile()
  26. cy.findByRole('region', { name: 'PDF preview and logs' }).within(() => {
  27. cy.findByLabelText(/Page.*1/i).should('be.visible')
  28. cy.findByText('Test Section').should('be.visible')
  29. })
  30. })
  31. it('create and edit markdown file', function () {
  32. const fileName = `test-${Date.now()}.md`
  33. const markdownContent = '# Markdown title'
  34. login(USER)
  35. createProject('test-project')
  36. cy.findByRole('navigation', { name: 'Project files and outline' })
  37. .findByRole('button', { name: 'New file' })
  38. .click()
  39. cy.findByRole('dialog').within(() => {
  40. cy.findByLabelText('File Name').as('filename').clear()
  41. cy.get('@filename').type(fileName)
  42. cy.findByRole('button', { name: 'Create' }).click()
  43. })
  44. cy.findByRole('button', { name: fileName }).click()
  45. // wait until we've switched to the newly created empty file
  46. cy.findByRole('textbox', { name: 'Source Editor editing' }).should(
  47. 'have.length',
  48. 1
  49. )
  50. cy.findByRole('textbox', { name: 'Source Editor editing' }).type(
  51. markdownContent
  52. )
  53. cy.findByRole('button', { name: 'main.tex' }).click()
  54. cy.findByRole('textbox', { name: 'Source Editor editing' }).should(
  55. 'contain.text',
  56. '\\maketitle'
  57. )
  58. cy.findByRole('button', { name: fileName }).click()
  59. cy.findByRole('textbox', { name: 'Source Editor editing' }).should(
  60. 'contain.text',
  61. markdownContent
  62. )
  63. })
  64. it('can link and display linked image from other project', function () {
  65. const sourceProjectName = `test-project-${Date.now()}`
  66. const targetProjectName = `${sourceProjectName}-target`
  67. login(USER)
  68. createProject(sourceProjectName, {
  69. type: 'Example project',
  70. open: false,
  71. }).as('sourceProjectId')
  72. createProject(targetProjectName)
  73. // link the image from `projectName` into this project
  74. cy.findByRole('button', { name: 'New file' }).click()
  75. cy.findByRole('dialog').within(() => {
  76. cy.findByRole('button', { name: 'From another project' }).click()
  77. cy.findByLabelText('Select a Project').select(sourceProjectName)
  78. cy.findByLabelText('Select a File').select('frog.jpg')
  79. cy.findByRole('button', { name: 'Create' }).click()
  80. })
  81. cy.findByRole('navigation', { name: 'Project files and outline' })
  82. .findByRole('treeitem', { name: 'frog.jpg' })
  83. .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. }).as('sourceProjectId')
  100. createProject(targetProjectName).as('targetProjectId')
  101. // link the image from `projectName` into this project
  102. cy.findByRole('navigation', { name: 'Project files and outline' })
  103. .findByRole('button', { name: 'New file' })
  104. .click()
  105. cy.findByRole('dialog').within(() => {
  106. cy.findByRole('button', { name: 'From another project' }).click()
  107. cy.findByLabelText('Select a Project').select(sourceProjectName)
  108. cy.findByLabelText('Select a File').select('frog.jpg')
  109. cy.findByRole('button', { name: 'Create' }).click()
  110. })
  111. cy.findByRole('navigation', { name: 'Project actions' }).within(() => {
  112. cy.findByRole('button', { name: 'Share' }).click()
  113. })
  114. cy.findByRole('dialog').within(() => {
  115. cy.findByTestId('collaborator-email-input').type(COLLABORATOR + ',')
  116. cy.findByRole('button', { name: 'Invite' }).click()
  117. cy.findByText('Invite not yet accepted.')
  118. })
  119. login(COLLABORATOR)
  120. openProjectViaInviteNotification(targetProjectName)
  121. cy.get('@targetProjectId').then(targetProjectId => {
  122. cy.url().should('include', targetProjectId)
  123. })
  124. cy.findByRole('navigation', { name: 'Project files and outline' })
  125. .findByRole('treeitem', { name: 'frog.jpg' })
  126. .click()
  127. cy.findByRole('link', { name: 'Another project' })
  128. .should('have.attr', 'href')
  129. .then(href => {
  130. cy.get('@sourceProjectId').then(sourceProjectId => {
  131. expect(href).to.equal(`/project/${sourceProjectId}`)
  132. })
  133. })
  134. })
  135. })