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

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