Merge pull request #20371 from overleaf/mf-us-gov-banner

[web] Add US gov banner based on inclusion and exclusion criteria

GitOrigin-RevId: c45ed280c8ef2dbdf9f3b84488e767c06fcc1ae1
This commit is contained in:
M Fahru
2024-10-14 11:02:15 +00:00
committed by Copybot
parent f3cb79c12f
commit 16ba4b0ddf
12 changed files with 211 additions and 11 deletions
@@ -138,6 +138,17 @@ describe('ProjectListController', function () {
}),
},
}
this.TutorialHandler = {
getInactiveTutorials: sinon.stub().returns([]),
}
this.Modules = {
promises: {
hooks: {
fire: sinon.stub().resolves([]),
},
},
}
this.ProjectListController = SandboxedModule.require(MODULE_PATH, {
requires: {
@@ -158,17 +169,14 @@ describe('ProjectListController', function () {
'../User/UserGetter': this.UserGetter,
'../Subscription/SubscriptionViewModelBuilder':
this.SubscriptionViewModelBuilder,
'../../infrastructure/Modules': {
promises: {
hooks: { fire: sinon.stub().resolves([]) },
},
},
'../../infrastructure/Modules': this.Modules,
'../Survey/SurveyHandler': this.SurveyHandler,
'../User/UserPrimaryEmailCheckHandler':
this.UserPrimaryEmailCheckHandler,
'../Notifications/NotificationsBuilder': this.NotificationBuilder,
'../Subscription/SubscriptionLocator': this.SubscriptionLocator,
'../../infrastructure/GeoIpLookup': this.GeoIpLookup,
'../Tutorial/TutorialHandler': this.TutorialHandler,
},
})
@@ -594,6 +602,101 @@ describe('ProjectListController', function () {
this.ProjectListController.projectListPage(this.req, this.res)
})
})
describe('enterprise banner', function () {
beforeEach(function (done) {
this.Features.hasFeature.withArgs('saas').returns(true)
this.LimitationsManager.promises.userIsMemberOfGroupSubscription.resolves(
{ isMember: false }
)
this.UserGetter.promises.getUserFullEmails.resolves([
{
email: 'test@test-domain.com',
},
])
done()
})
describe('normal enterprise banner', function () {
it('shows banner', function () {
this.res.render = (pageName, opts) => {
expect(opts.showGroupsAndEnterpriseBanner).to.be.true
}
this.ProjectListController.projectListPage(this.req, this.res)
})
it('does not show banner if user is part of any affiliation', function () {
this.UserGetter.promises.getUserFullEmails.resolves([
{
email: 'test@overleaf.com',
affiliation: {
licence: 'pro_plus',
institution: {
id: 1,
confirmed: true,
name: 'Overleaf',
ssoBeta: false,
ssoEnabled: true,
},
},
},
])
this.res.render = (pageName, opts) => {
expect(opts.showGroupsAndEnterpriseBanner).to.be.false
}
this.ProjectListController.projectListPage(this.req, this.res)
})
it('does not show banner if user is part of any group subscription', function () {
this.LimitationsManager.promises.userIsMemberOfGroupSubscription.resolves(
{ isMember: true }
)
this.res.render = (pageName, opts) => {
expect(opts.showGroupsAndEnterpriseBanner).to.be.false
}
this.ProjectListController.projectListPage(this.req, this.res)
})
it('have a banner variant of "FOMO" or "on-premise"', function () {
this.res.render = (pageName, opts) => {
expect(opts.groupsAndEnterpriseBannerVariant).to.be.oneOf([
'FOMO',
'on-premise',
])
}
this.ProjectListController.projectListPage(this.req, this.res)
})
})
describe('US government enterprise banner', function () {
it('does not show enterprise banner if US government enterprise banner is shown', function () {
const emails = [
{
email: 'test@test.mil',
confirmedAt: new Date('2024-01-01'),
},
]
this.UserGetter.promises.getUserFullEmails.resolves(emails)
this.Modules.promises.hooks.fire
.withArgs('getUSGovBanner', emails, false, false)
.resolves([
{
showUSGovBanner: true,
usGovBannerVariant: 'variant',
},
])
this.res.render = (pageName, opts) => {
expect(opts.showGroupsAndEnterpriseBanner).to.be.false
expect(opts.showUSGovBanner).to.be.true
}
this.ProjectListController.projectListPage(this.req, this.res)
})
})
})
})
describe('projectListReactPage with duplicate projects', function () {
@@ -9,6 +9,10 @@ describe('TutorialHandler', function () {
beforeEach(function () {
this.clock = sinon.useFakeTimers()
const THIRTY_DAYS_AGO = Date.now() - 30 * 24 * 60 * 60 * 1000
const TOMORROW = Date.now() + 24 * 60 * 60 * 1000
const YESTERDAY = Date.now() - 24 * 60 * 60 * 1000
this.user = {
_id: new ObjectId(),
completedTutorials: {
@@ -23,7 +27,17 @@ describe('TutorialHandler', function () {
},
'postponed-long-ago': {
state: 'postponed',
updatedAt: new Date(Date.now() - 30 * 24 * 60 * 60 * 1000),
updatedAt: new Date(THIRTY_DAYS_AGO),
},
'postponed-until-tomorrow': {
state: 'postponed',
updatedAt: new Date(THIRTY_DAYS_AGO),
postponedUntil: new Date(TOMORROW),
},
'postponed-until-yesterday': {
state: 'postponed',
updatedAt: new Date(THIRTY_DAYS_AGO),
postponedUntil: new Date(YESTERDAY),
},
},
}
@@ -54,7 +68,20 @@ describe('TutorialHandler', function () {
'legacy-format',
'completed',
'postponed-recently',
'postponed-until-tomorrow',
])
expect(hiddenTutorials).to.have.lengthOf(4)
const shownTutorials = Object.keys(this.user.completedTutorials).filter(
key => !hiddenTutorials.includes(key)
)
expect(shownTutorials).to.have.members([
'postponed-long-ago',
'postponed-until-yesterday',
])
expect(shownTutorials).to.have.lengthOf(2)
})
})
})