2022-04-27 12:13:42 -04:00
|
|
|
import { expect } from 'chai'
|
|
|
|
import { screen, render } from '@testing-library/react'
|
|
|
|
import fetchMock from 'fetch-mock'
|
2024-03-11 08:28:55 -04:00
|
|
|
import LinkingSection from '@/features/settings/components/linking-section'
|
|
|
|
import { UserProvider } from '@/shared/context/user-context'
|
|
|
|
import { SSOProvider } from '@/features/settings/context/sso-context'
|
2023-12-07 09:29:45 -05:00
|
|
|
import { SplitTestProvider } from '@/shared/context/split-test-context'
|
2022-04-27 12:13:42 -04:00
|
|
|
|
|
|
|
function renderSectionWithProviders() {
|
|
|
|
render(<LinkingSection />, {
|
|
|
|
wrapper: ({ children }) => (
|
2023-12-07 09:29:45 -05:00
|
|
|
<SplitTestProvider>
|
|
|
|
<UserProvider>
|
|
|
|
<SSOProvider>{children}</SSOProvider>
|
|
|
|
</UserProvider>
|
|
|
|
</SplitTestProvider>
|
2022-04-27 12:13:42 -04:00
|
|
|
),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
const mockOauthProviders = {
|
|
|
|
google: {
|
|
|
|
descriptionKey: 'login_with_service',
|
|
|
|
descriptionOptions: { service: 'Google' },
|
|
|
|
name: 'Google',
|
|
|
|
linkPath: '/auth/google',
|
|
|
|
},
|
|
|
|
orcid: {
|
|
|
|
descriptionKey: 'oauth_orcid_description',
|
|
|
|
descriptionOptions: {
|
|
|
|
link: '/blog/434',
|
|
|
|
appName: 'Overleaf',
|
|
|
|
},
|
2022-05-26 08:58:21 -04:00
|
|
|
name: 'ORCID',
|
2022-04-27 12:13:42 -04:00
|
|
|
linkPath: '/auth/orcid',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
describe('<LinkingSection />', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
window.metaAttributesCache = window.metaAttributesCache || new Map()
|
|
|
|
window.metaAttributesCache.set('ol-user', {})
|
|
|
|
|
|
|
|
// suppress integrations and references widgets as they cannot be tested in
|
|
|
|
// all environments
|
|
|
|
window.metaAttributesCache.set('integrationLinkingWidgets', [])
|
|
|
|
window.metaAttributesCache.set('referenceLinkingWidgets', [])
|
2023-12-07 09:29:45 -05:00
|
|
|
window.metaAttributesCache.set('integrationLinkingWidgets', [])
|
2022-04-27 12:13:42 -04:00
|
|
|
|
|
|
|
window.metaAttributesCache.set('ol-thirdPartyIds', {
|
|
|
|
google: 'google-id',
|
|
|
|
})
|
|
|
|
|
|
|
|
window.metaAttributesCache.set('ol-oauthProviders', mockOauthProviders)
|
|
|
|
})
|
|
|
|
|
|
|
|
afterEach(function () {
|
|
|
|
window.metaAttributesCache = new Map()
|
|
|
|
fetchMock.reset()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('shows header', async function () {
|
|
|
|
renderSectionWithProviders()
|
|
|
|
|
|
|
|
screen.getByText('Integrations')
|
|
|
|
screen.getByText(
|
2022-05-24 03:47:08 -04:00
|
|
|
'You can link your Overleaf account with other services to enable the features described below.'
|
2022-04-27 12:13:42 -04:00
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('lists SSO providers', async function () {
|
|
|
|
renderSectionWithProviders()
|
|
|
|
screen.getByText('linked accounts')
|
|
|
|
|
|
|
|
screen.getByText('Google')
|
2022-05-24 03:47:08 -04:00
|
|
|
screen.getByText('Log in with Google.')
|
2022-04-27 12:13:42 -04:00
|
|
|
screen.getByRole('button', { name: 'Unlink' })
|
|
|
|
|
2022-05-26 08:58:21 -04:00
|
|
|
screen.getByText('ORCID')
|
2022-04-27 12:13:42 -04:00
|
|
|
screen.getByText(
|
|
|
|
/Securely establish your identity by linking your ORCID iD/
|
|
|
|
)
|
|
|
|
const helpLink = screen.getByRole('link', { name: 'Learn more' })
|
|
|
|
expect(helpLink.getAttribute('href')).to.equal('/blog/434')
|
|
|
|
const linkButton = screen.getByRole('link', { name: 'Link' })
|
|
|
|
expect(linkButton.getAttribute('href')).to.equal('/auth/orcid?intent=link')
|
|
|
|
})
|
|
|
|
|
2022-05-16 04:02:17 -04:00
|
|
|
it('shows SSO error message', async function () {
|
|
|
|
window.metaAttributesCache.set('ol-ssoErrorMessage', 'You no SSO')
|
|
|
|
renderSectionWithProviders()
|
2022-05-16 04:02:50 -04:00
|
|
|
screen.getByText('Error linking account: You no SSO')
|
2022-05-16 04:02:17 -04:00
|
|
|
})
|
|
|
|
|
2022-04-27 12:13:42 -04:00
|
|
|
it('does not show providers section when empty', async function () {
|
|
|
|
window.metaAttributesCache.delete('ol-oauthProviders')
|
|
|
|
renderSectionWithProviders()
|
|
|
|
|
|
|
|
expect(screen.queryByText('linked accounts')).to.not.exist
|
|
|
|
})
|
|
|
|
})
|