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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. import { ensureUserExists, login } from './helpers/login'
  2. import { createProject } from './helpers/project'
  3. import { isExcludedBySharding, startWith } from './helpers/config'
  4. import { throttledRecompile } from './helpers/compile'
  5. describe('Project creation and compilation', function () {
  6. if (isExcludedBySharding('CE_DEFAULT')) return
  7. startWith({})
  8. ensureUserExists({ email: 'user@example.com' })
  9. ensureUserExists({ email: 'collaborator@example.com' })
  10. it('users can create project and compile it', function () {
  11. login('user@example.com')
  12. cy.visit('/project')
  13. // this is the first project created, the welcome screen is displayed instead of the project list
  14. createProject('test-project')
  15. cy.url().should('match', /\/project\/[a-fA-F0-9]{24}/)
  16. const recompile = throttledRecompile()
  17. cy.findByText('\\maketitle').parent().click()
  18. cy.findByText('\\maketitle').parent().type('\n\\section{{}Test Section}')
  19. recompile()
  20. cy.get('.pdf-viewer').should('contain.text', 'Test Section')
  21. })
  22. it('create and edit markdown file', function () {
  23. const fileName = `test-${Date.now()}.md`
  24. const markdownContent = '# Markdown title'
  25. login('user@example.com')
  26. cy.visit('/project')
  27. createProject('test-project')
  28. // FIXME: Add aria-label maybe? or at least data-test-id
  29. cy.findByText('New file').click({ force: true })
  30. cy.findByRole('dialog').within(() => {
  31. cy.get('input').clear()
  32. cy.get('input').type(fileName)
  33. cy.findByText('Create').click()
  34. })
  35. cy.findByText(fileName).click()
  36. // wait until we've switched to the newly created empty file
  37. cy.get('.cm-line').should('have.length', 1)
  38. cy.get('.cm-line').type(markdownContent)
  39. cy.findByText('main.tex').click()
  40. cy.get('.cm-content').should('contain.text', '\\maketitle')
  41. cy.findByText(fileName).click()
  42. cy.get('.cm-content').should('contain.text', markdownContent)
  43. })
  44. it('can link and display linked image from other project', function () {
  45. const sourceProjectName = `test-project-${Date.now()}`
  46. const targetProjectName = `${sourceProjectName}-target`
  47. login('user@example.com')
  48. cy.visit('/project')
  49. createProject(sourceProjectName, { type: 'Example Project' }).as(
  50. 'sourceProjectId'
  51. )
  52. cy.visit('/project')
  53. createProject(targetProjectName)
  54. // link the image from `projectName` into this project
  55. cy.findByText('New file').click({ force: true })
  56. cy.findByRole('dialog').within(() => {
  57. cy.findByText('From another project').click()
  58. cy.findByLabelText('Select a Project').select(sourceProjectName)
  59. cy.findByLabelText('Select a File').select('frog.jpg')
  60. cy.findByText('Create').click()
  61. })
  62. cy.findByTestId('file-tree').findByText('frog.jpg').click()
  63. cy.findByText('Another project')
  64. .should('have.attr', 'href')
  65. .then(href => {
  66. cy.get('@sourceProjectId').then(sourceProjectId => {
  67. expect(href).to.equal(`/project/${sourceProjectId}`)
  68. })
  69. })
  70. })
  71. it('can refresh linked files as collaborator', function () {
  72. const sourceProjectName = `test-project-${Date.now()}`
  73. const targetProjectName = `${sourceProjectName}-target`
  74. login('user@example.com')
  75. cy.visit('/project')
  76. createProject(sourceProjectName, { type: 'Example Project' }).as(
  77. 'sourceProjectId'
  78. )
  79. cy.visit('/project')
  80. createProject(targetProjectName).as('targetProjectId')
  81. // link the image from `projectName` into this project
  82. cy.findByText('New file').click({ force: true })
  83. cy.findByRole('dialog').within(() => {
  84. cy.findByText('From another project').click()
  85. cy.findByLabelText('Select a Project').select(sourceProjectName)
  86. cy.findByLabelText('Select a File').select('frog.jpg')
  87. cy.findByText('Create').click()
  88. })
  89. cy.findByText('Share').click()
  90. cy.findByRole('dialog').within(() => {
  91. cy.get('input').type('collaborator@example.com,')
  92. cy.findByText('Share').click({ force: true })
  93. })
  94. cy.visit('/project')
  95. cy.findByText('Account').click()
  96. cy.findByText('Log Out').click()
  97. login('collaborator@example.com')
  98. cy.visit('/project')
  99. cy.findByText(targetProjectName)
  100. .parent()
  101. .parent()
  102. .within(() => {
  103. cy.findByText('Join Project').click()
  104. })
  105. cy.findByText('Open Project').click()
  106. cy.url().should('match', /\/project\/[a-fA-F0-9]{24}/)
  107. cy.get('@targetProjectId').then(targetProjectId => {
  108. cy.url().should('include', targetProjectId)
  109. })
  110. cy.findByTestId('file-tree').findByText('frog.jpg').click()
  111. cy.findByText('Another project')
  112. .should('have.attr', 'href')
  113. .then(href => {
  114. cy.get('@sourceProjectId').then(sourceProjectId => {
  115. expect(href).to.equal(`/project/${sourceProjectId}`)
  116. })
  117. })
  118. })
  119. })