learn-wiki.spec.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import { isExcludedBySharding, startWith } from './helpers/config'
  2. import { ensureUserExists, login } from './helpers/login'
  3. import { v4 as uuid } from 'uuid'
  4. describe('LearnWiki', function () {
  5. const COPYING_A_PROJECT_URL = '/learn/how-to/Copying_a_project'
  6. const UPLOADING_A_PROJECT_URL = '/learn/how-to/Uploading_a_project'
  7. const WITHOUT_PROJECTS_USER = 'user-without-projects@example.com'
  8. const REGULAR_USER = 'user@example.com'
  9. // Re-use value for "exists" and "does not exist" tests
  10. const LABEL_LEARN_LATEX = 'Learn LaTeX with a tutorial'
  11. ensureUserExists({ email: WITHOUT_PROJECTS_USER })
  12. ensureUserExists({ email: REGULAR_USER })
  13. describe('enabled in Pro', () => {
  14. if (isExcludedBySharding('PRO_CUSTOM_2')) return
  15. startWith({
  16. pro: true,
  17. vars: {
  18. OVERLEAF_PROXY_LEARN: 'true',
  19. },
  20. })
  21. it('should add a documentation entry to the nav bar', () => {
  22. login(REGULAR_USER)
  23. cy.visit('/project')
  24. cy.findByRole('menuitem', { name: 'Documentation' }).should(
  25. 'have.attr',
  26. 'href',
  27. '/learn'
  28. )
  29. })
  30. it('should display a tutorial link in the welcome page', () => {
  31. login(WITHOUT_PROJECTS_USER)
  32. cy.visit('/project')
  33. cy.findByRole('link', { name: LABEL_LEARN_LATEX })
  34. .should('have.attr', 'href', '/learn/latex/Learn_LaTeX_in_30_minutes')
  35. .and('have.attr', 'target', '_blank')
  36. .within(() => {
  37. cy.get('img').should('have.attr', 'src').and('not.be.empty')
  38. })
  39. })
  40. it('should render wiki page', () => {
  41. login(REGULAR_USER)
  42. cy.visit(UPLOADING_A_PROJECT_URL)
  43. // Wiki content
  44. cy.findByRole('heading', { name: 'Uploading a project' })
  45. cy.contains(/how to create an Overleaf project/)
  46. cy.findByRole('img', { name: 'Creating a new project on Overleaf' })
  47. .should('be.visible')
  48. .and((el: any) => {
  49. expect(el[0].naturalWidth, 'renders image').to.be.greaterThan(0)
  50. })
  51. // Wiki navigation
  52. cy.findByRole('link', { name: 'Copying a project' }).should('exist')
  53. })
  54. it('should navigate back and forth', function () {
  55. login(REGULAR_USER)
  56. cy.visit(COPYING_A_PROJECT_URL)
  57. cy.findByRole('heading', { name: 'Copying a project' })
  58. cy.findByRole('link', { name: 'Uploading a project' }).click()
  59. cy.url().should('contain', UPLOADING_A_PROJECT_URL)
  60. cy.findByRole('heading', { name: 'Uploading a project' })
  61. cy.findByRole('link', { name: 'Copying a project' }).click()
  62. cy.url().should('contain', COPYING_A_PROJECT_URL)
  63. cy.findByRole('heading', { name: 'Copying a project' })
  64. })
  65. })
  66. describe('disabled in Pro', () => {
  67. if (isExcludedBySharding('PRO_DEFAULT_1')) return
  68. startWith({ pro: true })
  69. checkDisabled()
  70. })
  71. describe('unavailable in CE', () => {
  72. if (isExcludedBySharding('CE_CUSTOM_1')) return
  73. startWith({
  74. pro: false,
  75. vars: {
  76. OVERLEAF_PROXY_LEARN: 'true',
  77. },
  78. })
  79. checkDisabled()
  80. })
  81. function checkDisabled() {
  82. it('should not add a documentation entry to the nav bar', () => {
  83. login(REGULAR_USER)
  84. cy.visit('/project')
  85. cy.findByText('Documentation').should('not.exist')
  86. })
  87. it('should not render wiki page', () => {
  88. login(REGULAR_USER)
  89. cy.visit(COPYING_A_PROJECT_URL, {
  90. failOnStatusCode: false,
  91. })
  92. cy.findByText('Not found')
  93. })
  94. it('should not display a tutorial link in the welcome page', () => {
  95. login(WITHOUT_PROJECTS_USER)
  96. cy.visit('/project')
  97. cy.findByText(LABEL_LEARN_LATEX).should('not.exist')
  98. })
  99. }
  100. })