project-list.spec.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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', () => {
  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', () => {
  15. ensureUserExists({ email: WITHOUT_PROJECTS_USER })
  16. it("'Import from Github' is not displayed in the welcome page", () => {
  17. login(WITHOUT_PROJECTS_USER)
  18. cy.visit('/project')
  19. cy.findByText('Create a new project').click()
  20. cy.findByText(/Import from Github/i).should('not.exist')
  21. })
  22. })
  23. describe('user with projects', () => {
  24. const projectName = `test-project-${uuid()}`
  25. ensureUserExists({ email: REGULAR_USER })
  26. before(() => {
  27. login(REGULAR_USER)
  28. createProject(projectName, { type: 'Example Project' })
  29. })
  30. it('Can download project sources', () => {
  31. login(REGULAR_USER)
  32. cy.visit('/project')
  33. findProjectRow(projectName).within(() =>
  34. cy.findByRole('button', { name: 'Download .zip file' }).click()
  35. )
  36. cy.task('readFileInZip', {
  37. pathToZip: `cypress/downloads/${projectName}.zip`,
  38. fileToRead: 'main.tex',
  39. }).should('contain', 'Your introduction goes here')
  40. })
  41. it('Can download project PDF', () => {
  42. login(REGULAR_USER)
  43. cy.visit('/project')
  44. findProjectRow(projectName).within(() =>
  45. cy.findByRole('button', { name: 'Download PDF' }).click()
  46. )
  47. const pdfName = projectName.replaceAll('-', '_')
  48. cy.task('readPdf', `cypress/downloads/${pdfName}.pdf`).should(
  49. 'contain',
  50. 'Your introduction goes here'
  51. )
  52. })
  53. it('can assign and remove tags to projects', () => {
  54. const tagName = uuid().slice(0, 7) // long tag names are truncated in the UI, which affects selectors
  55. login(REGULAR_USER)
  56. cy.visit('/project')
  57. cy.log('select project')
  58. cy.get(`[aria-label="Select ${projectName}"]`).click()
  59. cy.log('add tag to project')
  60. cy.get('button[aria-label="Tags"]').click()
  61. cy.findByText('Create new tag').click()
  62. cy.get('input[name="new-tag-form-name"]').type(`${tagName}{enter}`)
  63. cy.get(`button[aria-label="Select tag ${tagName}"]`) // tag label in project row
  64. cy.log('remove tag')
  65. cy.get(`button[aria-label="Remove tag ${tagName}"]`)
  66. .first()
  67. .click({ force: true })
  68. cy.get(`button[aria-label="Select tag ${tagName}"]`).should('not.exist')
  69. })
  70. it('can filter by tag', () => {
  71. cy.log('create a separate project to filter')
  72. const nonTaggedProjectName = `project-${uuid()}`
  73. login(REGULAR_USER)
  74. createProject(nonTaggedProjectName)
  75. cy.visit('/project')
  76. cy.log('select project')
  77. cy.get(`[aria-label="Select ${projectName}"]`).click()
  78. cy.log('add tag to project')
  79. const tagName = uuid().slice(0, 7) // long tag names are truncated in the UI, which affects selectors
  80. cy.get('button[aria-label="Tags"]').click()
  81. cy.findByText('Create new tag').click()
  82. cy.get('input[name="new-tag-form-name"]').type(`${tagName}{enter}`)
  83. cy.log(
  84. 'check the non-tagged project is filtered out after clicking the tag'
  85. )
  86. cy.findByText(nonTaggedProjectName).should('exist')
  87. cy.get('button').contains(tagName).click({ force: true })
  88. cy.findByText(nonTaggedProjectName).should('not.exist')
  89. })
  90. })
  91. })