39 lines
1.0 KiB
JavaScript
39 lines
1.0 KiB
JavaScript
describe('Component vnRating', () => {
|
|
let $element;
|
|
let $ctrl;
|
|
|
|
beforeEach(ngModule('vnCore'));
|
|
|
|
beforeEach(inject(($compile, $rootScope) => {
|
|
$element = $compile(`<vn-rating ng-model="$ctrl.stars"></vn-rating>`)($rootScope);
|
|
$ctrl = $element.controller('vnRating');
|
|
}));
|
|
|
|
afterEach(() => {
|
|
$element.remove();
|
|
});
|
|
|
|
describe('field() setter', () => {
|
|
it(`should change field value and then call the populateStars() method`, () => {
|
|
jest.spyOn($ctrl, 'populateStars');
|
|
|
|
$ctrl.field = 5;
|
|
|
|
expect($ctrl.populateStars).toHaveBeenCalledWith();
|
|
expect($ctrl.stars.length).toEqual(5);
|
|
});
|
|
});
|
|
|
|
describe('populateStars()', () => {
|
|
it(`should populate the stars array and mark four of them as active`, () => {
|
|
jest.spyOn($ctrl, 'populateStars');
|
|
|
|
$ctrl.field = 4;
|
|
|
|
const activeStars = $ctrl.stars.filter(star => star.isActive);
|
|
|
|
expect(activeStars.length).toEqual(4);
|
|
});
|
|
});
|
|
});
|