project-list.spec.ts 3.7 KB

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