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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. describe('Project creation and compilation', function () {
  9. if (isExcludedBySharding('CE_DEFAULT')) return
  10. startWith({})
  11. ensureUserExists({ email: 'user@example.com' })
  12. ensureUserExists({ email: 'collaborator@example.com' })
  13. it('users can create project and compile it', function () {
  14. login('user@example.com')
  15. createProject('test-project')
  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. createProject('test-project')
  27. // FIXME: Add aria-label maybe? or at least data-test-id
  28. cy.findByText('New file').click({ force: true })
  29. cy.findByRole('dialog').within(() => {
  30. cy.get('input').clear()
  31. cy.get('input').type(fileName)
  32. cy.findByText('Create').click()
  33. })
  34. cy.findByText(fileName).click()
  35. // wait until we've switched to the newly created empty file
  36. cy.get('.cm-line').should('have.length', 1)
  37. cy.get('.cm-line').type(markdownContent)
  38. cy.findByText('main.tex').click()
  39. cy.findByRole('textbox', { name: /Source Editor editing/i }).should(
  40. 'contain.text',
  41. '\\maketitle'
  42. )
  43. cy.findByText(fileName).click()
  44. cy.findByRole('textbox', { name: /Source Editor editing/i }).should(
  45. 'contain.text',
  46. markdownContent
  47. )
  48. })
  49. it('can link and display linked image from other project', function () {
  50. const sourceProjectName = `test-project-${Date.now()}`
  51. const targetProjectName = `${sourceProjectName}-target`
  52. login('user@example.com')
  53. createProject(sourceProjectName, {
  54. type: 'Example project',
  55. open: false,
  56. }).as('sourceProjectId')
  57. createProject(targetProjectName)
  58. // link the image from `projectName` into this project
  59. cy.findByText('New file').click({ force: true })
  60. cy.findByRole('dialog').within(() => {
  61. cy.findByText('From another project').click()
  62. cy.findByLabelText('Select a Project').select(sourceProjectName)
  63. cy.findByLabelText('Select a File').select('frog.jpg')
  64. cy.findByText('Create').click()
  65. })
  66. cy.findByTestId('file-tree').findByText('frog.jpg').click()
  67. cy.findByText('Another project')
  68. .should('have.attr', 'href')
  69. .then(href => {
  70. cy.get('@sourceProjectId').then(sourceProjectId => {
  71. expect(href).to.equal(`/project/${sourceProjectId}`)
  72. })
  73. })
  74. })
  75. it('can refresh linked files as collaborator', function () {
  76. const sourceProjectName = `test-project-${Date.now()}`
  77. const targetProjectName = `${sourceProjectName}-target`
  78. login('user@example.com')
  79. createProject(sourceProjectName, {
  80. type: 'Example project',
  81. open: false,
  82. }).as('sourceProjectId')
  83. createProject(targetProjectName).as('targetProjectId')
  84. // link the image from `projectName` into this project
  85. cy.findByText('New file').click({ force: true })
  86. cy.findByRole('dialog').within(() => {
  87. cy.findByText('From another project').click()
  88. cy.findByLabelText('Select a Project').select(sourceProjectName)
  89. cy.findByLabelText('Select a File').select('frog.jpg')
  90. cy.findByText('Create').click()
  91. })
  92. cy.findByText('Share').click()
  93. cy.findByRole('dialog').within(() => {
  94. cy.findByTestId('collaborator-email-input').type(
  95. 'collaborator@example.com,'
  96. )
  97. cy.findByText('Invite').click({ force: true })
  98. cy.findByText('Invite not yet accepted.')
  99. })
  100. login('collaborator@example.com')
  101. openProjectViaInviteNotification(targetProjectName)
  102. cy.get('@targetProjectId').then(targetProjectId => {
  103. cy.url().should('include', targetProjectId)
  104. })
  105. cy.findByTestId('file-tree').findByText('frog.jpg').click()
  106. cy.findByText('Another project')
  107. .should('have.attr', 'href')
  108. .then(href => {
  109. cy.get('@sourceProjectId').then(sourceProjectId => {
  110. expect(href).to.equal(`/project/${sourceProjectId}`)
  111. })
  112. })
  113. })
  114. })