Don't show empty privacy section (#32582)

* Don't show empty privacy section

If all the options to display things things in it are disabled

Also makes it more consistent with other areas.

* Move test
This commit is contained in:
David Baker 2026-02-20 15:09:11 +01:00 committed by GitHub
parent 02b07c876a
commit 5f3211741f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 29 additions and 21 deletions

View File

@ -14,8 +14,6 @@ import { Alert } from "@vector-im/compound-web";
import { getThreepidsWithBindStatus } from "../../../../boundThreepids";
import { useMatrixClientContext } from "../../../../contexts/MatrixClientContext";
import { type ThirdPartyIdentifier } from "../../../../AddThreepid";
import SettingsStore from "../../../../settings/SettingsStore";
import { UIFeature } from "../../../../settings/UIFeature";
import { _t } from "../../../../languageHandler";
import SetIdServer from "../SetIdServer";
import { SettingsSubsection } from "../shared/SettingsSubsection";
@ -124,8 +122,6 @@ export const DiscoverySettings: React.FC = () => {
})();
}, [client, getThreepidState]);
if (!SettingsStore.getValue(UIFeature.ThirdPartyID)) return null;
if (mustAgreeToTerms && requiredPolicyInfo.policiesAndServices) {
const intro = (
<Alert type="info" title={_t("settings|general|discovery_needs_terms_title")}>

View File

@ -362,6 +362,21 @@ export default class SecurityUserSettingsTab extends React.Component<IProps, ISt
}
}
let discoverySection;
if (SettingsStore.getValue(UIFeature.ThirdPartyID)) {
discoverySection = <DiscoverySettings />;
}
let privacySection;
if (discoverySection || posthogSection) {
privacySection = (
<SettingsSection heading={_t("common|privacy")}>
{discoverySection}
{posthogSection}
</SettingsSection>
);
}
return (
<SettingsTab>
{warning}
@ -370,10 +385,7 @@ export default class SecurityUserSettingsTab extends React.Component<IProps, ISt
{secureBackup}
{eventIndex}
</SettingsSection>
<SettingsSection heading={_t("common|privacy")}>
<DiscoverySettings />
{posthogSection}
</SettingsSection>
{privacySection}
{advancedSection}
</SettingsTab>
);

View File

@ -15,8 +15,6 @@ import userEvent from "@testing-library/user-event";
import { DiscoverySettings } from "../../../../../../src/components/views/settings/discovery/DiscoverySettings";
import { stubClient } from "../../../../../test-utils";
import MatrixClientContext from "../../../../../../src/contexts/MatrixClientContext";
import { UIFeature } from "../../../../../../src/settings/UIFeature";
import SettingsStore from "../../../../../../src/settings/SettingsStore";
import defaultDispatcher from "../../../../../../src/dispatcher/dispatcher";
const mockGetAccessToken = jest.fn().mockResolvedValue("$$getAccessToken");
@ -51,16 +49,6 @@ describe("DiscoverySettings", () => {
const DiscoveryWrapper = (props = {}) => <MatrixClientContext.Provider value={client} {...props} />;
it("is empty if 3pid features are disabled", async () => {
jest.spyOn(SettingsStore, "getValue").mockImplementation((key: any): any => {
if (key === UIFeature.ThirdPartyID) return false;
});
const { container } = render(<DiscoverySettings />, { wrapper: DiscoveryWrapper });
expect(container).toBeEmptyDOMElement();
});
it("displays alert if an identity server needs terms accepting", async () => {
mocked(client).getIdentityServerUrl.mockReturnValue("https://example.com");
mocked(client).getTerms.mockResolvedValue(sampleTerms);

View File

@ -5,7 +5,7 @@ Copyright 2022 The Matrix.org Foundation C.I.C.
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE files in the repository root for full details.
*/
import { render } from "jest-matrix-react";
import { render, screen } from "jest-matrix-react";
import React, { act } from "react";
import userEvent from "@testing-library/user-event";
@ -21,6 +21,8 @@ import {
} from "../../../../../../test-utils";
import { SDKContext, SdkContextClass } from "../../../../../../../src/contexts/SDKContext";
import defaultDispatcher from "../../../../../../../src/dispatcher/dispatcher";
import { UIFeature } from "../../../../../../../src/settings/UIFeature";
import SettingsStore from "../../../../../../../src/settings/SettingsStore";
describe("<SecurityUserSettingsTab />", () => {
const defaultProps = {
@ -89,4 +91,14 @@ describe("<SecurityUserSettingsTab />", () => {
});
expect(getByText("You have no ignored users.")).toBeVisible();
});
it("does not render privacy header if 3pid features are disabled", async () => {
jest.spyOn(SettingsStore, "getValue").mockImplementation((key: any): any => {
if (key === UIFeature.ThirdPartyID) return false;
});
render(getComponent());
expect(screen.queryByRole("heading", { name: "Privacy" })).toBeNull();
});
});