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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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').clear().type(fileName)
  41. cy.findByRole('button', { name: 'Create' }).click()
  42. })
  43. cy.findByRole('button', { name: fileName }).click()
  44. // wait until we've switched to the newly created empty file
  45. cy.findByRole('textbox', { name: 'Source Editor editing' }).should(
  46. 'have.length',
  47. 1
  48. )
  49. cy.findByRole('textbox', { name: 'Source Editor editing' }).type(
  50. markdownContent
  51. )
  52. cy.findByRole('button', { name: 'main.tex' }).click()
  53. cy.findByRole('textbox', { name: 'Source Editor editing' }).should(
  54. 'contain.text',
  55. '\\maketitle'
  56. )
  57. cy.findByRole('button', { name: fileName }).click()
  58. cy.findByRole('textbox', { name: 'Source Editor editing' }).should(
  59. 'contain.text',
  60. markdownContent
  61. )
  62. })
  63. it('can link and display linked image from other project', function () {
  64. const sourceProjectName = `test-project-${Date.now()}`
  65. const targetProjectName = `${sourceProjectName}-target`
  66. login(USER)
  67. createProject(sourceProjectName, {
  68. type: 'Example project',
  69. open: false,
  70. }).as('sourceProjectId')
  71. createProject(targetProjectName)
  72. // link the image from `projectName` into this project
  73. cy.findByRole('button', { name: 'New file' }).click()
  74. cy.findByRole('dialog').within(() => {
  75. cy.findByRole('button', { name: 'From another project' }).click()
  76. cy.findByLabelText('Select a Project').select(sourceProjectName)
  77. cy.findByLabelText('Select a File').select('frog.jpg')
  78. cy.findByRole('button', { name: 'Create' }).click()
  79. })
  80. cy.findByRole('navigation', { name: 'Project files and outline' })
  81. .findByRole('treeitem', { name: 'frog.jpg' })
  82. .click()
  83. cy.findByRole('link', { name: 'Another project' })
  84. .should('have.attr', 'href')
  85. .then(href => {
  86. cy.get('@sourceProjectId').then(sourceProjectId => {
  87. expect(href).to.equal(`/project/${sourceProjectId}`)
  88. })
  89. })
  90. })
  91. it('can refresh linked files as collaborator', function () {
  92. const sourceProjectName = `test-project-${Date.now()}`
  93. const targetProjectName = `${sourceProjectName}-target`
  94. login(USER)
  95. createProject(sourceProjectName, {
  96. type: 'Example project',
  97. open: false,
  98. }).as('sourceProjectId')
  99. createProject(targetProjectName).as('targetProjectId')
  100. // link the image from `projectName` into this project
  101. cy.findByRole('navigation', { name: 'Project files and outline' })
  102. .findByRole('button', { name: 'New file' })
  103. .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)
  120. cy.get('@targetProjectId').then(targetProjectId => {
  121. cy.url().should('include', targetProjectId)
  122. })
  123. cy.findByRole('navigation', { name: 'Project files and outline' })
  124. .findByRole('treeitem', { name: 'frog.jpg' })
  125. .click()
  126. cy.findByRole('link', { name: 'Another project' })
  127. .should('have.attr', 'href')
  128. .then(href => {
  129. cy.get('@sourceProjectId').then(sourceProjectId => {
  130. expect(href).to.equal(`/project/${sourceProjectId}`)
  131. })
  132. })
  133. })
  134. })