project-list.spec.ts 3.7 KB

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