2024-10-14 21:41:58 +05:30
|
|
|
/*
|
|
|
|
|
Copyright 2024 New Vector Ltd.
|
|
|
|
|
Copyright 2022 The Matrix.org Foundation C.I.C.
|
|
|
|
|
|
2025-01-06 11:18:54 +00:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
|
2024-10-14 21:41:58 +05:30
|
|
|
Please see LICENSE files in the repository root for full details.
|
|
|
|
|
*/
|
|
|
|
|
|
2025-02-05 13:25:06 +00:00
|
|
|
import React, { type ReactElement } from "react";
|
2024-10-14 21:41:58 +05:30
|
|
|
// eslint-disable-next-line no-restricted-imports
|
2025-02-05 13:25:06 +00:00
|
|
|
import { render, type RenderOptions } from "@testing-library/react";
|
2024-10-14 21:41:58 +05:30
|
|
|
import { TooltipProvider } from "@vector-im/compound-web";
|
2026-07-07 10:50:40 +01:00
|
|
|
import { I18nApi, I18nContext } from "@element-hq/web-shared-components";
|
|
|
|
|
|
|
|
|
|
const i18nApi = new I18nApi();
|
2024-10-14 21:41:58 +05:30
|
|
|
|
2025-12-02 13:47:14 +00:00
|
|
|
/**
|
|
|
|
|
* Wraps the provided components in:
|
|
|
|
|
* * A TooltipProvider
|
|
|
|
|
* * An I18nContext.Provider
|
|
|
|
|
*
|
|
|
|
|
* ...plus any wrapper provided in the options.
|
|
|
|
|
* @param Wrapper Additional wrapper to include
|
|
|
|
|
* @returns The wrapped component
|
|
|
|
|
*/
|
|
|
|
|
const wrapWithStandardContexts = (Wrapper: RenderOptions["wrapper"]) => {
|
2024-10-14 21:41:58 +05:30
|
|
|
return ({ children }: { children: React.ReactNode }) => {
|
|
|
|
|
if (Wrapper) {
|
|
|
|
|
return (
|
|
|
|
|
<Wrapper>
|
2026-07-07 10:50:40 +01:00
|
|
|
<I18nContext.Provider value={i18nApi}>
|
2025-12-02 13:47:14 +00:00
|
|
|
<TooltipProvider>{children}</TooltipProvider>
|
|
|
|
|
</I18nContext.Provider>
|
2024-10-14 21:41:58 +05:30
|
|
|
</Wrapper>
|
|
|
|
|
);
|
|
|
|
|
} else {
|
2025-12-02 13:47:14 +00:00
|
|
|
return (
|
|
|
|
|
<TooltipProvider>
|
2026-07-07 10:50:40 +01:00
|
|
|
<I18nContext.Provider value={i18nApi}>{children}</I18nContext.Provider>
|
2025-12-02 13:47:14 +00:00
|
|
|
</TooltipProvider>
|
|
|
|
|
);
|
2024-10-14 21:41:58 +05:30
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const customRender = (ui: ReactElement, options: RenderOptions = {}) => {
|
|
|
|
|
return render(ui, {
|
|
|
|
|
...options,
|
2025-12-02 13:47:14 +00:00
|
|
|
wrapper: wrapWithStandardContexts(options?.wrapper) as RenderOptions["wrapper"],
|
2024-10-14 21:41:58 +05:30
|
|
|
}) as ReturnType<typeof render>;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// eslint-disable-next-line no-restricted-imports
|
|
|
|
|
export * from "@testing-library/react";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This custom render function wraps your component with a TooltipProvider.
|
|
|
|
|
* See https://testing-library.com/docs/react-testing-library/setup/#custom-render
|
|
|
|
|
*/
|
|
|
|
|
export { customRender as render };
|