Update usages of test utilities preferring RTL (#10203)
This commit is contained in:
parent
17bbd4eaac
commit
c29e5f18ff
37 changed files with 341 additions and 424 deletions
|
@ -14,8 +14,8 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
import React, { ReactElement } from "react";
|
||||
import ReactDOM from "react-dom";
|
||||
import React from "react";
|
||||
import { render } from "@testing-library/react";
|
||||
import { MatrixClient } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";
|
||||
|
@ -37,16 +37,9 @@ describe("CryptographyPanel", () => {
|
|||
const rendered = render(<CryptographyPanel />);
|
||||
|
||||
// Then it displays info about the user's session
|
||||
const codes = rendered.querySelectorAll("code");
|
||||
const codes = rendered.container.querySelectorAll("code");
|
||||
expect(codes.length).toEqual(2);
|
||||
expect(codes[0].innerHTML).toEqual(sessionId);
|
||||
expect(codes[1].innerHTML).toEqual(sessionKeyFormatted);
|
||||
});
|
||||
});
|
||||
|
||||
function render(component: ReactElement<CryptographyPanel>): HTMLDivElement {
|
||||
const parentDiv = document.createElement("div");
|
||||
document.body.appendChild(parentDiv);
|
||||
ReactDOM.render(component, parentDiv);
|
||||
return parentDiv;
|
||||
}
|
||||
|
|
|
@ -14,8 +14,7 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
import React from "react";
|
||||
import { fireEvent, render } from "@testing-library/react";
|
||||
import { act } from "react-dom/test-utils";
|
||||
import { act, fireEvent, render } from "@testing-library/react";
|
||||
import { CrossSigningInfo } from "matrix-js-sdk/src/crypto/CrossSigning";
|
||||
import { DeviceInfo } from "matrix-js-sdk/src/crypto/deviceinfo";
|
||||
import { sleep } from "matrix-js-sdk/src/utils";
|
||||
|
|
|
@ -25,8 +25,7 @@ import {
|
|||
PushRuleActionName,
|
||||
} from "matrix-js-sdk/src/matrix";
|
||||
import { IThreepid, ThreepidMedium } from "matrix-js-sdk/src/@types/threepids";
|
||||
import { act } from "react-dom/test-utils";
|
||||
import { fireEvent, getByTestId, render, screen, waitFor } from "@testing-library/react";
|
||||
import { act, fireEvent, getByTestId, render, screen, waitFor } from "@testing-library/react";
|
||||
|
||||
import Notifications from "../../../../src/components/views/settings/Notifications";
|
||||
import SettingsStore from "../../../../src/settings/SettingsStore";
|
||||
|
|
|
@ -12,8 +12,8 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { render } from "@testing-library/react";
|
||||
import React from "react";
|
||||
import { renderIntoDocument } from "react-dom/test-utils";
|
||||
|
||||
import SettingsFieldset from "../../../../src/components/views/settings/SettingsFieldset";
|
||||
|
||||
|
@ -21,24 +21,19 @@ describe("<SettingsFieldset />", () => {
|
|||
const defaultProps = {
|
||||
"legend": "Who can read history?",
|
||||
"children": <div>test</div>,
|
||||
"data-test-id": "test",
|
||||
"data-testid": "test",
|
||||
};
|
||||
const getComponent = (props = {}) => {
|
||||
const wrapper = renderIntoDocument<HTMLDivElement>(
|
||||
<div>
|
||||
<SettingsFieldset {...defaultProps} {...props} />
|
||||
</div>,
|
||||
) as HTMLDivElement;
|
||||
return wrapper.children[0];
|
||||
return render(<SettingsFieldset {...defaultProps} {...props} />);
|
||||
};
|
||||
|
||||
it("renders fieldset without description", () => {
|
||||
expect(getComponent()).toMatchSnapshot();
|
||||
expect(getComponent().asFragment()).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it("renders fieldset with plain text description", () => {
|
||||
const description = "Changes to who can read history.";
|
||||
expect(getComponent({ description })).toMatchSnapshot();
|
||||
expect(getComponent({ description }).asFragment()).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it("renders fieldset with react description", () => {
|
||||
|
@ -48,6 +43,6 @@ describe("<SettingsFieldset />", () => {
|
|||
<a href="#test">a link</a>
|
||||
</>
|
||||
);
|
||||
expect(getComponent({ description })).toMatchSnapshot();
|
||||
expect(getComponent({ description }).asFragment()).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,66 +1,72 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`<SettingsFieldset /> renders fieldset with plain text description 1`] = `
|
||||
<fieldset
|
||||
class="mx_SettingsFieldset"
|
||||
data-test-id="test"
|
||||
>
|
||||
<legend
|
||||
class="mx_SettingsFieldset_legend"
|
||||
<DocumentFragment>
|
||||
<fieldset
|
||||
class="mx_SettingsFieldset"
|
||||
data-testid="test"
|
||||
>
|
||||
Who can read history?
|
||||
</legend>
|
||||
<div
|
||||
class="mx_SettingsFieldset_description"
|
||||
>
|
||||
Changes to who can read history.
|
||||
</div>
|
||||
<div>
|
||||
test
|
||||
</div>
|
||||
</fieldset>
|
||||
<legend
|
||||
class="mx_SettingsFieldset_legend"
|
||||
>
|
||||
Who can read history?
|
||||
</legend>
|
||||
<div
|
||||
class="mx_SettingsFieldset_description"
|
||||
>
|
||||
Changes to who can read history.
|
||||
</div>
|
||||
<div>
|
||||
test
|
||||
</div>
|
||||
</fieldset>
|
||||
</DocumentFragment>
|
||||
`;
|
||||
|
||||
exports[`<SettingsFieldset /> renders fieldset with react description 1`] = `
|
||||
<fieldset
|
||||
class="mx_SettingsFieldset"
|
||||
data-test-id="test"
|
||||
>
|
||||
<legend
|
||||
class="mx_SettingsFieldset_legend"
|
||||
<DocumentFragment>
|
||||
<fieldset
|
||||
class="mx_SettingsFieldset"
|
||||
data-testid="test"
|
||||
>
|
||||
Who can read history?
|
||||
</legend>
|
||||
<div
|
||||
class="mx_SettingsFieldset_description"
|
||||
>
|
||||
<p>
|
||||
Test
|
||||
</p>
|
||||
<a
|
||||
href="#test"
|
||||
<legend
|
||||
class="mx_SettingsFieldset_legend"
|
||||
>
|
||||
a link
|
||||
</a>
|
||||
</div>
|
||||
<div>
|
||||
test
|
||||
</div>
|
||||
</fieldset>
|
||||
Who can read history?
|
||||
</legend>
|
||||
<div
|
||||
class="mx_SettingsFieldset_description"
|
||||
>
|
||||
<p>
|
||||
Test
|
||||
</p>
|
||||
<a
|
||||
href="#test"
|
||||
>
|
||||
a link
|
||||
</a>
|
||||
</div>
|
||||
<div>
|
||||
test
|
||||
</div>
|
||||
</fieldset>
|
||||
</DocumentFragment>
|
||||
`;
|
||||
|
||||
exports[`<SettingsFieldset /> renders fieldset without description 1`] = `
|
||||
<fieldset
|
||||
class="mx_SettingsFieldset"
|
||||
data-test-id="test"
|
||||
>
|
||||
<legend
|
||||
class="mx_SettingsFieldset_legend"
|
||||
<DocumentFragment>
|
||||
<fieldset
|
||||
class="mx_SettingsFieldset"
|
||||
data-testid="test"
|
||||
>
|
||||
Who can read history?
|
||||
</legend>
|
||||
<div>
|
||||
test
|
||||
</div>
|
||||
</fieldset>
|
||||
<legend
|
||||
class="mx_SettingsFieldset_legend"
|
||||
>
|
||||
Who can read history?
|
||||
</legend>
|
||||
<div>
|
||||
test
|
||||
</div>
|
||||
</fieldset>
|
||||
</DocumentFragment>
|
||||
`;
|
||||
|
|
|
@ -15,8 +15,7 @@ limitations under the License.
|
|||
*/
|
||||
|
||||
import React from "react";
|
||||
import { fireEvent, render } from "@testing-library/react";
|
||||
import { act } from "react-dom/test-utils";
|
||||
import { act, fireEvent, render } from "@testing-library/react";
|
||||
|
||||
import CurrentDeviceSection from "../../../../../src/components/views/settings/devices/CurrentDeviceSection";
|
||||
import { DeviceType } from "../../../../../src/utils/device/parseUserAgent";
|
||||
|
|
|
@ -14,9 +14,8 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { fireEvent, render } from "@testing-library/react";
|
||||
import { act, fireEvent, render } from "@testing-library/react";
|
||||
import React from "react";
|
||||
import { act } from "react-dom/test-utils";
|
||||
|
||||
import SelectableDeviceTile from "../../../../../src/components/views/settings/devices/SelectableDeviceTile";
|
||||
import { DeviceType } from "../../../../../src/utils/device/parseUserAgent";
|
||||
|
|
|
@ -15,8 +15,7 @@ limitations under the License.
|
|||
*/
|
||||
|
||||
import React from "react";
|
||||
import { fireEvent, render, RenderResult } from "@testing-library/react";
|
||||
import { act } from "react-dom/test-utils";
|
||||
import { act, fireEvent, render, RenderResult } from "@testing-library/react";
|
||||
import { DeviceInfo } from "matrix-js-sdk/src/crypto/deviceinfo";
|
||||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
import { DeviceTrustLevel } from "matrix-js-sdk/src/crypto/CrossSigning";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue