mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-31 04:41:32 +02:00
Merge pull request #3495 from overleaf/ae-prettier-2
Upgrade Prettier to v2 GitOrigin-RevId: 85aa3fa1acb6332c4f58c46165a43d1a51471f33
This commit is contained in:
@@ -2,8 +2,8 @@ const SandboxedModule = require('sandboxed-module')
|
||||
const { expect } = require('chai')
|
||||
const modulePath = '../../../../app/src/Features/Helpers/AuthorizationHelper'
|
||||
|
||||
describe('AuthorizationHelper', function() {
|
||||
beforeEach(function() {
|
||||
describe('AuthorizationHelper', function () {
|
||||
beforeEach(function () {
|
||||
this.AuthorizationHelper = SandboxedModule.require(modulePath, {
|
||||
requires: {
|
||||
'../../models/User': {
|
||||
@@ -25,28 +25,28 @@ describe('AuthorizationHelper', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('hasAnyStaffAccess', function() {
|
||||
it('with empty user', function() {
|
||||
describe('hasAnyStaffAccess', function () {
|
||||
it('with empty user', function () {
|
||||
const user = {}
|
||||
expect(this.AuthorizationHelper.hasAnyStaffAccess(user)).to.be.false
|
||||
})
|
||||
|
||||
it('with no access user', function() {
|
||||
it('with no access user', function () {
|
||||
const user = { isAdmin: false, staffAccess: { adminMetrics: false } }
|
||||
expect(this.AuthorizationHelper.hasAnyStaffAccess(user)).to.be.false
|
||||
})
|
||||
|
||||
it('with admin user', function() {
|
||||
it('with admin user', function () {
|
||||
const user = { isAdmin: true }
|
||||
expect(this.AuthorizationHelper.hasAnyStaffAccess(user)).to.be.true
|
||||
})
|
||||
|
||||
it('with staff user', function() {
|
||||
it('with staff user', function () {
|
||||
const user = { staffAccess: { adminMetrics: true, somethingElse: false } }
|
||||
expect(this.AuthorizationHelper.hasAnyStaffAccess(user)).to.be.true
|
||||
})
|
||||
|
||||
it('with non-staff user with extra attributes', function() {
|
||||
it('with non-staff user with extra attributes', function () {
|
||||
// make sure that staffAccess attributes not declared on the model don't
|
||||
// give user access
|
||||
const user = { staffAccess: { adminMetrics: false, somethingElse: true } }
|
||||
|
||||
@@ -6,7 +6,7 @@ const MODULE_PATH = require('path').join(
|
||||
'../../../../app/src/Features/Helpers/NewLogsUI.js'
|
||||
)
|
||||
|
||||
describe('NewLogsUI helper', function() {
|
||||
describe('NewLogsUI helper', function () {
|
||||
let NewLogsUI
|
||||
|
||||
function userIdFromTime(time) {
|
||||
@@ -27,7 +27,7 @@ describe('NewLogsUI helper', function() {
|
||||
)
|
||||
}
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
this.user = {
|
||||
alphaProgram: false,
|
||||
betaProgram: false,
|
||||
@@ -47,7 +47,7 @@ describe('NewLogsUI helper', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('should always show the new UI with popup for alpha users', function() {
|
||||
it('should always show the new UI with popup for alpha users', function () {
|
||||
this.user.alphaProgram = true
|
||||
for (const percentile of [0, 20, 40, 60, 80]) {
|
||||
this.user._id = userIdFromTime(percentile)
|
||||
@@ -56,13 +56,13 @@ describe('NewLogsUI helper', function() {
|
||||
}
|
||||
})
|
||||
|
||||
describe('for beta users', function() {
|
||||
beforeEach(function() {
|
||||
describe('for beta users', function () {
|
||||
beforeEach(function () {
|
||||
this.user.betaProgram = true
|
||||
})
|
||||
|
||||
describe('with a 0% rollout', function() {
|
||||
it('should always show the existing UI', function() {
|
||||
describe('with a 0% rollout', function () {
|
||||
it('should always show the existing UI', function () {
|
||||
for (const percentile of [0, 20, 40, 60, 80]) {
|
||||
this.user._id = userIdFromTime(percentile)
|
||||
const variant = NewLogsUI.getNewLogsUIVariantForUser(this.user)
|
||||
@@ -71,7 +71,7 @@ describe('NewLogsUI helper', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('with a new UI rollout', function() {
|
||||
describe('with a new UI rollout', function () {
|
||||
const newUIWithPopupPercentage = 33
|
||||
const newUIWithoutPopupPercentage = 33
|
||||
|
||||
@@ -79,31 +79,31 @@ describe('NewLogsUI helper', function() {
|
||||
const newUIWithoutPopupThreshold =
|
||||
newUIWithPopupPercentage + newUIWithoutPopupPercentage
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
this.settings.logsUIPercentageBeta = newUIWithPopupPercentage
|
||||
this.settings.logsUIPercentageWithoutPopupBeta = newUIWithoutPopupPercentage
|
||||
})
|
||||
it('should show the new UI with popup when the id is below the new UI with popup upper threshold (exc)', function() {
|
||||
it('should show the new UI with popup when the id is below the new UI with popup upper threshold (exc)', function () {
|
||||
this.user._id = userIdFromTime(newUIWithPopupThreshold - 1)
|
||||
const variant = NewLogsUI.getNewLogsUIVariantForUser(this.user)
|
||||
expect(isNewUIWithPopup(variant)).to.be.true
|
||||
})
|
||||
it('should show the new UI without popup when the id is at the new UI with popup upper threshold (exc)', function() {
|
||||
it('should show the new UI without popup when the id is at the new UI with popup upper threshold (exc)', function () {
|
||||
this.user._id = userIdFromTime(newUIWithPopupThreshold)
|
||||
const variant = NewLogsUI.getNewLogsUIVariantForUser(this.user)
|
||||
expect(isNewUIWithoutPopup(variant)).to.be.true
|
||||
})
|
||||
it('should show the new UI without popup when the id is above the new UI with popup upper threshold (inc) and below the new UI without popup upper threshold (exc)', function() {
|
||||
it('should show the new UI without popup when the id is above the new UI with popup upper threshold (inc) and below the new UI without popup upper threshold (exc)', function () {
|
||||
this.user._id = userIdFromTime(newUIWithoutPopupThreshold - 1)
|
||||
const variant = NewLogsUI.getNewLogsUIVariantForUser(this.user)
|
||||
expect(isNewUIWithoutPopup(variant)).to.be.true
|
||||
})
|
||||
it('should show the existing UI when the id is at the new UI without popup upper threshold (exc)', function() {
|
||||
it('should show the existing UI when the id is at the new UI without popup upper threshold (exc)', function () {
|
||||
this.user._id = userIdFromTime(newUIWithoutPopupThreshold)
|
||||
const variant = NewLogsUI.getNewLogsUIVariantForUser(this.user)
|
||||
expect(isExistingUI(variant)).to.be.true
|
||||
})
|
||||
it('should show the existing UI when the id is above the new UI without popup upper threshold (exc)', function() {
|
||||
it('should show the existing UI when the id is above the new UI without popup upper threshold (exc)', function () {
|
||||
this.user._id = userIdFromTime(newUIWithoutPopupThreshold + 1)
|
||||
const variant = NewLogsUI.getNewLogsUIVariantForUser(this.user)
|
||||
expect(isExistingUI(variant)).to.be.true
|
||||
@@ -111,9 +111,9 @@ describe('NewLogsUI helper', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('for regular users', function() {
|
||||
describe('with a 0% rollout', function() {
|
||||
it('should always show the existing UI', function() {
|
||||
describe('for regular users', function () {
|
||||
describe('with a 0% rollout', function () {
|
||||
it('should always show the existing UI', function () {
|
||||
for (const percentile of [0, 20, 40, 60, 80]) {
|
||||
this.user._id = userIdFromTime(percentile)
|
||||
const variant = NewLogsUI.getNewLogsUIVariantForUser(this.user)
|
||||
@@ -122,7 +122,7 @@ describe('NewLogsUI helper', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('with a new UI rollout', function() {
|
||||
describe('with a new UI rollout', function () {
|
||||
const newUIWithPopupPercentage = 33
|
||||
const newUIWithoutPopupPercentage = 33
|
||||
|
||||
@@ -130,31 +130,31 @@ describe('NewLogsUI helper', function() {
|
||||
const newUIWithoutPopupThreshold =
|
||||
newUIWithPopupPercentage + newUIWithoutPopupPercentage
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
this.settings.logsUIPercentage = newUIWithPopupPercentage
|
||||
this.settings.logsUIPercentageWithoutPopup = newUIWithoutPopupPercentage
|
||||
})
|
||||
it('should show the new UI with popup when the id is below the new UI with popup upper threshold (exc)', function() {
|
||||
it('should show the new UI with popup when the id is below the new UI with popup upper threshold (exc)', function () {
|
||||
this.user._id = userIdFromTime(newUIWithPopupThreshold - 1)
|
||||
const variant = NewLogsUI.getNewLogsUIVariantForUser(this.user)
|
||||
expect(isNewUIWithPopup(variant)).to.be.true
|
||||
})
|
||||
it('should show the new UI without popup when the id is at the new UI with popup upper threshold (exc)', function() {
|
||||
it('should show the new UI without popup when the id is at the new UI with popup upper threshold (exc)', function () {
|
||||
this.user._id = userIdFromTime(newUIWithPopupThreshold)
|
||||
const variant = NewLogsUI.getNewLogsUIVariantForUser(this.user)
|
||||
expect(isNewUIWithoutPopup(variant)).to.be.true
|
||||
})
|
||||
it('should show the new UI without popup when the id is above the new UI with popup upper threshold (inc) and below the new UI without popup upper threshold (exc)', function() {
|
||||
it('should show the new UI without popup when the id is above the new UI with popup upper threshold (inc) and below the new UI without popup upper threshold (exc)', function () {
|
||||
this.user._id = userIdFromTime(newUIWithoutPopupThreshold - 1)
|
||||
const variant = NewLogsUI.getNewLogsUIVariantForUser(this.user)
|
||||
expect(isNewUIWithoutPopup(variant)).to.be.true
|
||||
})
|
||||
it('should show the existing UI when the id is at the new UI without popup upper threshold (exc)', function() {
|
||||
it('should show the existing UI when the id is at the new UI without popup upper threshold (exc)', function () {
|
||||
this.user._id = userIdFromTime(newUIWithoutPopupThreshold)
|
||||
const variant = NewLogsUI.getNewLogsUIVariantForUser(this.user)
|
||||
expect(isExistingUI(variant)).to.be.true
|
||||
})
|
||||
it('should show the existing UI when the id is above the new UI without popup upper threshold (exc)', function() {
|
||||
it('should show the existing UI when the id is above the new UI without popup upper threshold (exc)', function () {
|
||||
this.user._id = userIdFromTime(newUIWithoutPopupThreshold + 1)
|
||||
const variant = NewLogsUI.getNewLogsUIVariantForUser(this.user)
|
||||
expect(isExistingUI(variant)).to.be.true
|
||||
|
||||
@@ -5,13 +5,13 @@ const MODULE_PATH = require('path').join(
|
||||
'../../../../app/src/Features/Helpers/SafeHTMLSubstitution.js'
|
||||
)
|
||||
|
||||
describe('SafeHTMLSubstitution', function() {
|
||||
describe('SafeHTMLSubstitution', function () {
|
||||
let SafeHTMLSubstitution
|
||||
before(function() {
|
||||
before(function () {
|
||||
SafeHTMLSubstitution = SandboxedModule.require(MODULE_PATH)
|
||||
})
|
||||
|
||||
describe('SPLIT_REGEX', function() {
|
||||
describe('SPLIT_REGEX', function () {
|
||||
const CASES = {
|
||||
'PRE<0>INNER</0>POST': ['PRE', '0', 'INNER', 'POST'],
|
||||
'<0>INNER</0>': ['', '0', 'INNER', ''],
|
||||
@@ -21,7 +21,7 @@ describe('SafeHTMLSubstitution', function() {
|
||||
'PLAIN TEXT': ['PLAIN TEXT']
|
||||
}
|
||||
Object.entries(CASES).forEach(([input, output]) => {
|
||||
it(`should parse "${input}" as expected`, function() {
|
||||
it(`should parse "${input}" as expected`, function () {
|
||||
expect(input.split(SafeHTMLSubstitution.SPLIT_REGEX)).to.deep.equal(
|
||||
output
|
||||
)
|
||||
@@ -29,27 +29,27 @@ describe('SafeHTMLSubstitution', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('render', function() {
|
||||
describe('substitution', function() {
|
||||
it('should substitute a single component', function() {
|
||||
describe('render', function () {
|
||||
describe('substitution', function () {
|
||||
it('should substitute a single component', function () {
|
||||
expect(
|
||||
SafeHTMLSubstitution.render('<0>good</0>', [{ name: 'b' }])
|
||||
).to.equal('<b>good</b>')
|
||||
})
|
||||
|
||||
it('should substitute a single component as string', function() {
|
||||
it('should substitute a single component as string', function () {
|
||||
expect(SafeHTMLSubstitution.render('<0>good</0>', ['b'])).to.equal(
|
||||
'<b>good</b>'
|
||||
)
|
||||
})
|
||||
|
||||
it('should substitute a single component twice', function() {
|
||||
it('should substitute a single component twice', function () {
|
||||
expect(
|
||||
SafeHTMLSubstitution.render('<0>one</0><0>two</0>', [{ name: 'b' }])
|
||||
).to.equal('<b>one</b><b>two</b>')
|
||||
})
|
||||
|
||||
it('should substitute two components', function() {
|
||||
it('should substitute two components', function () {
|
||||
expect(
|
||||
SafeHTMLSubstitution.render('<0>one</0><1>two</1>', [
|
||||
{ name: 'b' },
|
||||
@@ -58,7 +58,7 @@ describe('SafeHTMLSubstitution', function() {
|
||||
).to.equal('<b>one</b><i>two</i>')
|
||||
})
|
||||
|
||||
it('should substitute a single component with a class', function() {
|
||||
it('should substitute a single component with a class', function () {
|
||||
expect(
|
||||
SafeHTMLSubstitution.render('<0>text</0>', [
|
||||
{
|
||||
@@ -71,7 +71,7 @@ describe('SafeHTMLSubstitution', function() {
|
||||
).to.equal('<b class="magic">text</b>')
|
||||
})
|
||||
|
||||
it('should substitute two nested components', function() {
|
||||
it('should substitute two nested components', function () {
|
||||
expect(
|
||||
SafeHTMLSubstitution.render('<0><1>nested</1></0>', [
|
||||
{ name: 'b' },
|
||||
@@ -80,7 +80,7 @@ describe('SafeHTMLSubstitution', function() {
|
||||
).to.equal('<b><i>nested</i></b>')
|
||||
})
|
||||
|
||||
it('should handle links', function() {
|
||||
it('should handle links', function () {
|
||||
expect(
|
||||
SafeHTMLSubstitution.render('<0>Go to Login</0>', [
|
||||
{ name: 'a', attrs: { href: 'https://www.overleaf.com/login' } }
|
||||
@@ -88,7 +88,7 @@ describe('SafeHTMLSubstitution', function() {
|
||||
).to.equal('<a href="https://www.overleaf.com/login">Go to Login</a>')
|
||||
})
|
||||
|
||||
it('should not complain about too many components', function() {
|
||||
it('should not complain about too many components', function () {
|
||||
expect(
|
||||
SafeHTMLSubstitution.render('<0>good</0>', [
|
||||
{ name: 'b' },
|
||||
@@ -99,52 +99,52 @@ describe('SafeHTMLSubstitution', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('pug.escape', function() {
|
||||
it('should handle plain text', function() {
|
||||
describe('pug.escape', function () {
|
||||
it('should handle plain text', function () {
|
||||
expect(SafeHTMLSubstitution.render('plain text')).to.equal('plain text')
|
||||
})
|
||||
|
||||
it('should keep a simple string delimiter', function() {
|
||||
it('should keep a simple string delimiter', function () {
|
||||
expect(SafeHTMLSubstitution.render("'")).to.equal(`'`)
|
||||
})
|
||||
|
||||
it('should escape double quotes', function() {
|
||||
it('should escape double quotes', function () {
|
||||
expect(SafeHTMLSubstitution.render('"')).to.equal(`"`)
|
||||
})
|
||||
|
||||
it('should escape &', function() {
|
||||
it('should escape &', function () {
|
||||
expect(SafeHTMLSubstitution.render('&')).to.equal(`&`)
|
||||
})
|
||||
|
||||
it('should escape <', function() {
|
||||
it('should escape <', function () {
|
||||
expect(SafeHTMLSubstitution.render('<')).to.equal(`<`)
|
||||
})
|
||||
|
||||
it('should escape >', function() {
|
||||
it('should escape >', function () {
|
||||
expect(SafeHTMLSubstitution.render('>')).to.equal(`>`)
|
||||
})
|
||||
|
||||
it('should escape html', function() {
|
||||
it('should escape html', function () {
|
||||
expect(SafeHTMLSubstitution.render('<b>bad</b>')).to.equal(
|
||||
'<b>bad</b>'
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('escape around substitutions', function() {
|
||||
it('should escape text inside a component', function() {
|
||||
describe('escape around substitutions', function () {
|
||||
it('should escape text inside a component', function () {
|
||||
expect(
|
||||
SafeHTMLSubstitution.render('<0><i>inner</i></0>', [{ name: 'b' }])
|
||||
).to.equal('<b><i>inner</i></b>')
|
||||
})
|
||||
|
||||
it('should escape text in front of a component', function() {
|
||||
it('should escape text in front of a component', function () {
|
||||
expect(
|
||||
SafeHTMLSubstitution.render('<i>PRE</i><0>inner</0>', [{ name: 'b' }])
|
||||
).to.equal('<i>PRE</i><b>inner</b>')
|
||||
})
|
||||
|
||||
it('should escape text after of a component', function() {
|
||||
it('should escape text after of a component', function () {
|
||||
expect(
|
||||
SafeHTMLSubstitution.render('<0>inner</0><i>POST</i>', [
|
||||
{ name: 'b' }
|
||||
|
||||
@@ -5,8 +5,8 @@ const modulePath = require('path').join(
|
||||
'../../../../app/src/Features/Helpers/UrlHelper.js'
|
||||
)
|
||||
|
||||
describe('UrlHelper', function() {
|
||||
beforeEach(function() {
|
||||
describe('UrlHelper', function () {
|
||||
beforeEach(function () {
|
||||
this.settings = {
|
||||
apis: { linkedUrlProxy: { url: undefined } },
|
||||
siteUrl: 'http://localhost:3000'
|
||||
@@ -15,8 +15,8 @@ describe('UrlHelper', function() {
|
||||
requires: { 'settings-sharelatex': this.settings }
|
||||
})
|
||||
})
|
||||
describe('getSafeRedirectPath', function() {
|
||||
it('sanitize redirect path to prevent open redirects', function() {
|
||||
describe('getSafeRedirectPath', function () {
|
||||
it('sanitize redirect path to prevent open redirects', function () {
|
||||
expect(this.UrlHelper.getSafeRedirectPath('https://evil.com')).to.be
|
||||
.undefined
|
||||
|
||||
|
||||
Reference in New Issue
Block a user