Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 25x 25x 1x 25x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 2x 2x 2x 2x 4x 4x 1x 1x 1x 1x 4x 4x 22x 22x 4x 4x 6x 4x 2x 2x 2x | /*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import type { IEC3ConfigurationsClient, IEC3JobsClient, IOdataClient, IReportsClient } from "@itwin/insights-client";
import type { RenderResult } from "@testing-library/react";
import { act } from "@testing-library/react";
import { fireEvent, render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import React from "react";
import type { GetAccessTokenFn } from "../components/context/APIContext";
import { ApiContext } from "../components/context/APIContext";
import * as moq from "typemoq";
import { EC3Config } from "../components/EC3/EC3Config";
import { UiFramework } from "@itwin/appui-react";
import { EC3Widget } from "../ec3-widget-react";
import { EmptyLocalization } from "@itwin/core-common";
export interface RenderParameters {
component: React.ReactNode;
ec3ConfigurationsClient?: IEC3ConfigurationsClient;
ec3JobsClient?: IEC3JobsClient;
reportsClient?: IReportsClient;
oDataClient?: IOdataClient;
getAccessTokenFn?: GetAccessTokenFn;
iTwinId?: string;
}
export const mockITwinId = "mockedITwinId";
export async function renderWithContext({
component,
ec3ConfigurationsClient,
ec3JobsClient,
reportsClient,
oDataClient,
getAccessTokenFn,
}: RenderParameters): Promise<RenderResult> {
let result: RenderResult;
await act(async () => {
result = render(
<ApiContext.Provider
value={{
reportsClient: reportsClient ?? moq.Mock.ofType<IReportsClient>().object,
oDataClient: oDataClient ?? moq.Mock.ofType<IOdataClient>().object,
ec3JobsClient: ec3JobsClient ?? moq.Mock.ofType<IEC3JobsClient>().object,
ec3ConfigurationsClient: ec3ConfigurationsClient ?? moq.Mock.ofType<IEC3ConfigurationsClient>().object,
config: new EC3Config({
iTwinId: mockITwinId,
clientId: "",
redirectUri: "",
getAccessToken: getAccessTokenFn ?? (async () => ""),
}),
}}
>
{component}
</ApiContext.Provider>,
);
});
return result!;
}
export async function simulateInput(rootElement: HTMLElement, text: string) {
const input = rootElement.querySelector(".iui-select-button") as HTMLInputElement;
await act(async () => {
await userEvent.click(input);
});
const item = screen.getByText(text);
await act(async () => {
await userEvent.click(item);
});
expect(input.querySelector(".iui-content")).toHaveTextContent(text);
}
export async function simulateCombobox(rootElement: HTMLElement, text: string) {
Element.prototype.scrollIntoView = jest.fn();
const input = rootElement.querySelector(".iui-input") as HTMLInputElement;
await act(async () => {
fireEvent.focus(input);
});
const item = screen.getByText(text);
await act(async () => {
await userEvent.click(item);
});
expect(input.value).toEqual(text);
}
export async function simulateSelect(rootElement: HTMLElement, text: string) {
Element.prototype.scrollIntoView = jest.fn();
const input = rootElement.querySelector(".iui-select-button") as HTMLInputElement;
await act(async () => {
fireEvent.click(input);
});
const item = screen.getByText(text);
await act(async () => {
await userEvent.click(item);
});
expect(input.querySelector(".iui-content")).toHaveTextContent(text);
}
export async function simulateTextInput(rootElement: HTMLElement, text: string) {
const input = rootElement as HTMLInputElement;
await act(async () => {
fireEvent.change(input, { target: { value: text } });
});
expect(input.value).toEqual(text);
}
export async function getComboboxOptions(rootElement: HTMLElement) {
const input = rootElement.querySelector(".iui-input") as HTMLInputElement;
await act(async () => {
fireEvent.focus(input);
});
return document.querySelectorAll(".iui-menu-item");
}
export async function getSelectOptions(rootElement: HTMLElement) {
const input = rootElement.querySelector(".iui-select-button") as HTMLInputElement;
await act(async () => {
fireEvent.click(input);
});
return document.querySelectorAll(".iui-menu-item");
}
export async function getInputOptions(rootElement: HTMLElement) {
const input = rootElement.querySelector(".iui-select-button") as HTMLInputElement;
await act(async () => {
await userEvent.click(input);
});
return document.querySelectorAll(".iui-menu-item");
}
export async function simulateClick(button: HTMLElement) {
await act(async () => {
await userEvent.click(button);
});
}
export class TestUtils {
private static _initialized = false;
public static async initialize() {
if (TestUtils._initialized) {
return;
}
await UiFramework.initialize(undefined);
await EC3Widget.initialize({ localization: new EmptyLocalization() });
TestUtils._initialized = true;
}
public static terminate() {
EC3Widget.terminate();
UiFramework.terminate();
TestUtils._initialized = false;
}
}
|