NewLogsUITests.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. const SandboxedModule = require('sandboxed-module')
  2. const { expect } = require('chai')
  3. const { ObjectId } = require('mongodb')
  4. const MODULE_PATH = require('path').join(
  5. __dirname,
  6. '../../../../app/src/Features/Helpers/NewLogsUI.js'
  7. )
  8. describe('NewLogsUI helper', function () {
  9. let NewLogsUI
  10. before(function () {
  11. // We're disabling the Logs UI split test while rolling out the PDF Preview
  12. this.skip()
  13. })
  14. function userIdFromTime(time) {
  15. return ObjectId.createFromTime(time).toString()
  16. }
  17. function isExistingUI(variant) {
  18. return !variant.newLogsUI && !variant.subvariant
  19. }
  20. function isNewUIWithPopup(variant) {
  21. return variant.newLogsUI && variant.subvariant === 'new-logs-ui-with-popup'
  22. }
  23. function isNewUIWithoutPopup(variant) {
  24. return (
  25. variant.newLogsUI && variant.subvariant === 'new-logs-ui-without-popup'
  26. )
  27. }
  28. function getTestInterval(lowerBoundary, upperBoundary) {
  29. const midpoint = Math.floor(
  30. lowerBoundary + (upperBoundary - lowerBoundary) / 2
  31. )
  32. return [lowerBoundary, midpoint, upperBoundary]
  33. }
  34. beforeEach(function () {
  35. this.user = {
  36. alphaProgram: false,
  37. _id: ObjectId('60085414b76eeb00737d93aa'),
  38. }
  39. this.settings = {
  40. overleaf: {
  41. foo: 'bar',
  42. },
  43. }
  44. NewLogsUI = SandboxedModule.require(MODULE_PATH, {
  45. requires: {
  46. mongodb: { ObjectId },
  47. '@overleaf/settings': this.settings,
  48. },
  49. })
  50. })
  51. describe('In a non-SaaS context', function () {
  52. beforeEach(function () {
  53. delete this.settings.overleaf
  54. })
  55. it('should always show the existing UI', function () {
  56. for (const percentile of [0, 20, 40, 60, 80]) {
  57. this.user._id = userIdFromTime(percentile)
  58. const variant = NewLogsUI.getNewLogsUIVariantForUser(this.user)
  59. expect(isExistingUI(variant)).to.be.true
  60. }
  61. })
  62. })
  63. describe('For alpha users', function () {
  64. beforeEach(function () {
  65. this.user.alphaProgram = true
  66. })
  67. it('should always show the new UI with popup', function () {
  68. for (const percentile of [0, 20, 40, 60, 80]) {
  69. this.user._id = userIdFromTime(percentile)
  70. const variant = NewLogsUI.getNewLogsUIVariantForUser(this.user)
  71. expect(isNewUIWithPopup(variant)).to.be.true
  72. }
  73. })
  74. })
  75. describe('For regular users', function () {
  76. it('should show the new UI with popup when the id is in the [0, 5[ interval', function () {
  77. const testInterval = getTestInterval(0, 4)
  78. for (const percentile of testInterval) {
  79. this.user._id = userIdFromTime(percentile)
  80. const variant = NewLogsUI.getNewLogsUIVariantForUser(this.user)
  81. expect(isNewUIWithPopup(variant)).to.be.true
  82. }
  83. this.user._id = userIdFromTime(5)
  84. const variant = NewLogsUI.getNewLogsUIVariantForUser(this.user)
  85. expect(isNewUIWithPopup(variant)).to.be.false
  86. })
  87. it('should show the new UI without popup when the id is in the [5, 10[ interval', function () {
  88. const testInterval = getTestInterval(5, 9)
  89. for (const percentile of testInterval) {
  90. this.user._id = userIdFromTime(percentile)
  91. const variant = NewLogsUI.getNewLogsUIVariantForUser(this.user)
  92. expect(isNewUIWithoutPopup(variant)).to.be.true
  93. }
  94. this.user._id = userIdFromTime(10)
  95. const variant = NewLogsUI.getNewLogsUIVariantForUser(this.user)
  96. expect(isNewUIWithoutPopup(variant)).to.be.false
  97. })
  98. it('should show the new UI with popup when the id is in the [10, 38[ interval', function () {
  99. const testInterval = getTestInterval(10, 37)
  100. for (const percentile of testInterval) {
  101. this.user._id = userIdFromTime(percentile)
  102. const variant = NewLogsUI.getNewLogsUIVariantForUser(this.user)
  103. expect(isNewUIWithPopup(variant)).to.be.true
  104. }
  105. this.user._id = userIdFromTime(38)
  106. const variant = NewLogsUI.getNewLogsUIVariantForUser(this.user)
  107. expect(isNewUIWithPopup(variant)).to.be.false
  108. })
  109. it('should show the new UI without popup when the id is in the [38, 66[ interval', function () {
  110. const testInterval = getTestInterval(38, 65)
  111. for (const percentile of testInterval) {
  112. this.user._id = userIdFromTime(percentile)
  113. const variant = NewLogsUI.getNewLogsUIVariantForUser(this.user)
  114. expect(isNewUIWithoutPopup(variant)).to.be.true
  115. }
  116. this.user._id = userIdFromTime(66)
  117. const variant = NewLogsUI.getNewLogsUIVariantForUser(this.user)
  118. expect(isNewUIWithoutPopup(variant)).to.be.false
  119. })
  120. it('should show the existing UI when the id is in the [66, 99] interval', function () {
  121. const testInterval = getTestInterval(66, 99)
  122. for (const percentile of testInterval) {
  123. this.user._id = userIdFromTime(percentile)
  124. const variant = NewLogsUI.getNewLogsUIVariantForUser(this.user)
  125. expect(isExistingUI(variant)).to.be.true
  126. }
  127. this.user._id = userIdFromTime(100)
  128. const variant = NewLogsUI.getNewLogsUIVariantForUser(this.user)
  129. expect(isExistingUI(variant)).to.be.false
  130. })
  131. })
  132. })