Show all labs even if incompatible, with appropriate tooltip explaining requirements (#10369)

Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
This commit is contained in:
Michael Telatynski 2023-03-15 08:37:41 +00:00 committed by GitHub
parent 209b65243a
commit e3930fb8b0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 156 additions and 120 deletions

View file

@ -15,7 +15,7 @@ limitations under the License.
*/
import React from "react";
import { render } from "@testing-library/react";
import { render, waitFor } from "@testing-library/react";
import { defer } from "matrix-js-sdk/src/utils";
import LabsUserSettingsTab from "../../../../../../src/components/views/settings/tabs/user/LabsUserSettingsTab";
@ -28,7 +28,7 @@ import {
import SdkConfig from "../../../../../../src/SdkConfig";
import MatrixClientBackedController from "../../../../../../src/settings/controllers/MatrixClientBackedController";
describe("<SecurityUserSettingsTab />", () => {
describe("<LabsUserSettingsTab />", () => {
const sdkConfigSpy = jest.spyOn(SdkConfig, "get");
const defaultProps = {
@ -70,10 +70,10 @@ describe("<SecurityUserSettingsTab />", () => {
const { container } = render(getComponent());
const labsSections = container.getElementsByClassName("mx_SettingsTab_section");
expect(labsSections.length).toEqual(11);
expect(labsSections).toHaveLength(12);
});
it("renders a labs flag which requires unstable support once support is confirmed", async () => {
it("allow setting a labs flag which requires unstable support once support is confirmed", async () => {
// enable labs
sdkConfigSpy.mockImplementation((configName) => configName === "show_labs_settings");
@ -83,10 +83,20 @@ describe("<SecurityUserSettingsTab />", () => {
});
MatrixClientBackedController.matrixClient = cli;
const { queryByText, findByText } = render(getComponent());
const { queryByText } = render(getComponent());
expect(queryByText("Explore public spaces in the new search dialog")).toBeFalsy();
expect(
queryByText("Explore public spaces in the new search dialog")!
.closest(".mx_SettingsFlag")!
.querySelector(".mx_AccessibleButton"),
).toHaveAttribute("aria-disabled", "true");
deferred.resolve(true);
await expect(findByText("Explore public spaces in the new search dialog")).resolves.toBeDefined();
await waitFor(() => {
expect(
queryByText("Explore public spaces in the new search dialog")!
.closest(".mx_SettingsFlag")!
.querySelector(".mx_AccessibleButton"),
).toHaveAttribute("aria-disabled", "false");
});
});
});

View file

@ -22,6 +22,7 @@ import { MatrixClientPeg } from "../../../../../../src/MatrixClientPeg";
import { mockPlatformPeg, stubClient } from "../../../../../test-utils";
import SettingsStore from "../../../../../../src/settings/SettingsStore";
import { SettingLevel } from "../../../../../../src/settings/SettingLevel";
import MatrixClientBackedController from "../../../../../../src/settings/controllers/MatrixClientBackedController";
describe("PreferencesUserSettingsTab", () => {
beforeEach(() => {
@ -36,6 +37,7 @@ describe("PreferencesUserSettingsTab", () => {
beforeEach(() => {
stubClient();
jest.spyOn(SettingsStore, "setValue");
jest.spyOn(SettingsStore, "canSetValue").mockReturnValue(true);
jest.spyOn(window, "matchMedia").mockReturnValue({ matches: false } as MediaQueryList);
});
@ -47,10 +49,12 @@ describe("PreferencesUserSettingsTab", () => {
const mockIsVersionSupported = (val: boolean) => {
const client = MatrixClientPeg.get();
jest.spyOn(client, "doesServerSupportUnstableFeature").mockResolvedValue(false);
jest.spyOn(client, "isVersionSupported").mockImplementation(async (version: string) => {
if (version === "v1.4") return val;
return false;
});
MatrixClientBackedController.matrixClient = client;
};
const mockGetValue = (val: boolean) => {
@ -98,13 +102,12 @@ describe("PreferencesUserSettingsTab", () => {
mockIsVersionSupported(false);
});
it("can be enabled", async () => {
mockGetValue(false);
it("is forcibly enabled", async () => {
const toggle = getToggle();
await waitFor(() => expect(toggle).toHaveAttribute("aria-disabled", "false"));
fireEvent.click(toggle);
expectSetValueToHaveBeenCalled("sendReadReceipts", null, SettingLevel.ACCOUNT, true);
await waitFor(() => {
expect(toggle).toHaveAttribute("aria-checked", "true");
expect(toggle).toHaveAttribute("aria-disabled", "true");
});
});
it("cannot be disabled", async () => {

View file

@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`<SecurityUserSettingsTab /> renders settings marked as beta as beta cards 1`] = `
exports[`<LabsUserSettingsTab /> renders settings marked as beta as beta cards 1`] = `
<div
class="mx_SettingsTab_section"
data-testid="labs-beta-section"