-
Notifications
You must be signed in to change notification settings - Fork 363
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import Checkbox from "./../../lib/Styled/Checkbox/Checkbox"; | ||
import { mount } from "enzyme"; | ||
import { ICheckboxProps } from "../../lib/Styled/Checkbox/types"; | ||
import CheckboxIcon from "./../../lib/Styled/Checkbox/Elements/CheckboxIcon"; | ||
import jasmineEnzyme from "jasmine-enzyme"; | ||
import React from "react"; | ||
|
||
describe("Checkbox", function() { | ||
beforeEach(() => { | ||
jasmineEnzyme(); | ||
}); | ||
const mountCheckbox = (overridingProps: ICheckboxProps) => | ||
mount( | ||
<Checkbox label="" onChange={() => {}} name="stub" {...overridingProps} /> | ||
); | ||
|
||
describe("basic", () => { | ||
it("keeps isChecked as false when passing it as prop and calling onChange", () => { | ||
const cb = mountCheckbox({ isChecked: false, onChange: undefined }); | ||
cb.find("input").simulate("change", { target: { checked: true } }); | ||
expect(cb.find("input").prop("checked")).toBe(false); | ||
}); | ||
|
||
it("keeps isChecked as true when passing it as prop and calling onChange", () => { | ||
const cb = mountCheckbox({ isChecked: true, onChange: undefined }); | ||
cb.find("input").simulate("change", { target: { checked: false } }); | ||
expect(cb.find("input").prop("checked")).toBe(true); | ||
}); | ||
|
||
it("should be unchecked by default", () => { | ||
const cb = mountCheckbox({ defaultChecked: false }); | ||
expect(cb.find("input[checked]").length === 1).toBe(true); | ||
}); | ||
|
||
it("should call onchange on change", () => { | ||
const spy = jasmine.createSpy(); | ||
const cb = mountCheckbox({ isChecked: false, onChange: spy }); | ||
cb.find("input").simulate("change", { target: { checked: true } }); | ||
expect(cb.find(Checkbox).prop("isChecked")).toBe(false); | ||
expect(spy).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it("should call onchange once", () => { | ||
const spy = jasmine.createSpy(); | ||
const cb = mountCheckbox({ onChange: spy }); | ||
cb.find("input").simulate("change"); | ||
expect(spy).toHaveBeenCalledTimes(1); | ||
}); | ||
}); | ||
|
||
describe("defaultChecked", () => { | ||
it("should render defaultChecked", () => { | ||
const cb = mountCheckbox({ defaultChecked: true }); | ||
|
||
const element = cb.find("input"); | ||
expect(element.prop("checked")).toBe(true); | ||
}); | ||
it("should render defaultChecked={undefined}", () => { | ||
const cb = mountCheckbox({}); | ||
|
||
const element = cb.find("input"); | ||
expect(element.prop("checked")).toBe(false); | ||
}); | ||
}); | ||
|
||
describe("disabled", () => { | ||
it("should show a not-allowed cursor", () => { | ||
const cb = mountCheckbox({ isDisabled: true }); | ||
expect(cb.find("input")).toBeDisabled(); | ||
}); | ||
}); | ||
}); |