2019-02-19 06:05:39 +00:00
|
|
|
describe('Component vnCheck', () => {
|
2019-02-19 06:04:56 +00:00
|
|
|
let $element;
|
2019-10-26 10:04:48 +00:00
|
|
|
let controller;
|
2019-09-30 18:46:22 +00:00
|
|
|
let element;
|
2019-02-19 06:04:56 +00:00
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
beforeEach(ngModule('vnCore'));
|
2019-02-19 06:04:56 +00:00
|
|
|
|
|
|
|
beforeEach(inject(($compile, $rootScope) => {
|
2019-10-08 21:57:02 +00:00
|
|
|
$element = $compile(`<vn-check></vn-check>`)($rootScope);
|
2019-10-26 10:04:48 +00:00
|
|
|
controller = $element.controller('vnCheck');
|
2019-09-30 18:46:22 +00:00
|
|
|
element = $element[0];
|
2019-02-19 06:04:56 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
$element.remove();
|
|
|
|
});
|
|
|
|
|
2019-09-30 18:46:22 +00:00
|
|
|
describe('field() setter', () => {
|
2019-02-19 06:04:56 +00:00
|
|
|
it(`should set model value`, () => {
|
2019-10-26 10:04:48 +00:00
|
|
|
controller.field = true;
|
2019-02-19 06:04:56 +00:00
|
|
|
|
2019-10-26 10:04:48 +00:00
|
|
|
expect(controller.field).toEqual(true);
|
2019-02-19 06:04:56 +00:00
|
|
|
});
|
|
|
|
|
2019-09-30 18:46:22 +00:00
|
|
|
it(`should uncheck value and change to true when clicked`, () => {
|
2019-10-26 10:04:48 +00:00
|
|
|
controller.field = false;
|
2019-09-30 18:46:22 +00:00
|
|
|
element.click();
|
2019-02-19 06:04:56 +00:00
|
|
|
|
2019-10-26 10:04:48 +00:00
|
|
|
expect(controller.field).toEqual(true);
|
2019-02-19 06:04:56 +00:00
|
|
|
});
|
|
|
|
|
2019-09-30 18:46:22 +00:00
|
|
|
it(`should check value and change to false when clicked`, () => {
|
2019-10-26 10:04:48 +00:00
|
|
|
controller.field = true;
|
2019-09-30 18:46:22 +00:00
|
|
|
element.click();
|
2019-02-19 06:04:56 +00:00
|
|
|
|
2019-10-26 10:04:48 +00:00
|
|
|
expect(controller.field).toEqual(false);
|
2019-02-19 06:04:56 +00:00
|
|
|
});
|
|
|
|
|
2019-10-01 09:15:15 +00:00
|
|
|
it(`should check value and change to false when clicked`, () => {
|
2019-10-26 10:04:48 +00:00
|
|
|
controller.field = true;
|
|
|
|
controller.tripleState = true;
|
2019-09-30 18:46:22 +00:00
|
|
|
element.click();
|
2019-02-19 06:04:56 +00:00
|
|
|
|
2019-10-26 10:04:48 +00:00
|
|
|
expect(controller.field).toEqual(false);
|
2019-02-19 06:04:56 +00:00
|
|
|
});
|
|
|
|
|
2019-10-01 09:15:15 +00:00
|
|
|
it(`should set value to null and change to true when clicked`, () => {
|
2019-10-26 10:04:48 +00:00
|
|
|
controller.field = null;
|
|
|
|
controller.tripleState = true;
|
2019-09-30 18:46:22 +00:00
|
|
|
element.click();
|
2019-02-19 06:04:56 +00:00
|
|
|
|
2019-10-26 10:04:48 +00:00
|
|
|
expect(controller.field).toEqual(true);
|
2019-02-19 06:04:56 +00:00
|
|
|
});
|
|
|
|
|
2019-09-30 18:46:22 +00:00
|
|
|
it(`should cast value to boolean when clicked`, () => {
|
2019-10-26 10:04:48 +00:00
|
|
|
controller.field = 0;
|
2019-09-30 18:46:22 +00:00
|
|
|
element.click();
|
2019-02-19 06:04:56 +00:00
|
|
|
|
2019-10-26 10:04:48 +00:00
|
|
|
expect(controller.field).toEqual(true);
|
2019-02-19 06:04:56 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|