Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add internal text to switch component #3327

Merged
merged 15 commits into from
Feb 6, 2019
Prev Previous commit
Next Next commit
additional tests
  • Loading branch information
Leah Anderson committed Feb 6, 2019
commit e92267239a6df229dfe33e232babaab3fe5046cd
33 changes: 29 additions & 4 deletions packages/core/test/controls/controlsTests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,37 @@ describe("Controls:", () => {

controlsTests(Switch, "checkbox", Classes.SWITCH, () => {
describe("internal text", () => {
const switchWithText = mount(<Switch innerLabelChecked="Checked text" innerLabel="Unchecked text" />);
it("renders internal text", () => {
const innerTextNodes = switchWithText.find(`.${Classes.SWITCH}-inner-text`);
it("renders both innerLabels when both defined", () => {
const switchWithText = mount(<Switch innerLabelChecked="checked" innerLabel="unchecked" />);
const innerTextNodes = switchWithText.find(`.${Classes.SWITCH_INNER_TEXT}`);
const checkedTest = innerTextNodes.first().text();
const uncheckedText = innerTextNodes.last().text();
assert.lengthOf(innerTextNodes, 2);
assert.equal(checkedTest.trim(), "checked");
assert.equal(uncheckedText.trim(), "unchecked");
});
it("does not render innerLabel components when neither defined", () => {
const switchWithoutText = mount(<Switch />);
const innerTextNodes = switchWithoutText.find(`.${Classes.SWITCH_INNER_TEXT}`);
assert.lengthOf(innerTextNodes, 0);
});
it("renders innerLabel when innerLabelChecked is undefined", () => {
const switchWithText = mount(<Switch innerLabel="onlyInnerLabel" />);
const innerTextNodes = switchWithText.find(`.${Classes.SWITCH_INNER_TEXT}`);
const checkedText = innerTextNodes.last().text();
const uncheckedText = innerTextNodes.first().text();
assert.lengthOf(innerTextNodes, 2);
assert.equal(checkedText.trim(), "onlyInnerLabel");
assert.equal(checkedText.trim(), uncheckedText.trim());
});
it("renders innerLabelChecked only when checked", () => {
const switchWithText = mount(<Switch innerLabelChecked="onlyChecked" />);
const innerTextNodes = switchWithText.find(`.${Classes.SWITCH_INNER_TEXT}`);
const checked = innerTextNodes.first().text();
const uncheckedText = innerTextNodes.last().text();
assert.equal(uncheckedText.trim(), "Unchecked text");
assert.lengthOf(innerTextNodes, 2);
assert.equal(checked.trim(), "onlyChecked");
assert.equal(uncheckedText.trim(), "");
});
});
});
Expand Down