-
Notifications
You must be signed in to change notification settings - Fork 4
/
Autocomplete-test.tsx
70 lines (63 loc) · 1.97 KB
/
Autocomplete-test.tsx
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
import { expect } from "chai";
import { stub } from "sinon";
import * as React from "react";
import { shallow, mount } from "enzyme";
import Autocomplete from "../Autocomplete";
import EditableInput from "../EditableInput";
describe("Autocomplete", () => {
let wrapper;
const autocompleteValues = ["a", "b", "c"];
beforeEach(() => {
wrapper = shallow(
<Autocomplete
autocompleteValues={autocompleteValues}
disabled={false}
name="test"
label="Test"
value="b"
/>
);
});
describe("rendering", () => {
it("shows input", () => {
const input = wrapper.find(EditableInput);
expect(input.length).to.equal(1);
expect(input.props().type).to.equal("text");
expect(input.props().disabled).to.equal(false);
expect(input.props().name).to.equal("test");
expect(input.props().label).to.equal("Test");
expect(input.props().value).to.equal("b");
expect(input.props().list).to.equal("test-autocomplete-list");
});
it("shows autocomplete list", () => {
const list = wrapper.find("datalist");
expect(list.length).to.equal(1);
expect(list.props().id).to.equal("test-autocomplete-list");
const options = list.find("option");
expect(options.length).to.equal(3);
expect(options.at(0).props().value).to.equal("a");
expect(options.at(1).props().value).to.equal("b");
expect(options.at(2).props().value).to.equal("c");
});
});
describe("behavior", () => {
it("returns value", () => {
wrapper = mount(
<Autocomplete
autocompleteValues={autocompleteValues}
disabled={false}
name="test"
label="Test"
value="b"
/>
);
const getValueStub = stub(EditableInput.prototype, "getValue").returns(
"test value"
);
expect((wrapper.instance() as Autocomplete).getValue()).to.equal(
"test value"
);
getValueStub.restore();
});
});
});