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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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.get('.cm-content').should('contain.text', '\\maketitle')
  40. cy.findByText(fileName).click()
  41. cy.get('.cm-content').should('contain.text', markdownContent)
  42. })
  43. it('can link and display linked image from other project', function () {
  44. const sourceProjectName = `test-project-${Date.now()}`
  45. const targetProjectName = `${sourceProjectName}-target`
  46. login('user@example.com')
  47. createProject(sourceProjectName, { type: 'Example Project' }).as(
  48. 'sourceProjectId'
  49. )
  50. createProject(targetProjectName)
  51. // link the image from `projectName` into this project
  52. cy.findByText('New file').click({ force: true })
  53. cy.findByRole('dialog').within(() => {
  54. cy.findByText('From another project').click()
  55. cy.findByLabelText('Select a Project').select(sourceProjectName)
  56. cy.findByLabelText('Select a File').select('frog.jpg')
  57. cy.findByText('Create').click()
  58. })
  59. cy.findByTestId('file-tree').findByText('frog.jpg').click()
  60. cy.findByText('Another project')
  61. .should('have.attr', 'href')
  62. .then(href => {
  63. cy.get('@sourceProjectId').then(sourceProjectId => {
  64. expect(href).to.equal(`/project/${sourceProjectId}`)
  65. })
  66. })
  67. })
  68. it('can refresh linked files as collaborator', function () {
  69. const sourceProjectName = `test-project-${Date.now()}`
  70. const targetProjectName = `${sourceProjectName}-target`
  71. login('user@example.com')
  72. createProject(sourceProjectName, { type: 'Example Project' }).as(
  73. 'sourceProjectId'
  74. )
  75. createProject(targetProjectName).as('targetProjectId')
  76. // link the image from `projectName` into this project
  77. cy.findByText('New file').click({ force: true })
  78. cy.findByRole('dialog').within(() => {
  79. cy.findByText('From another project').click()
  80. cy.findByLabelText('Select a Project').select(sourceProjectName)
  81. cy.findByLabelText('Select a File').select('frog.jpg')
  82. cy.findByText('Create').click()
  83. })
  84. cy.findByText('Share').click()
  85. cy.findByRole('dialog').within(() => {
  86. cy.get('input').type('collaborator@example.com,')
  87. cy.findByText('Invite').click({ force: true })
  88. cy.findByText('Invite not yet accepted.')
  89. })
  90. cy.visit('/project')
  91. cy.findByText('Account').click()
  92. cy.findByText('Log Out').click()
  93. login('collaborator@example.com')
  94. openProjectViaInviteNotification(targetProjectName)
  95. cy.get('@targetProjectId').then(targetProjectId => {
  96. cy.url().should('include', targetProjectId)
  97. })
  98. cy.findByTestId('file-tree').findByText('frog.jpg').click()
  99. cy.findByText('Another project')
  100. .should('have.attr', 'href')
  101. .then(href => {
  102. cy.get('@sourceProjectId').then(sourceProjectId => {
  103. expect(href).to.equal(`/project/${sourceProjectId}`)
  104. })
  105. })
  106. })
  107. })