Skip to content

Commit

Permalink
Tests for the scroller
Browse files Browse the repository at this point in the history
  • Loading branch information
Kasparas Galdikas committed Feb 2, 2015
1 parent 7568d10 commit a7fb874
Showing 1 changed file with 76 additions and 0 deletions.
76 changes: 76 additions & 0 deletions tests/mentio.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,82 @@ describe('mentio-menu', function () {
expect(searchSpy).toHaveBeenCalledWith({ term : 'test1 ' });
});

it('should have a working isFirstItemActive method', function() {
createMentio($scope);
createMentioMenu($scope);

mentioScope.query('@', '');
mentioScope.$apply();

var menu = mentioScope.getActiveMenuScope();
expect(menu.isFirstItemActive()).toBe(true);

menu.activateNextItem();
expect(menu.isFirstItemActive()).toBe(false);
});

it('should have a working isLastItemActive method', function() {
createMentio($scope);
createMentioMenu($scope);

mentioScope.query('@', '');
mentioScope.$apply();

var menu = mentioScope.getActiveMenuScope();
expect(menu.isLastItemActive()).toBe(false);

menu.activatePreviousItem();
expect(menu.isLastItemActive()).toBe(true);
});

it('should have a working adjustScroll method', function() {
var menuItemsListEl = {
scrollTop: 0,
scrollHeight: 90
};

var menuItemEl = {
offsetHeight: 30
};

createMentio($scope);
createMentioMenu($scope);

mentioScope.query('@', '');
mentioScope.$apply();

var menuScope = mentioScope.getActiveMenuScope();

menuScope.items = [{ label: 'test1' }, { label: 'test2' }, { label: 'test3' }];
menuScope.$apply();

var menuEl = document.querySelector('mentio-menu');
var querySpy = spyOn(menuEl, 'querySelector').andCallFake(function(sel) {
if (sel === 'ul') return menuItemsListEl;

return menuItemEl;
});

// First item active
menuScope.adjustScroll(1);
expect(menuItemsListEl.scrollTop).toBe(0);

// Second item active
menuScope.activateNextItem();
menuScope.adjustScroll(1);
expect(menuItemsListEl.scrollTop).toBe(30);

// Third item active
menuScope.activateNextItem();
menuScope.adjustScroll(1);
expect(menuItemsListEl.scrollTop).toBe(90);

// Previous (second) item active
menuScope.activatePreviousItem();
menuScope.adjustScroll(-1);
expect(menuItemsListEl.scrollTop).toBe(60);
});

it('should return valid coordinates for textarea/input underline position', function () {

var textarea = angular.element('<textarea ng-trim="false">123</textarea>');
Expand Down

0 comments on commit a7fb874

Please sign in to comment.