learn-wiki.spec.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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.get('nav').findByText('Documentation')
  25. })
  26. it('should display a tutorial link in the welcome page', () => {
  27. login(WITHOUT_PROJECTS_USER)
  28. cy.visit('/project')
  29. cy.findByText(LABEL_LEARN_LATEX)
  30. })
  31. it('should render wiki page', () => {
  32. login(REGULAR_USER)
  33. cy.visit(UPLOADING_A_PROJECT_URL)
  34. // Wiki content
  35. cy.get('.page').findByText('Uploading a project')
  36. cy.get('.page').contains(/how to create an Overleaf project/)
  37. cy.get('img[alt="Creating a new project on Overleaf"]')
  38. .should('be.visible')
  39. .and((el: any) => {
  40. expect(el[0].naturalWidth, 'renders image').to.be.greaterThan(0)
  41. })
  42. // Wiki navigation
  43. cy.get('.contents').findByText('Copying a project')
  44. })
  45. it('should navigate back and forth', function () {
  46. login(REGULAR_USER)
  47. cy.visit(COPYING_A_PROJECT_URL)
  48. cy.get('.page').findByText('Copying a project')
  49. cy.get('.contents').findByText('Uploading a project').click()
  50. cy.url().should('contain', UPLOADING_A_PROJECT_URL)
  51. cy.get('.page').findByText('Uploading a project')
  52. cy.get('.contents').findByText('Copying a project').click()
  53. cy.url().should('contain', COPYING_A_PROJECT_URL)
  54. cy.get('.page').findByText('Copying a project')
  55. })
  56. })
  57. describe('disabled in Pro', () => {
  58. if (isExcludedBySharding('PRO_DEFAULT_1')) return
  59. startWith({ pro: true })
  60. checkDisabled()
  61. })
  62. describe('unavailable in CE', () => {
  63. if (isExcludedBySharding('CE_CUSTOM_1')) return
  64. startWith({
  65. pro: false,
  66. vars: {
  67. OVERLEAF_PROXY_LEARN: 'true',
  68. },
  69. })
  70. checkDisabled()
  71. })
  72. function checkDisabled() {
  73. it('should not add a documentation entry to the nav bar', () => {
  74. login(REGULAR_USER)
  75. cy.visit('/project')
  76. cy.findByText('Documentation').should('not.exist')
  77. })
  78. it('should not render wiki page', () => {
  79. login(REGULAR_USER)
  80. cy.visit(COPYING_A_PROJECT_URL, {
  81. failOnStatusCode: false,
  82. })
  83. cy.findByText('Not found')
  84. })
  85. it('should not display a tutorial link in the welcome page', () => {
  86. login(WITHOUT_PROJECTS_USER)
  87. cy.visit('/project')
  88. cy.findByText(LABEL_LEARN_LATEX).should('not.exist')
  89. })
  90. }
  91. })