Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alecf committed Mar 27, 2019
1 parent 4a8bf47 commit 3db153f
Showing 1 changed file with 39 additions and 7 deletions.
46 changes: 39 additions & 7 deletions packages/table/test/editableCellTests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ import { mount } from "enzyme";
import * as React from "react";
import * as sinon from "sinon";

import * as Classes from "../src/common/classes";
import { Classes } from "@blueprintjs/core";
import * as TableClasses from "../src/common/classes";
import { EditableCell } from "../src/index";
import { CellType, expectCellLoading } from "./cellTestUtils";

describe("<EditableCell>", () => {
it("renders", () => {
const elem = mount(<EditableCell value="test-value-5000" />);
expect(elem.find(`.${Classes.TABLE_TRUNCATED_TEXT}`).text()).to.equal("test-value-5000");
expect(elem.find(`.${TableClasses.TABLE_TRUNCATED_TEXT}`).text()).to.equal("test-value-5000");
});

it("renders loading state", () => {
Expand All @@ -29,10 +30,10 @@ describe("<EditableCell>", () => {
const VALUE_2 = "bar";

const elem = mount(<EditableCell value={VALUE_1} />);
expect(elem.find(`.${Classes.TABLE_TRUNCATED_TEXT}`).text()).to.equal(VALUE_1);
expect(elem.find(`.${TableClasses.TABLE_TRUNCATED_TEXT}`).text()).to.equal(VALUE_1);

elem.setProps({ value: VALUE_2 });
expect(elem.find(`.${Classes.TABLE_TRUNCATED_TEXT}`).text()).to.equal(VALUE_2);
expect(elem.find(`.${TableClasses.TABLE_TRUNCATED_TEXT}`).text()).to.equal(VALUE_2);
});

it("edits", () => {
Expand Down Expand Up @@ -73,7 +74,7 @@ describe("<EditableCell>", () => {

// start editing
elem.setState({ isEditing: true, dirtyValue: "test-value-5000" });
const input = elem.find(`.${Classes.TABLE_EDITABLE_TEXT} input`);
const input = elem.find(`.${TableClasses.TABLE_EDITABLE_TEXT} input`);
expect(input.length).to.equal(1);

// make changes
Expand Down Expand Up @@ -129,11 +130,42 @@ describe("<EditableCell>", () => {

it("defaults to no wrapText", () => {
const elem = mount(<EditableCell />);
expect(elem.find(`.${Classes.TABLE_NO_WRAP_TEXT}`).exists()).to.be.true;
expect(elem.find(`.${TableClasses.TABLE_NO_WRAP_TEXT}`).exists()).to.be.true;
});

it("wraps text when wrapText is true", () => {
const elem = mount(<EditableCell wrapText={true} />);
expect(elem.find(`.${Classes.TABLE_NO_WRAP_TEXT}`).exists()).to.be.false;
expect(elem.find(`.${TableClasses.TABLE_NO_WRAP_TEXT}`).exists()).to.be.false;
});

it("Passes editableTextProps to inner EditableText", () => {
const onCancel = sinon.spy();
const onChange = sinon.spy();
const onConfirm = sinon.spy();

const elem = mount(
<EditableCell
value="test-value-5000"
onCancel={onCancel}
onChange={onChange}
onConfirm={onConfirm}
editableTextProps={{
className: "input-only-class",
maxLength: 345,
value: "ignore this",
}}
/>,
);

// start editing
elem.setState({ isEditing: true, dirtyValue: "test-value-5000" });
const input = elem.find("input");
console.log("input = ", elem.debug());
// input props that EditableCell does not care about should pass through unchanged
expect(input.prop("maxLength")).to.equal(345);
expect(elem.find(`.${Classes.EDITABLE_TEXT}`).prop("className")).to.contain("input-only-class");

// But special values should be overridden by EditableCell
expect(input.prop("value")).to.equal("test-value-5000");
});
});

0 comments on commit 3db153f

Please sign in to comment.