learn-wiki.spec.ts 3.7 KB

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