1
0
mirror of https://github.com/matrix-org/matrix-react-sdk.git synced 2025-08-07 21:23:00 +03:00
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
Michael Telatynski
2024-08-02 15:07:31 +01:00
parent df1b7772f2
commit 712ac34755
6 changed files with 27 additions and 8 deletions

View File

@@ -52,6 +52,13 @@ counterpart.setSeparator(KEY_SEPARATOR);
const FALLBACK_LOCALE = "en"; const FALLBACK_LOCALE = "en";
counterpart.setFallbackLocale(FALLBACK_LOCALE); counterpart.setFallbackLocale(FALLBACK_LOCALE);
export interface ErrorOptions {
// Because we're mixing the substitution variables and `cause` into the same object
// below, we want them to always explicitly say whether there is an underlying error
// or not to avoid typos of "cause" slipping through unnoticed.
cause: unknown | undefined;
}
/** /**
* Used to rethrow an error with a user-friendly translatable message while maintaining * Used to rethrow an error with a user-friendly translatable message while maintaining
* access to that original underlying error. Downstream consumers can display the * access to that original underlying error. Downstream consumers can display the
@@ -71,11 +78,15 @@ counterpart.setFallbackLocale(FALLBACK_LOCALE);
export class UserFriendlyError extends Error { export class UserFriendlyError extends Error {
public readonly translatedMessage: string; public readonly translatedMessage: string;
public constructor(message: TranslationKey, cause?: Error | unknown, substitutionVariables?: IVariables) { public constructor(
message: TranslationKey,
substitutionVariablesAndCause?: Omit<IVariables, keyof ErrorOptions> | ErrorOptions,
) {
// Prevent "Could not find /%\(cause\)s/g in x" logs to the console by removing it from the list
const { cause, ...substitutionVariables } = substitutionVariablesAndCause ?? {};
const errorOptions = { cause }; const errorOptions = { cause };
// Create the error with the English version of the message that we want to show // Create the error with the English version of the message that we want to show up in the logs
// up in the logs
const englishTranslatedMessage = _t(message, { ...substitutionVariables, locale: "en" }); const englishTranslatedMessage = _t(message, { ...substitutionVariables, locale: "en" });
super(englishTranslatedMessage, errorOptions); super(englishTranslatedMessage, errorOptions);

View File

@@ -144,6 +144,9 @@ describe("RoomView", () => {
wrappedRef={ref as any} wrappedRef={ref as any}
/> />
</SDKContext.Provider>, </SDKContext.Provider>,
{
legacyRoot: true,
},
); );
await flushPromises(); await flushPromises();
return roomView; return roomView;
@@ -181,6 +184,9 @@ describe("RoomView", () => {
onRegistered={jest.fn()} onRegistered={jest.fn()}
/> />
</SDKContext.Provider>, </SDKContext.Provider>,
{
legacyRoot: true,
},
); );
await flushPromises(); await flushPromises();
return roomView; return roomView;

View File

@@ -98,7 +98,7 @@ describe("Login", function () {
} }
function getComponent(hsUrl?: string, isUrl?: string, delegatedAuthentication?: OidcClientConfig) { function getComponent(hsUrl?: string, isUrl?: string, delegatedAuthentication?: OidcClientConfig) {
return render(getRawComponent(hsUrl, isUrl, delegatedAuthentication)); return render(getRawComponent(hsUrl, isUrl, delegatedAuthentication), { legacyRoot: true });
} }
it("should show form with change server link", async () => { it("should show form with change server link", async () => {
@@ -359,7 +359,9 @@ describe("Login", function () {
unstable_features: {}, unstable_features: {},
versions: ["v1.1"], versions: ["v1.1"],
}); });
const { rerender } = render(getRawComponent()); const { rerender } = render(getRawComponent(), {
legacyRoot: true,
});
await waitForElementToBeRemoved(() => screen.queryAllByLabelText("Loading…")); await waitForElementToBeRemoved(() => screen.queryAllByLabelText("Loading…"));
// error displayed // error displayed

View File

@@ -73,7 +73,6 @@ exports[`LogoutDialog Prompts user to connect backup if there is a backup on the
</details> </details>
</div> </div>
<div <div
aria-describedby=":rm:"
aria-label="Close dialog" aria-label="Close dialog"
class="mx_AccessibleButton mx_Dialog_cancelButton" class="mx_AccessibleButton mx_Dialog_cancelButton"
role="button" role="button"

View File

@@ -441,11 +441,11 @@ describe("MemberList", () => {
jest.spyOn(room, "getMyMembership").mockReturnValue(KnownMembership.Join); jest.spyOn(room, "getMyMembership").mockReturnValue(KnownMembership.Join);
jest.spyOn(room, "canInvite").mockReturnValue(true); jest.spyOn(room, "canInvite").mockReturnValue(true);
const { getByRole, getAllByRole } = renderComponent(); const { getByRole } = renderComponent();
await waitForElementToBeRemoved(() => screen.queryAllByRole("progressbar")); await waitForElementToBeRemoved(() => screen.queryAllByRole("progressbar"));
await waitFor(() => await waitFor(() =>
expect(getAllByRole("button", { name: "Invite to this room" })).not.toHaveAttribute( expect(getByRole("button", { name: "Invite to this room" })).not.toHaveAttribute(
"aria-disabled", "aria-disabled",
"true", "true",
), ),

View File

@@ -47,6 +47,7 @@ describe("<SecurityRoomSettingsTab />", () => {
wrapper: ({ children }) => ( wrapper: ({ children }) => (
<MatrixClientContext.Provider value={client}>{children}</MatrixClientContext.Provider> <MatrixClientContext.Provider value={client}>{children}</MatrixClientContext.Provider>
), ),
legacyRoot: true,
}); });
const setRoomStateEvents = ( const setRoomStateEvents = (