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:
@@ -14,8 +14,6 @@ import { Alert } from "@vector-im/compound-web";
|
|||||||
import { getThreepidsWithBindStatus } from "../../../../boundThreepids";
|
import { getThreepidsWithBindStatus } from "../../../../boundThreepids";
|
||||||
import { useMatrixClientContext } from "../../../../contexts/MatrixClientContext";
|
import { useMatrixClientContext } from "../../../../contexts/MatrixClientContext";
|
||||||
import { type ThirdPartyIdentifier } from "../../../../AddThreepid";
|
import { type ThirdPartyIdentifier } from "../../../../AddThreepid";
|
||||||
import SettingsStore from "../../../../settings/SettingsStore";
|
|
||||||
import { UIFeature } from "../../../../settings/UIFeature";
|
|
||||||
import { _t } from "../../../../languageHandler";
|
import { _t } from "../../../../languageHandler";
|
||||||
import SetIdServer from "../SetIdServer";
|
import SetIdServer from "../SetIdServer";
|
||||||
import { SettingsSubsection } from "../shared/SettingsSubsection";
|
import { SettingsSubsection } from "../shared/SettingsSubsection";
|
||||||
@@ -124,8 +122,6 @@ export const DiscoverySettings: React.FC = () => {
|
|||||||
})();
|
})();
|
||||||
}, [client, getThreepidState]);
|
}, [client, getThreepidState]);
|
||||||
|
|
||||||
if (!SettingsStore.getValue(UIFeature.ThirdPartyID)) return null;
|
|
||||||
|
|
||||||
if (mustAgreeToTerms && requiredPolicyInfo.policiesAndServices) {
|
if (mustAgreeToTerms && requiredPolicyInfo.policiesAndServices) {
|
||||||
const intro = (
|
const intro = (
|
||||||
<Alert type="info" title={_t("settings|general|discovery_needs_terms_title")}>
|
<Alert type="info" title={_t("settings|general|discovery_needs_terms_title")}>
|
||||||
|
|||||||
@@ -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 (
|
return (
|
||||||
<SettingsTab>
|
<SettingsTab>
|
||||||
{warning}
|
{warning}
|
||||||
@@ -370,10 +385,7 @@ export default class SecurityUserSettingsTab extends React.Component<IProps, ISt
|
|||||||
{secureBackup}
|
{secureBackup}
|
||||||
{eventIndex}
|
{eventIndex}
|
||||||
</SettingsSection>
|
</SettingsSection>
|
||||||
<SettingsSection heading={_t("common|privacy")}>
|
{privacySection}
|
||||||
<DiscoverySettings />
|
|
||||||
{posthogSection}
|
|
||||||
</SettingsSection>
|
|
||||||
{advancedSection}
|
{advancedSection}
|
||||||
</SettingsTab>
|
</SettingsTab>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -15,8 +15,6 @@ import userEvent from "@testing-library/user-event";
|
|||||||
import { DiscoverySettings } from "../../../../../../src/components/views/settings/discovery/DiscoverySettings";
|
import { DiscoverySettings } from "../../../../../../src/components/views/settings/discovery/DiscoverySettings";
|
||||||
import { stubClient } from "../../../../../test-utils";
|
import { stubClient } from "../../../../../test-utils";
|
||||||
import MatrixClientContext from "../../../../../../src/contexts/MatrixClientContext";
|
import MatrixClientContext from "../../../../../../src/contexts/MatrixClientContext";
|
||||||
import { UIFeature } from "../../../../../../src/settings/UIFeature";
|
|
||||||
import SettingsStore from "../../../../../../src/settings/SettingsStore";
|
|
||||||
import defaultDispatcher from "../../../../../../src/dispatcher/dispatcher";
|
import defaultDispatcher from "../../../../../../src/dispatcher/dispatcher";
|
||||||
|
|
||||||
const mockGetAccessToken = jest.fn().mockResolvedValue("$$getAccessToken");
|
const mockGetAccessToken = jest.fn().mockResolvedValue("$$getAccessToken");
|
||||||
@@ -51,16 +49,6 @@ describe("DiscoverySettings", () => {
|
|||||||
|
|
||||||
const DiscoveryWrapper = (props = {}) => <MatrixClientContext.Provider value={client} {...props} />;
|
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 () => {
|
it("displays alert if an identity server needs terms accepting", async () => {
|
||||||
mocked(client).getIdentityServerUrl.mockReturnValue("https://example.com");
|
mocked(client).getIdentityServerUrl.mockReturnValue("https://example.com");
|
||||||
mocked(client).getTerms.mockResolvedValue(sampleTerms);
|
mocked(client).getTerms.mockResolvedValue(sampleTerms);
|
||||||
|
|||||||
+13
-1
@@ -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
|
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.
|
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 React, { act } from "react";
|
||||||
import userEvent from "@testing-library/user-event";
|
import userEvent from "@testing-library/user-event";
|
||||||
|
|
||||||
@@ -21,6 +21,8 @@ import {
|
|||||||
} from "../../../../../../test-utils";
|
} from "../../../../../../test-utils";
|
||||||
import { SDKContext, SdkContextClass } from "../../../../../../../src/contexts/SDKContext";
|
import { SDKContext, SdkContextClass } from "../../../../../../../src/contexts/SDKContext";
|
||||||
import defaultDispatcher from "../../../../../../../src/dispatcher/dispatcher";
|
import defaultDispatcher from "../../../../../../../src/dispatcher/dispatcher";
|
||||||
|
import { UIFeature } from "../../../../../../../src/settings/UIFeature";
|
||||||
|
import SettingsStore from "../../../../../../../src/settings/SettingsStore";
|
||||||
|
|
||||||
describe("<SecurityUserSettingsTab />", () => {
|
describe("<SecurityUserSettingsTab />", () => {
|
||||||
const defaultProps = {
|
const defaultProps = {
|
||||||
@@ -89,4 +91,14 @@ describe("<SecurityUserSettingsTab />", () => {
|
|||||||
});
|
});
|
||||||
expect(getByText("You have no ignored users.")).toBeVisible();
|
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();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user