checkbox front unit test
gitea/salix/dev This commit looks good Details

This commit is contained in:
Joan Sanchez 2019-02-19 07:04:56 +01:00
parent e85c346f45
commit 79e8c1b19a
4 changed files with 68 additions and 6 deletions

View File

@ -1,5 +1,5 @@
<md-checkbox
aria-label="{{::$ctrl.label}}"
aria-label="::$ctrl.label"
md-indeterminate="$ctrl.isIntermediate"
ng-disabled="$ctrl.disabled"
ng-checked="$ctrl.isChecked"

View File

@ -16,9 +16,7 @@ export default class Controller extends Component {
set model(value) {
if (value === null) return;
if (this.model === true)
value = false;
else if (this.model === false && this.tripleState)
if (this.model === false && this.tripleState)
value = null;
this.emit('change', {value});

View File

@ -0,0 +1,64 @@
fdescribe('Component vnCheck', () => {
let controller;
let $element;
beforeEach(ngModule('vnCore'));
beforeEach(inject(($compile, $rootScope) => {
$element = $compile(`<vn-check></vn-check`)($rootScope);
controller = $element.controller('vnCheck');
}));
afterEach(() => {
$element.remove();
});
describe('model() setter', () => {
it(`should set model value`, () => {
controller.model = true;
expect(controller.model).toEqual(true);
});
it(`should set model value to null if current model value is false and is a triple-state checkbox`, () => {
controller._model = false;
controller.tripleState = true;
controller.model = true;
expect(controller.model).toEqual(null);
});
});
describe('field() setter', () => {
it(`should set model value`, () => {
controller.field = true;
expect(controller.field).toEqual(true);
});
it(`should set model value and convert numerical values to boolean values`, () => {
controller.field = 1;
expect(controller.field).toEqual(true);
});
});
describe('isIntermediate() getter', () => {
it(`should return true if intermediate property is truthy`, () => {
controller.intermediate = true;
let result = controller.isIntermediate;
expect(result).toEqual(true);
});
it(`should return true if is a triple-state checkbox and has null or undefined value`, () => {
controller.tripleState = true;
controller.model = null;
let result = controller.isIntermediate;
expect(result).toEqual(true);
});
});
});

View File

@ -32,12 +32,12 @@ vn-treeview {
background-color: $color-hover-cd
}
li.expanded .actions > vn-icon[icon="keyboard_arrow_down"] {
li.expanded > vn-horizontal > .actions > vn-icon[icon="keyboard_arrow_down"] {
transition: all 0.2s;
transform: rotate(180deg);
}
li.collapsed .actions > vn-icon[icon="keyboard_arrow_down"] {
li.collapsed > vn-horizontal > .actions > vn-icon[icon="keyboard_arrow_down"] {
transition: all 0.2s;
transform: rotate(0deg);
}