salix/front/core/components/check/index.spec.js

63 lines
1.7 KiB
JavaScript
Raw Permalink Normal View History

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;
let element;
2019-02-19 06:04:56 +00:00
beforeEach(ngModule('vnCore'));
2019-02-19 06:04:56 +00:00
beforeEach(inject(($compile, $rootScope) => {
$element = $compile(`<vn-check></vn-check>`)($rootScope);
2019-10-26 10:04:48 +00:00
controller = $element.controller('vnCheck');
element = $element[0];
2019-02-19 06:04:56 +00:00
}));
afterEach(() => {
$element.remove();
});
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
});
it(`should uncheck value and change to true when clicked`, () => {
2019-10-26 10:04:48 +00:00
controller.field = false;
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
});
it(`should check value and change to false when clicked`, () => {
2019-10-26 10:04:48 +00:00
controller.field = true;
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
});
it(`should check value and change to false when clicked`, () => {
2019-10-26 10:04:48 +00:00
controller.field = true;
controller.tripleState = true;
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
});
it(`should set value to null and change to true when clicked`, () => {
2019-10-26 10:04:48 +00:00
controller.tripleState = true;
2023-03-07 07:13:07 +00:00
controller.field = null;
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
});
it(`should cast value to boolean when clicked`, () => {
2019-10-26 10:04:48 +00:00
controller.field = 0;
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
});
});
});