MCPcopy
hub / github.com/palantir/blueprint / buttonTestSuite

Function buttonTestSuite

packages/core/test/buttons/buttonTests.tsx:30–208  ·  view source on GitHub ↗
(component: React.ComponentClass<any>, tagName: string)

Source from the content-addressed store, hash-verified

28});
29
30function buttonTestSuite(component: React.ComponentClass<any>, tagName: string) {
31 describe(`<${component.displayName.split(".")[1]}>`, () => {
32 it("renders its contents", () => {
33 const wrapper = button({ className: "foo" });
34 assert.isTrue(wrapper.is(tagName));
35 assert.isTrue(wrapper.hasClass(Classes.BUTTON));
36 assert.isTrue(wrapper.hasClass("foo"));
37 });
38
39 it('icon="style" renders Icon as first child', () => {
40 const wrapper = button({ icon: "style" });
41 const firstChild = wrapper.find(Icon).at(0);
42 assert.strictEqual(firstChild.prop("icon"), "style");
43 });
44
45 it("renders the button text prop", () => {
46 const wrapper = button({ text: "some text" }, true);
47 assert.equal(wrapper.text(), "some text");
48 });
49
50 it("wraps string children in spans", () => {
51 // so text can be hidden when loading
52 const wrapper = button({}, true, "raw string", <em>not a string</em>);
53 assert.equal(wrapper.find("span").length, 1, "span not found");
54 assert.equal(wrapper.find("em").length, 1, "em not found");
55 });
56
57 it("renders span if text={0}", () => {
58 const wrapper = button({ text: 0 }, true);
59 assert.equal(wrapper.text(), "0");
60 });
61
62 it('doesn\'t render a span if text=""', () => {
63 assert.equal(button({}, true, "").find("span").length, 0);
64 assert.equal(button({ text: "" }, true).find("span").length, 0);
65 });
66
67 it("renders a loading spinner when the loading prop is true", () => {
68 const wrapper = button({ loading: true });
69 assert.lengthOf(wrapper.find(Spinner), 1);
70 });
71
72 it("button is disabled when the loading prop is true", () => {
73 const wrapper = button({ loading: true });
74 assert.isTrue(wrapper.hasClass(Classes.DISABLED));
75 });
76
77 it("clicking button triggers onClick prop", () => {
78 const onClick = spy();
79 button({ onClick }).simulate("click");
80 assert.equal(onClick.callCount, 1);
81 });
82
83 it("clicking disabled button does not trigger onClick prop", () => {
84 const onClick = spy();
85 // full DOM mount so `button` element will ignore click
86 button({ disabled: true, onClick }, true).simulate("click");
87 assert.equal(onClick.callCount, 0);

Callers 1

buttonTests.tsxFile · 0.85

Calls 9

buttonFunction · 0.85
spyFunction · 0.85
hasClassMethod · 0.80
findMethod · 0.80
textMethod · 0.80
setTimeoutFunction · 0.50
mountFunction · 0.50

Tested by

no test coverage detected