learn-wiki.spec.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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('navigation', { name: 'Primary' }).findByRole('menuitem', {
  24. name: 'Documentation',
  25. })
  26. })
  27. it('should display a tutorial link in the welcome page', function () {
  28. login(WITHOUT_PROJECTS_USER)
  29. cy.visit('/project')
  30. cy.findByRole('link', { name: LABEL_LEARN_LATEX }).should(
  31. 'have.attr',
  32. 'href',
  33. '/learn/latex/Learn_LaTeX_in_30_minutes'
  34. )
  35. })
  36. it('should render wiki page', function () {
  37. login(REGULAR_USER)
  38. cy.visit(UPLOADING_A_PROJECT_URL)
  39. cy.findByRole('heading', { name: 'Uploading a project' })
  40. cy.contains(/how to create an Overleaf project/)
  41. cy.findByRole('img', { name: 'Creating a new project on Overleaf' })
  42. .should('be.visible')
  43. .and((el: any) => {
  44. expect(el[0].naturalWidth, 'renders image').to.be.greaterThan(0)
  45. })
  46. cy.visit(COPYING_A_PROJECT_URL)
  47. cy.findByRole('heading', { name: 'Copying a project' })
  48. cy.findByRole('link', {
  49. name: '1 How to copy a project (option 1)',
  50. }).should('exist')
  51. cy.findByRole('link', {
  52. name: '2 How to copy a project (option 2)',
  53. }).should('exist')
  54. })
  55. it('should navigate within wiki page using table of contents', function () {
  56. login(REGULAR_USER)
  57. cy.visit(COPYING_A_PROJECT_URL)
  58. cy.findByRole('heading', { name: 'Copying a project' })
  59. cy.findByRole('link', {
  60. name: '2 How to copy a project (option 2)',
  61. }).click()
  62. cy.url().should('contain', COPYING_A_PROJECT_URL)
  63. cy.findByRole('heading', {
  64. name: 'How to copy a project (option 2)',
  65. }).should('be.visible')
  66. })
  67. })
  68. describe('disabled in Pro', function () {
  69. if (isExcludedBySharding('PRO_DEFAULT_1')) return
  70. startWith({ pro: true })
  71. checkDisabled()
  72. })
  73. describe('unavailable in CE', function () {
  74. if (isExcludedBySharding('CE_CUSTOM_1')) return
  75. startWith({
  76. pro: false,
  77. vars: {
  78. OVERLEAF_PROXY_LEARN: 'true',
  79. },
  80. })
  81. checkDisabled()
  82. })
  83. function checkDisabled() {
  84. it('should not add a documentation entry to the nav bar', function () {
  85. login(REGULAR_USER)
  86. cy.visit('/project')
  87. cy.findByRole('navigation', { name: 'Primary' })
  88. .findByRole('menuitem', {
  89. name: 'Documentation',
  90. })
  91. .should('not.exist')
  92. })
  93. it('should not render wiki page', function () {
  94. login(REGULAR_USER)
  95. cy.visit(COPYING_A_PROJECT_URL, {
  96. failOnStatusCode: false,
  97. })
  98. cy.findByRole('heading', { name: 'Not found' })
  99. })
  100. it('should not display a tutorial link in the welcome page', function () {
  101. login(WITHOUT_PROJECTS_USER)
  102. cy.visit('/project')
  103. cy.findByText(LABEL_LEARN_LATEX).should('not.exist')
  104. })
  105. }
  106. })