Convert FormAccess test to use React Testing Library

This commit is contained in:
Jon Koops 2021-07-07 11:58:35 +02:00 committed by Jon Koops
parent dd15b13a4c
commit ffe9f74294
2 changed files with 16 additions and 20 deletions

View file

@ -2,7 +2,7 @@
// allows you to do things like:
// expect(element).toHaveTextContent(/react/i)
// learn more: https://github.com/testing-library/jest-dom
import "@testing-library/jest-dom/extend-expect";
import "@testing-library/jest-dom";
import i18n from 'i18next';
import { initReactI18next } from 'react-i18next';

View file

@ -1,17 +1,15 @@
import React from "react";
import { mount } from "enzyme";
import { Controller, useForm } from "react-hook-form";
import { FormGroup, Switch, TextInput } from "@patternfly/react-core";
import { render, screen } from "@testing-library/react";
import type WhoAmIRepresentation from "keycloak-admin/lib/defs/whoAmIRepresentation";
import React from "react";
import { Controller, useForm } from "react-hook-form";
import { AccessContextProvider } from "../../context/access/Access";
import { RealmContext } from "../../context/realm-context/RealmContext";
import { WhoAmI, WhoAmIContext } from "../../context/whoami/WhoAmI";
import whoami from "../../context/whoami/__tests__/mock-whoami.json";
import { FormAccess } from "./FormAccess";
import { WhoAmI, WhoAmIContext } from "../../../context/whoami/WhoAmI";
import whoami from "../../../context/whoami/__tests__/mock-whoami.json";
import { RealmContext } from "../../../context/realm-context/RealmContext";
import { AccessContextProvider } from "../../../context/access/Access";
import { FormAccess } from "../FormAccess";
describe("<FormAccess />", () => {
describe("FormAccess", () => {
const Form = ({ realm }: { realm: string }) => {
const { register, control } = useForm();
return (
@ -35,6 +33,7 @@ describe("<FormAccess />", () => {
<TextInput
type="text"
id="field"
data-testid="field"
name="fieldName"
ref={register()}
/>
@ -45,7 +44,7 @@ describe("<FormAccess />", () => {
control={control}
render={({ onChange, value }) => (
<Switch
id="kc-consent"
data-testid="kc-consent"
label={"on"}
labelOff="off"
isChecked={value}
@ -60,12 +59,9 @@ describe("<FormAccess />", () => {
);
};
it("render form disabled for test realm", () => {
const container = mount(<Form realm="test" />);
const disabled = container.find("input#field").props().disabled;
expect(disabled).toBe(true);
expect(container.find("input#kc-consent").props().disabled).toBe(true);
it("renders disabled form for test realm", () => {
render(<Form realm="test" />);
expect(screen.getByTestId("field")).toBeDisabled();
expect(screen.getByTestId("kc-consent")).toBeDisabled();
});
});