JSFiddle - React, Tailwind, and code Playground
JavaScript
describe("Directive : Search Input", function() {
var element, e, window, scope, controller, SearchService, userService, $stateParams;
beforeEach(module("app"));
beforeEach(module('src/templates/search-input.html'));
beforeEach(module(function($provide) {
userService = {
profile : {
name : 'Unit Test'
}
};
$stateParams = {
query : 'test'
};
SearchService = {
getSearchSuggestion: function(){
var deferred = q.defer();
deferred.resolve([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]);
return deferred.promise;
}
};
$provide.service('SearchService', function() {return SearchService});
$provide.value('userService', userService);
$provide.value('$stateParams', $stateParams);
})
);
beforeEach(inject(function($compile, $rootScope, _$window_) {
scope = $rootScope.$new();
window = _$window_;
e = $.Event('keypress');
e.keyCode = 23;
e.type = "noClick";
element = angular.element("<search-input></search-input>");
window.innerWidth = 700;
$compile(element)(scope);
scope.$digest();
controller = element.controller("searchInput");
}));
describe("when window inner width is greater or equal to 680", function(){
it("should return [placeholder]header.placeholder", function(){
expect(element.scope().getSearchText()).toBe("[placeholder]header.placeholder");
});
});
describe("controller name ", function(){
it("should be equal to profile name in userservice", function(){
expect(controller.name).toBe("Unit Test");
});
});
describe("find click ", function(){
it("Should return a false", function(){
expect(controller.find(e)).toBeFalsy();
})
});
describe("mouse movement ", function(){
it("mouse enter should update selectedList", function(){
element.scope().mouseEnter(6);
expect(element.scope().selectedList).toBe(6);
});
it("mouse leave should update...