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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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').parent().click()
  11. cy.findByText('\\maketitle').parent().type('\n\\section{{}Test Section}')
  12. // Wait for the PDF compilation throttling
  13. // eslint-disable-next-line cypress/no-unnecessary-waiting
  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. cy.findByTestId('file-tree').findByText('frog.jpg').click()
  59. cy.findByText('Another project')
  60. .should('have.attr', 'href')
  61. .then(href => {
  62. cy.get('@sourceProjectId').then(sourceProjectId => {
  63. expect(href).to.equal(`/project/${sourceProjectId}`)
  64. })
  65. })
  66. })
  67. it('can refresh linked files as collaborator', function () {
  68. const sourceProjectName = `test-project-${Date.now()}`
  69. const targetProjectName = `${sourceProjectName}-target`
  70. login('user@example.com')
  71. cy.visit('/project')
  72. createProject(sourceProjectName, { type: 'Example Project' }).as(
  73. 'sourceProjectId'
  74. )
  75. cy.visit('/project')
  76. createProject(targetProjectName).as('targetProjectId')
  77. // link the image from `projectName` into this project
  78. cy.findByText('New File').click({ force: true })
  79. cy.findByRole('dialog').within(() => {
  80. cy.findByText('From Another Project').click()
  81. cy.findByLabelText('Select a Project').select(sourceProjectName)
  82. cy.findByLabelText('Select a File').select('frog.jpg')
  83. cy.findByText('Create').click()
  84. })
  85. cy.findByText('Share').click()
  86. cy.findByRole('dialog').within(() => {
  87. cy.get('input').type('collaborator@example.com,')
  88. cy.findByText('Share').click({ force: true })
  89. })
  90. cy.visit('/project')
  91. cy.findByText('Account').click()
  92. cy.findByText('Log Out').click()
  93. login('collaborator@example.com')
  94. cy.visit('/project')
  95. // FIXME: Should have data-test-id
  96. cy.findByText(targetProjectName)
  97. .parent()
  98. .parent()
  99. .find('button.btn-info')
  100. .click()
  101. cy.findByText('Open Project').click()
  102. cy.url().should('match', /\/project\/[a-fA-F0-9]{24}/)
  103. cy.get('@targetProjectId').then(targetProjectId => {
  104. cy.url().should('include', targetProjectId)
  105. })
  106. cy.findByTestId('file-tree').findByText('frog.jpg').click()
  107. cy.findByText('Another project')
  108. .should('have.attr', 'href')
  109. .then(href => {
  110. cy.get('@sourceProjectId').then(sourceProjectId => {
  111. expect(href).to.equal(`/project/${sourceProjectId}`)
  112. })
  113. })
  114. })
  115. })