forked from jeff-collins/ment.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
67 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"directory" : "bower_components" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,87 @@ | ||
'use strict'; | ||
|
||
describe('mentio-menu directive', function () { | ||
var $compile, $rootScope; | ||
describe('mentio-menu', function () { | ||
var $compile, $rootScope, $templateCache, mentionRuleScope, menuScope, searchSpy, mockItems; | ||
|
||
beforeEach(module('mentio')); | ||
|
||
beforeEach(inject(function (_$compile_, _$rootScope_) { | ||
beforeEach(inject(function (_$compile_, _$rootScope_, _$templateCache_) { | ||
$compile = _$compile_; | ||
$rootScope = _$rootScope_; | ||
})); | ||
|
||
it('should search on items', function () { | ||
var element, $renderScope, $scope, searchSpy, mockItems; | ||
|
||
mockItems = [ | ||
{ | ||
id: 1 | ||
}, | ||
{ | ||
id: 2 | ||
$templateCache = _$templateCache_; | ||
|
||
$templateCache.put('/people-mentions.tpl', | ||
'<div>' + | ||
'<li mentio-menu-item="person" ng-repeat="person in items">' + | ||
' <img ng-src="{{person._source.imageUrl}}"><p class="name">{{person._source.name}}</p>' + | ||
' <p>{{person._source.bio.substring(0,30)}}</p>' + | ||
'</li>' + | ||
'</ul>' + | ||
'</div>'); | ||
|
||
var $scope = $rootScope.$new(); | ||
|
||
var mentionableTextArea = angular.element('<div><textarea ng-model="textArea" ng-trim="false"></textarea>' + | ||
'<span>Mentioned: {{atVar}}</span></div>'); | ||
|
||
$compile(mentionableTextArea)($scope); | ||
var mentionableTextAreaScope = mentionableTextArea.scope(); | ||
mentionableTextAreaScope.$apply(); | ||
|
||
var mentionMenu = angular.element('<mentio-menu bind="textArea" ng-model="atVar2" ng-cloak>' + | ||
'<mentio-rule trigger-char="@" items="people" template="/people-mentions.tpl" ' + | ||
'search="searchPeople(term)" select="getPeopleTextRaw(item)"></mentio-rule>' + | ||
'</mentio-menu>'); | ||
|
||
$compile(mentionMenu)($scope); | ||
var mentionMenuScope = mentionMenu.scope(); | ||
mentionMenuScope.$apply(); | ||
|
||
// This is ugly, uses undocumented method to access the child scopes | ||
for(var cs = $scope.$$childHead; cs; cs = cs.$$nextSibling) { | ||
if(cs.hide) { | ||
mentionRuleScope = cs; | ||
} | ||
]; | ||
if(cs.query) { | ||
menuScope = cs; | ||
} | ||
} | ||
|
||
$renderScope = $rootScope.$new(); | ||
mockItems = [ { id: 1 }, { id: 2 } ]; | ||
|
||
$renderScope.search = function (term) { | ||
if (term === 'foo') { | ||
$renderScope.items = mockItems; | ||
mentionRuleScope.search = function (object) { | ||
if (object.term === 'foo') { | ||
mentionRuleScope.items = mockItems; | ||
} else { | ||
$renderScope.items = []; | ||
mentionRuleScope.items = []; | ||
} | ||
}; | ||
|
||
searchSpy = spyOn($renderScope, 'search'); | ||
searchSpy = spyOn(mentionRuleScope, 'search'); | ||
searchSpy.andCallThrough(); | ||
})); | ||
|
||
element = $compile('<div mentio-menu bind="content" items="items"' + | ||
'search="search(term)" select="select(item)" ng-model="menuContent">')($renderScope); | ||
|
||
$renderScope.$digest(); | ||
|
||
$scope = element.isolateScope(); | ||
|
||
// TODO: move getAtMentionInfo() into a service so it can be mocked | ||
$scope.atVar = 'foo'; | ||
expect($scope.hide).toBeTruthy(); | ||
$scope.query(); | ||
|
||
$renderScope.$digest(); | ||
it('should show mentio for valid search term', function () { | ||
expect(mentionRuleScope.hide).toBeTruthy(); | ||
|
||
expect(searchSpy).toHaveBeenCalledWith('foo'); | ||
expect($scope.items).toEqual(mockItems); | ||
expect($scope.hide).toBeFalsy(); | ||
menuScope.atVar = 'foo'; | ||
menuScope.query('@'); | ||
menuScope.$apply(); | ||
|
||
expect(searchSpy).toHaveBeenCalledWith({ term : 'foo' }); | ||
expect(mentionRuleScope.items).toEqual(mockItems); | ||
expect(mentionRuleScope.hide).toBeFalsy(); | ||
}); | ||
|
||
/* | ||
* The menu should not display when the search returns no items | ||
*/ | ||
$scope.atVar = 'bar'; | ||
$scope.query(); | ||
it('should hide mentio for invalid search term', function () { | ||
expect(mentionRuleScope.hide).toBeTruthy(); | ||
|
||
$renderScope.$digest(); | ||
menuScope.atVar = 'fox'; | ||
menuScope.query('@'); | ||
menuScope.$apply(); | ||
|
||
expect(searchSpy.callCount).toBe(2); | ||
expect($scope.items).toEqual([]); | ||
expect($scope.hide).toBeTruthy(); | ||
expect(searchSpy).toHaveBeenCalledWith({ term : 'fox' }); | ||
expect(mentionRuleScope.items).toEqual([]); | ||
expect(mentionRuleScope.hide).toBeTruthy(); | ||
}); | ||
}); |