aboutsummaryrefslogtreecommitdiff
path: root/test/settings/components/ui/Text.test.tsx
blob: d5451bb69e533bc715508760ceb4b8184bc9688d (plain) (blame)
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
import React from "react";
import ReactDOM from "react-dom";
import ReactTestUtils from "react-dom/test-utils";
import Text from "../../../../src/settings/components/ui/Text";
import { expect } from "chai";

describe("settings/ui/Text", () => {
  let container: HTMLDivElement;

  beforeEach(() => {
    container = document.createElement("div");
    document.body.appendChild(container);
  });

  afterEach(() => {
    document.body.removeChild(container);
  });

  it("renders text input", () => {
    ReactTestUtils.act(() => {
      ReactDOM.render(
        <Text name="myname" label="myfield" value="myvalue" />,
        container
      );
    });

    const label = document.querySelector("label")!;
    const input = document.querySelector("input")!;
    expect(label.textContent).to.contain("myfield");
    expect(input.type).to.contain("text");
    expect(input.name).to.contain("myname");
    expect(input.value).to.contain("myvalue");
  });

  it("invoke onChange", (done) => {
    ReactTestUtils.act(() => {
      ReactDOM.render(
        <Text
          name="myname"
          label="myfield"
          value="myvalue"
          onChange={(e) => {
            expect((e.target as HTMLInputElement).value).to.equal("newvalue");
            done();
          }}
        />,
        container
      );
    });

    const input = document.querySelector("input")!;
    input.value = "newvalue";
    ReactTestUtils.Simulate.change(input);
  });
});