learn-wiki.spec.ts 2.9 KB

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