fix(frontend): only show register infos when links are configured
Docker / build-and-push (backend) (push) Has been cancelled
Docker / build-and-push (frontend) (push) Has been cancelled
E2E Tests / backend-sqlite (push) Has been cancelled
E2E Tests / backend-mariadb (push) Has been cancelled
E2E Tests / backend-postgres (push) Has been cancelled
Lint and check format / Lint files and check formatting (push) Has been cancelled
REUSE Compliance Check / reuse (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
Static Analysis / Njsscan code scanning (push) Has been cancelled
Static Analysis / CodeQL analysis (javascript) (push) Has been cancelled
Run tests & build / Test and build with NodeJS 24 (push) Has been cancelled

Fixes #6469

Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
Philip Molares
2026-05-06 21:08:51 +02:00
committed by Philip Molares
parent 033e627bab
commit 016ec6fd90
3 changed files with 159 additions and 3 deletions
@@ -0,0 +1,71 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Register Infos does not show any links if the frontend config links are null: no links 1`] = `<div />`;
exports[`Register Infos only shows privacy links: privacy link 1`] = `
<div>
login.register.infoTermsPrivacy
<ul>
<li>
<a
class=""
dir="auto"
href="https://example.com/privacy"
rel="noopener noreferrer"
target="_blank"
>
appbar.help.legal.privacy
</a>
</li>
</ul>
</div>
`;
exports[`Register Infos only shows termsOfUse links: termsOfUse link 1`] = `
<div>
login.register.infoTermsPrivacy
<ul>
<li>
<a
class=""
dir="auto"
href="https://example.com/terms-of-use"
rel="noopener noreferrer"
target="_blank"
>
appbar.help.legal.termsOfUse
</a>
</li>
</ul>
</div>
`;
exports[`Register Infos show privacy and termsOfUse links: privacy and termsOfUse link 1`] = `
<div>
login.register.infoTermsPrivacy
<ul>
<li>
<a
class=""
dir="auto"
href="https://example.com/terms-of-use"
rel="noopener noreferrer"
target="_blank"
>
appbar.help.legal.termsOfUse
</a>
</li>
<li>
<a
class=""
dir="auto"
href="https://example.com/privacy"
rel="noopener noreferrer"
target="_blank"
>
appbar.help.legal.privacy
</a>
</li>
</ul>
</div>
`;
@@ -0,0 +1,85 @@
/*
* SPDX-FileCopyrightText: 2023 The HedgeDoc developers (see AUTHORS file)
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { mockI18n } from '../../../../test-utils/mock-i18n'
import { render } from '@testing-library/react'
import { FrontendConfigContextProvider } from '../../../common/frontend-config-context/frontend-config-context-provider'
import { RegisterInfos } from './register-infos'
import type { FrontendConfigInterface } from '@hedgedoc/commons'
import { PermissionLevel } from '@hedgedoc/commons'
describe('Register Infos', () => {
let mockFrontendConfig: FrontendConfigInterface
beforeAll(mockI18n)
beforeEach(() => {
mockFrontendConfig = {
version: {
major: 0,
minor: 0,
patch: 0,
fullString: '',
preRelease: undefined,
commit: undefined
},
guestAccess: PermissionLevel.DENY,
allowRegister: false,
allowProfileEdits: false,
allowChooseUsername: false,
authProviders: [],
branding: {
name: null,
logo: null
},
useImageProxy: false,
specialUrls: {
privacy: null,
termsOfUse: null,
imprint: null
},
plantUmlServer: null,
maxDocumentLength: 0
}
})
it('does not show any links if the frontend config links are null', async () => {
const view = render(
<FrontendConfigContextProvider config={mockFrontendConfig}>
<RegisterInfos />
</FrontendConfigContextProvider>
)
expect(view.container).toMatchSnapshot('no links')
})
it('only shows termsOfUse links', async () => {
mockFrontendConfig.specialUrls.termsOfUse = 'https://example.com/terms-of-use'
const view = render(
<FrontendConfigContextProvider config={mockFrontendConfig}>
<RegisterInfos />
</FrontendConfigContextProvider>
)
expect(view.container).toMatchSnapshot('termsOfUse link')
})
it('only shows privacy links', async () => {
mockFrontendConfig.specialUrls.privacy = 'https://example.com/privacy'
const view = render(
<FrontendConfigContextProvider config={mockFrontendConfig}>
<RegisterInfos />
</FrontendConfigContextProvider>
)
expect(view.container).toMatchSnapshot('privacy link')
})
it('show privacy and termsOfUse links', async () => {
mockFrontendConfig.specialUrls.termsOfUse = 'https://example.com/terms-of-use'
mockFrontendConfig.specialUrls.privacy = 'https://example.com/privacy'
const view = render(
<FrontendConfigContextProvider config={mockFrontendConfig}>
<RegisterInfos />
</FrontendConfigContextProvider>
)
expect(view.container).toMatchSnapshot('privacy and termsOfUse link')
})
})
@@ -15,7 +15,7 @@ export const RegisterInfos: React.FC = () => {
useTranslation()
const specialUrls = useFrontendConfig().specialUrls
if (specialUrls.termsOfUse === undefined && specialUrls.privacy === undefined) {
if (specialUrls.termsOfUse === null && specialUrls.privacy === null) {
return null
}
@@ -23,12 +23,12 @@ export const RegisterInfos: React.FC = () => {
<>
<Trans i18nKey='login.register.infoTermsPrivacy' />
<ul>
{specialUrls.termsOfUse !== undefined && (
{specialUrls.termsOfUse !== null && (
<li>
<TranslatedExternalLink i18nKey='appbar.help.legal.termsOfUse' href={specialUrls.termsOfUse ?? ''} />
</li>
)}
{specialUrls.privacy !== undefined && (
{specialUrls.privacy !== null && (
<li>
<TranslatedExternalLink i18nKey='appbar.help.legal.privacy' href={specialUrls.privacy ?? ''} />
</li>