learn-wiki.spec.ts 3.0 KB

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