learn-wiki.spec.ts 3.7 KB

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