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

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