Merge pull request #33202 from overleaf/jel-domain-captured-by-group-settings-page

[Domain capture] Check `domainCapturedByGroup` for existing emails on user settings

GitOrigin-RevId: 5ac86b89969b186cce0cac410c2957e5aa1b9703
This commit is contained in:
Jessica Lawshe
2026-05-11 10:04:15 -05:00
committed by Copybot
parent 6a911e4ec3
commit ba13ccdb11
5 changed files with 78 additions and 16 deletions

View File

@@ -11,12 +11,15 @@ import { UserEmailData } from '../../../../../../types/user-email'
import { UserEmailsProvider } from '../../../../../../frontend/js/features/settings/context/user-email-context'
import { Affiliation } from '../../../../../../types/affiliation'
import getMeta from '@/utils/meta'
import { SplitTestProvider } from '@/shared/context/split-test-context'
function renderEmailsRow(data: UserEmailData) {
return render(
<UserEmailsProvider>
<EmailsRow userEmailData={data} />
</UserEmailsProvider>
<SplitTestProvider>
<UserEmailsProvider>
<EmailsRow userEmailData={data} />
</UserEmailsProvider>
</SplitTestProvider>
)
}
@@ -33,6 +36,7 @@ describe('<EmailsRow/>', function () {
samlInitPath: '/saml',
hasSamlBeta: true,
})
window.metaAttributesCache.set('ol-splitTestVariants', {})
fetchMock.get('/user/emails?ensureAffiliation=true', [])
})
@@ -165,6 +169,37 @@ describe('<EmailsRow/>', function () {
expect(screen.queryByRole('button', { name: 'Link accounts' })).to.be
.null
})
it('uses `domainCapturedByGroup` when the feature flag is enabled', function () {
affiliatedEmailWithDomainCaptureAndCommons.affiliation.group = {
_id: 'grou123',
domainCaptureEnabled: true,
managedUsersEnabled: true,
}
affiliatedEmailWithDomainCaptureAndCommons.affiliation.domainCapturedByGroup = true
window.metaAttributesCache.set('ol-splitTestVariants', {
'domain-captured-by-group': 'enabled',
})
renderEmailsRow(affiliatedEmailWithDomainCaptureAndCommons)
expect(screen.queryByRole('button', { name: 'Link accounts' })).to.be
.null
})
it('ignores group domain capture when the feature flag is enabled and the domain is not captured', function () {
affiliatedEmailWithDomainCaptureAndCommons.affiliation.domainCapturedByGroup = false
window.metaAttributesCache.set('ol-splitTestVariants', {
'domain-captured-by-group': 'enabled',
})
renderEmailsRow(affiliatedEmailWithDomainCaptureAndCommons)
getByTextContent(
'You can now link your Overleaf account to your Overleaf institutional account.'
)
screen.getByRole('button', { name: 'Link accounts' })
})
})
})
})

View File

@@ -13,6 +13,7 @@ import EmailsSection from '../../../../../../frontend/js/features/settings/compo
import { Institution } from '../../../../../../types/institution'
import { Affiliation } from '../../../../../../types/affiliation'
import getMeta from '@/utils/meta'
import { SplitTestProvider } from '@/shared/context/split-test-context'
const userEmailData: UserEmailData = {
confirmedAt: '2022-03-10T10:59:44.139Z',
@@ -32,6 +33,14 @@ const userEmailData2: UserEmailData & { affiliation: Affiliation } = {
default: false,
}
function renderEmailsSection() {
return render(<EmailsSection />, {
wrapper: ({ children }) => (
<SplitTestProvider>{children}</SplitTestProvider>
),
})
}
describe('email actions - make primary', function () {
beforeEach(function () {
Object.assign(getMeta('ol-ExposedSettings'), {
@@ -49,7 +58,7 @@ describe('email actions - make primary', function () {
const userEmailDataCopy = { ...userEmailData2 }
const { confirmedAt: _, ...userEmailData } = userEmailDataCopy
fetchMock.get('/user/emails?ensureAffiliation=true', [userEmailData])
render(<EmailsSection />)
renderEmailsSection()
const button = (await screen.findByRole('button', {
name: /make primary/i,
@@ -66,7 +75,7 @@ describe('email actions - make primary', function () {
},
}
fetchMock.get('/user/emails?ensureAffiliation=true', [userEmailDataCopy])
render(<EmailsSection />)
renderEmailsSection()
const button = (await screen.findByRole('button', {
name: /make primary/i,
@@ -86,7 +95,7 @@ describe('email actions - make primary', function () {
}
fetchMock.get('/user/emails?ensureAffiliation=true', [userEmailDataCopy])
render(<EmailsSection />)
renderEmailsSection()
const button = (await screen.findByRole('button', {
name: /make primary/i,
@@ -103,7 +112,7 @@ describe('email actions - make primary', function () {
const userEmailDataCopy = { ...userEmailData2 }
fetchMock.get('/user/emails?ensureAffiliation=true', [userEmailDataCopy])
render(<EmailsSection />)
renderEmailsSection()
const button = (await screen.findByRole('button', {
name: /make primary/i,
@@ -144,7 +153,7 @@ describe('email actions - make primary', function () {
userEmailDataCopy1,
userEmailDataCopy2,
])
render(<EmailsSection />)
renderEmailsSection()
const buttons = (await screen.findAllByRole('button', {
name: /make primary/i,
@@ -177,7 +186,7 @@ describe('email actions - make primary', function () {
it('shows confirmation modal and closes it', async function () {
fetchMock.get('/user/emails?ensureAffiliation=true', [userEmailData])
render(<EmailsSection />)
renderEmailsSection()
const button = await screen.findByRole('button', {
name: /make primary/i,
@@ -205,7 +214,7 @@ describe('email actions - make primary', function () {
fetchMock
.get('/user/emails?ensureAffiliation=true', [userEmailData])
.post('/user/emails/default?delete-unconfirmed-primary', 200)
render(<EmailsSection />)
renderEmailsSection()
await confirmPrimaryEmail()
@@ -221,7 +230,7 @@ describe('email actions - make primary', function () {
fetchMock
.get('/user/emails?ensureAffiliation=true', [userEmailData])
.post('/user/emails/default?delete-unconfirmed-primary', 503)
render(<EmailsSection />)
renderEmailsSection()
await confirmPrimaryEmail()
@@ -241,13 +250,14 @@ describe('email actions - delete', function () {
afterEach(function () {
fetchMock.removeRoutes().clearHistory()
window.metaAttributesCache.set('ol-splitTestVariants', {})
})
it('shows loader when deleting and removes the row', async function () {
fetchMock
.get('/user/emails?ensureAffiliation=true', [userEmailData])
.post('/user/emails/delete', 200)
render(<EmailsSection />)
renderEmailsSection()
const button = await screen.findByRole('button', { name: /remove/i })
fireEvent.click(button)
@@ -261,7 +271,7 @@ describe('email actions - delete', function () {
fetchMock
.get('/user/emails?ensureAffiliation=true', [userEmailData])
.post('/user/emails/delete', 503)
render(<EmailsSection />)
renderEmailsSection()
const button = await screen.findByRole('button', { name: /remove/i })
fireEvent.click(button)