project-list.spec.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import { ensureUserExists, login } from './helpers/login'
  2. import { createProject } from './helpers/project'
  3. import { isExcludedBySharding, startWith } from './helpers/config'
  4. import { v4 as uuid } from 'uuid'
  5. const WITHOUT_PROJECTS_USER = 'user-without-projects@example.com'
  6. const REGULAR_USER = 'user@example.com'
  7. describe('Project List', function () {
  8. if (isExcludedBySharding('PRO_DEFAULT_2')) return
  9. startWith({ pro: true })
  10. const findProjectRow = (projectName: string) => {
  11. cy.log('find project row')
  12. return cy.findByText(projectName).parent().parent()
  13. }
  14. describe('user with no projects', function () {
  15. ensureUserExists({ email: WITHOUT_PROJECTS_USER })
  16. it("'Import from GitHub' is not displayed in the welcome page", function () {
  17. login(WITHOUT_PROJECTS_USER)
  18. cy.visit('/project')
  19. cy.findByRole('button', { name: 'Create a new project' }).click()
  20. cy.findByRole('menuitem', { name: 'Import from GitHub' }).should(
  21. 'not.exist'
  22. )
  23. })
  24. })
  25. describe('user with projects', function () {
  26. const projectName = `test-project-${uuid()}`
  27. ensureUserExists({ email: REGULAR_USER })
  28. before(function () {
  29. login(REGULAR_USER)
  30. createProject(projectName, { type: 'Example project', open: false })
  31. })
  32. beforeEach(function () {
  33. login(REGULAR_USER)
  34. cy.visit('/project')
  35. })
  36. it('Can download project sources', function () {
  37. findProjectRow(projectName).within(() =>
  38. cy.findByRole('button', { name: 'Download .zip file' }).click()
  39. )
  40. const zipName = projectName.replaceAll('-', '_')
  41. cy.task('readFileInZip', {
  42. pathToZip: `cypress/downloads/${zipName}.zip`,
  43. fileToRead: 'main.tex',
  44. }).should('contain', 'Your introduction goes here')
  45. })
  46. it('Can download project PDF', function () {
  47. findProjectRow(projectName).within(() =>
  48. cy.findByRole('button', { name: 'Download PDF' }).click()
  49. )
  50. const pdfName = projectName.replaceAll('-', '_')
  51. cy.task('readPdf', `cypress/downloads/${pdfName}.pdf`).should(
  52. 'contain',
  53. 'Your introduction goes here'
  54. )
  55. })
  56. it('can assign and remove tags to projects', function () {
  57. const tagName = uuid().slice(0, 7) // long tag names are truncated in the UI, which affects selectors
  58. cy.log('select project')
  59. cy.findByRole('checkbox', { name: `Select ${projectName}` }).check()
  60. cy.log('add tag to project')
  61. cy.findByRole('button', { name: 'Tags' }).click()
  62. cy.findByRole('menuitem', { name: 'Create new tag' }).click()
  63. cy.findByRole('dialog').within(() => {
  64. cy.findByRole('heading', { name: 'Create new tag' })
  65. cy.findByLabelText('New tag name').type(`${tagName}{enter}`)
  66. })
  67. cy.findByRole('button', { name: `Select tag ${tagName}` }) // tag label in project row
  68. cy.log('remove tag')
  69. cy.findByRole('button', { name: `Remove tag ${tagName}` })
  70. .first()
  71. .click()
  72. cy.findByRole('button', { name: `Select tag ${tagName}` }).should(
  73. 'not.exist'
  74. )
  75. })
  76. it('can filter by tag', function () {
  77. cy.log('create a separate project to filter')
  78. const nonTaggedProjectName = `project-${uuid()}`
  79. createProject(nonTaggedProjectName, { open: false })
  80. cy.log('select project')
  81. cy.findByRole('checkbox', { name: `Select ${projectName}` }).check()
  82. cy.log('add tag to project')
  83. const tagName = uuid().slice(0, 7) // long tag names are truncated in the UI, which affects selectors
  84. cy.findByRole('button', { name: 'Tags' }).click()
  85. cy.findByRole('menuitem', { name: 'Create new tag' }).click()
  86. cy.findByRole('dialog').within(() => {
  87. cy.findByRole('heading', { name: 'Create new tag' })
  88. cy.findByLabelText('New tag name').type(`${tagName}{enter}`)
  89. })
  90. cy.log(
  91. 'check the non-tagged project is filtered out after clicking the tag'
  92. )
  93. cy.findByRole('link', { name: nonTaggedProjectName }).should('exist')
  94. cy.findByRole('button', { name: `Select tag ${tagName}` }).click()
  95. cy.findByRole('link', { name: nonTaggedProjectName }).should('not.exist')
  96. })
  97. })
  98. })