New compile UI admin panel (#3666)

* Extract new logs UI feature check to a helper function

* Add new logs UI per-user availability to the admin panel

* Stub NewLogsUIHelper in the unit tests

GitOrigin-RevId: b5344448d507c7cd7422b342286ada2b839b1785
This commit is contained in:
Paulo Jorge Reis
2021-02-17 13:52:46 +00:00
committed by Copybot
parent 70fb5da37d
commit 2051caf28e
4 changed files with 119 additions and 104 deletions
@@ -119,6 +119,9 @@ describe('ProjectController', function() {
},
inc: sinon.stub()
}
this.NewLogsUIHelper = {
shouldUserSeeNewLogsUI: sinon.stub().returns(false)
}
this.ProjectController = SandboxedModule.require(MODULE_PATH, {
globals: {
@@ -165,7 +168,8 @@ describe('ProjectController', function() {
'../Analytics/AnalyticsManager': { recordEvent: () => {} },
'../../infrastructure/Modules': {
hooks: { fire: sinon.stub().yields(null, []) }
}
},
'../Helpers/NewLogsUI': this.NewLogsUIHelper
}
})
@@ -1047,85 +1051,6 @@ describe('ProjectController', function() {
this.ProjectController.loadEditor(this.req, this.res)
})
describe('showNewLogsUI staged rollout', function() {
function userIdFromTime(time) {
return ObjectId.createFromTime(time).toString()
}
function checkNewLogsUI(shouldGetNewLogsUI) {
it(`should set showNewLogsUI to ${shouldGetNewLogsUI}`, function(done) {
this.res.render = (pageName, opts) => {
opts.showNewLogsUI.should.equal(shouldGetNewLogsUI)
done()
}
this.ProjectController.loadEditor(this.req, this.res)
})
}
describe('for alpha users', function() {
beforeEach(function() {
this.user.alphaProgram = true
})
checkNewLogsUI(true)
})
describe('for beta users', function() {
beforeEach(function() {
this.user.betaProgram = true
})
describe('with a beta rollout percentage of 0', function() {
beforeEach(function() {
this.settings.logsUIPercentageBeta = 0
})
checkNewLogsUI(false)
})
describe('with a beta rollout percentage > 0', function() {
const percentileThresold = 50
beforeEach(function() {
this.settings.logsUIPercentageBeta = percentileThresold
})
describe('when the user id is higher than the percent threshold', function() {
beforeEach(function() {
this.user._id = userIdFromTime(percentileThresold + 1)
})
checkNewLogsUI(false)
})
describe('when the user id is lower than the percent threshold', function() {
beforeEach(function() {
this.user._id = userIdFromTime(percentileThresold - 1)
})
checkNewLogsUI(true)
})
})
})
describe('for normal users', function() {
describe('with a rollout percentage of 0', function() {
beforeEach(function() {
this.settings.logsUIPercentage = 0
})
checkNewLogsUI(false)
})
describe('with a rollout percentage > 0', function() {
const percentileThresold = 50
beforeEach(function() {
this.settings.logsUIPercentage = percentileThresold
})
describe('when the user id is higher than the percent threshold', function() {
beforeEach(function() {
this.user._id = userIdFromTime(percentileThresold + 1)
})
checkNewLogsUI(false)
})
describe('when the user id is lower than the percent threshold', function() {
beforeEach(function() {
this.user._id = userIdFromTime(percentileThresold - 1)
})
checkNewLogsUI(true)
})
})
})
})
describe('wsUrl', function() {
function checkLoadEditorWsMetric(metric) {
it(`should inc metric ${metric}`, function(done) {