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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. import { ensureUserExists, login } from './helpers/login'
  2. import { createProject } from './helpers/project'
  3. import { startWith } from './helpers/config'
  4. import { throttledRecompile } from './helpers/compile'
  5. describe('Project creation and compilation', function () {
  6. startWith({})
  7. ensureUserExists({ email: 'user@example.com' })
  8. ensureUserExists({ email: 'collaborator@example.com' })
  9. it('users can create project and compile it', function () {
  10. login('user@example.com')
  11. cy.visit('/project')
  12. // this is the first project created, the welcome screen is displayed instead of the project list
  13. createProject('test-project')
  14. cy.url().should('match', /\/project\/[a-fA-F0-9]{24}/)
  15. const recompile = throttledRecompile()
  16. cy.findByText('\\maketitle').parent().click()
  17. cy.findByText('\\maketitle').parent().type('\n\\section{{}Test Section}')
  18. recompile()
  19. cy.get('.pdf-viewer').should('contain.text', 'Test Section')
  20. })
  21. it('create and edit markdown file', function () {
  22. const fileName = `test-${Date.now()}.md`
  23. const markdownContent = '# Markdown title'
  24. login('user@example.com')
  25. cy.visit('/project')
  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. cy.visit('/project')
  48. createProject(sourceProjectName, { type: 'Example Project' }).as(
  49. 'sourceProjectId'
  50. )
  51. cy.visit('/project')
  52. createProject(targetProjectName)
  53. // link the image from `projectName` into this project
  54. cy.findByText('New file').click({ force: true })
  55. cy.findByRole('dialog').within(() => {
  56. cy.findByText('From another project').click()
  57. cy.findByLabelText('Select a Project').select(sourceProjectName)
  58. cy.findByLabelText('Select a File').select('frog.jpg')
  59. cy.findByText('Create').click()
  60. })
  61. cy.findByTestId('file-tree').findByText('frog.jpg').click()
  62. cy.findByText('Another project')
  63. .should('have.attr', 'href')
  64. .then(href => {
  65. cy.get('@sourceProjectId').then(sourceProjectId => {
  66. expect(href).to.equal(`/project/${sourceProjectId}`)
  67. })
  68. })
  69. })
  70. it('can refresh linked files as collaborator', function () {
  71. const sourceProjectName = `test-project-${Date.now()}`
  72. const targetProjectName = `${sourceProjectName}-target`
  73. login('user@example.com')
  74. cy.visit('/project')
  75. createProject(sourceProjectName, { type: 'Example Project' }).as(
  76. 'sourceProjectId'
  77. )
  78. cy.visit('/project')
  79. createProject(targetProjectName).as('targetProjectId')
  80. // link the image from `projectName` into this project
  81. cy.findByText('New file').click({ force: true })
  82. cy.findByRole('dialog').within(() => {
  83. cy.findByText('From another project').click()
  84. cy.findByLabelText('Select a Project').select(sourceProjectName)
  85. cy.findByLabelText('Select a File').select('frog.jpg')
  86. cy.findByText('Create').click()
  87. })
  88. cy.findByText('Share').click()
  89. cy.findByRole('dialog').within(() => {
  90. cy.get('input').type('collaborator@example.com,')
  91. cy.findByText('Share').click({ force: true })
  92. })
  93. cy.visit('/project')
  94. cy.findByText('Account').click()
  95. cy.findByText('Log Out').click()
  96. login('collaborator@example.com')
  97. cy.visit('/project')
  98. cy.findByText(targetProjectName)
  99. .parent()
  100. .parent()
  101. .within(() => {
  102. cy.findByText('Join Project').click()
  103. })
  104. cy.findByText('Open Project').click()
  105. cy.url().should('match', /\/project\/[a-fA-F0-9]{24}/)
  106. cy.get('@targetProjectId').then(targetProjectId => {
  107. cy.url().should('include', targetProjectId)
  108. })
  109. cy.findByTestId('file-tree').findByText('frog.jpg').click()
  110. cy.findByText('Another project')
  111. .should('have.attr', 'href')
  112. .then(href => {
  113. cy.get('@sourceProjectId').then(sourceProjectId => {
  114. expect(href).to.equal(`/project/${sourceProjectId}`)
  115. })
  116. })
  117. })
  118. })