salix/client/item/src/diary/index.spec.js

66 lines
2.2 KiB
JavaScript
Raw Normal View History

import './index.js';
describe('Item', () => {
describe('Component vnItemDiary', () => {
let $componentController;
let $scope;
let controller;
let $httpBackend;
beforeEach(() => {
angular.mock.module('item');
});
beforeEach(angular.mock.inject((_$componentController_, $rootScope, _$httpBackend_) => {
$componentController = _$componentController_;
$httpBackend = _$httpBackend_;
$httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({});
$scope = $rootScope.$new();
controller = $componentController('vnItemDiary', {$scope: $scope});
controller.$scope.model = {};
}));
describe('isToday()', () => {
it(`should call isToday() an return true if an specified date is the current date`, () => {
let date = new Date();
let result = controller.isToday(date);
expect(result).toBeTruthy();
});
it(`should call isToday() an return false if an specified date is the current date`, () => {
let date = '2018-07-03';
let result = controller.isToday(date);
expect(result).toBeFalsy();
});
});
describe('alertLevelIndex()', () => {
it(`should call alertLevelIndex() and return an index from line with alertLevel 0 and current date`, () => {
controller.$scope.model = {data: [
{name: 'My item 1', alertLevel: 3, date: '2018-05-02'},
{name: 'My item 2', alertLevel: 1, date: '2018-05-03'},
{name: 'My item 3', alertLevel: 0, date: new Date()}]
};
let result = controller.alertLevelIndex;
expect(result).toEqual(2);
});
});
describe('set item()', () => {
it(`should call filterBuilder()`, () => {
spyOn(controller, 'filterBuilder');
controller.item = {id: 1};
expect(controller.filterBuilder).toHaveBeenCalledWith();
expect(controller.item).toEqual({id: 1});
});
});
});
});