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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. import { login } from './helpers/login'
  2. import { createProject } from './helpers/project'
  3. describe('Project creation and compilation', function () {
  4. it('users can create project and compile it', function () {
  5. login('user@example.com')
  6. cy.visit('/project')
  7. // this is the first project created, the welcome screen is displayed instead of the project list
  8. createProject('test-project', { isFirstProject: true })
  9. cy.url().should('match', /\/project\/[a-fA-F0-9]{24}/)
  10. cy.findByText('\\maketitle')
  11. .parent()
  12. .click()
  13. .type('\n\\section{{}Test Section}')
  14. // Wait for the PDF compilation throttling
  15. cy.wait(3000)
  16. cy.findByText('Recompile').click()
  17. cy.get('.pdf-viewer').should('contain.text', 'Test Section')
  18. })
  19. it('create and edit markdown file', function () {
  20. const fileName = `test-${Date.now()}.md`
  21. const markdownContent = '# Markdown title'
  22. login('user@example.com')
  23. cy.visit('/project')
  24. createProject('test-project')
  25. // FIXME: Add aria-label maybe? or at least data-test-id
  26. cy.findByText('New File').click({ force: true })
  27. cy.findByRole('dialog').within(() => {
  28. cy.get('input').clear()
  29. cy.get('input').type(fileName)
  30. cy.findByText('Create').click()
  31. })
  32. cy.findByText(fileName).click()
  33. // wait until we've switched to the newly created empty file
  34. cy.get('.cm-line').should('have.length', 1)
  35. cy.get('.cm-line').type(markdownContent)
  36. cy.findByText('main.tex').click()
  37. cy.get('.cm-content').should('contain.text', '\\maketitle')
  38. cy.findByText(fileName).click()
  39. cy.get('.cm-content').should('contain.text', markdownContent)
  40. })
  41. it('can link and display linked image from other project', function () {
  42. const sourceProjectName = `test-project-${Date.now()}`
  43. const targetProjectName = `${sourceProjectName}-target`
  44. login('user@example.com')
  45. cy.visit('/project')
  46. createProject(sourceProjectName, { type: 'Example Project' }).as(
  47. 'sourceProjectId'
  48. )
  49. cy.visit('/project')
  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. // FIXME: should be aria-labeled or data-test-id
  60. cy.get('.file-tree').within(() => {
  61. cy.findByText('frog.jpg').click()
  62. })
  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. // FIXME: Open an issue for this.
  93. cy.get('button[type="submit"]').click({ force: true })
  94. cy.get('button[type="submit"]').click({ force: true })
  95. })
  96. cy.visit('/project')
  97. cy.findByText('Account').click()
  98. cy.findByText('Log Out').click()
  99. login('collaborator@example.com')
  100. cy.visit('/project')
  101. // FIXME: Should have data-test-id
  102. cy.findByText(targetProjectName)
  103. .parent()
  104. .parent()
  105. .find('button.btn-info')
  106. .click()
  107. cy.findByText('Open Project').click()
  108. cy.url().should('match', /\/project\/[a-fA-F0-9]{24}/)
  109. cy.get('@targetProjectId').then(targetProjectId => {
  110. cy.url().should('include', targetProjectId)
  111. })
  112. cy.get('.file-tree').within(() => {
  113. cy.findByText('frog.jpg').click()
  114. })
  115. cy.findByText('Another project')
  116. .should('have.attr', 'href')
  117. .then(href => {
  118. cy.get('@sourceProjectId').then(sourceProjectId => {
  119. expect(href).to.equal(`/project/${sourceProjectId}`)
  120. })
  121. })
  122. })
  123. })