Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyuzhcy committed Oct 29, 2015
2 parents 0569e11 + a8624e0 commit 804fe62
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ module.exports = function(grunt) {
.replace(/\\/g, '\\\\')
.replace(/'/g, "\\'")
.replace(/\r?\n/g, '\\n');
js = "!angular.$$csp() && angular.element(document).find('head').prepend('<style type=\"text/css\">" + css + "</style>');";
js = "angular.module('ui.bootstrap.carousel').run(function() {!angular.$$csp() && angular.element(document).find('head').prepend('<style type=\"text/css\">" + css + "</style>'); })";
state.js.push(js);

return state;
Expand Down
2 changes: 1 addition & 1 deletion src/pagination/pagination.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ angular.module('ui.bootstrap.pagination', [])
$scope.$watch('totalPages', function(value) {
setNumPages($scope.$parent, value); // Readonly variable

if ( $scope.page > value ) {
if ($scope.page > value) {
$scope.selectPage(value);
} else {
ngModelCtrl.$render();
Expand Down
2 changes: 1 addition & 1 deletion src/pagination/test/pagination.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ describe('pagination directive', function() {
});
});

describe('executes `ng-change` expression', function() {
describe('executes `ng-change` expression', function() {
beforeEach(function() {
$rootScope.selectPageHandler = jasmine.createSpy('selectPageHandler');
element = $compile('<uib-pagination total-items="total" ng-model="currentPage" ng-change="selectPageHandler()"></uib-pagination>')($rootScope);
Expand Down
1 change: 0 additions & 1 deletion src/position/position.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ angular.module('ui.bootstrap.position', [])
top: hostElPos.top - targetElHeight,
left: shiftWidth[pos1]()
};
break;
}

return targetElPos;
Expand Down
165 changes: 165 additions & 0 deletions src/position/test/position.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,104 @@ describe('position elements', function () {
});
});

describe('offset', function() {
var $document;

beforeEach(inject(function(_$document_) {
$document = _$document_;
}));

it('returns getBoundingClientRect by default', function() {
var el = angular.element('<div>Foo</div>');

/* getBoundingClientRect values will be based on the testing Chrome window
so that makes this tests very brittle if we don't mock */
spyOn(el[0], 'getBoundingClientRect').and.returnValue({
width: 100,
height: 100,
top: 2,
left: 2
});
$document.find('body').append(el);

var offset = $position.offset(el);

expect(offset).toEqual({
width: 100,
height: 100,
top: 2,
left: 2
});

el.remove();
});
});

describe('position', function() {
var $document, el;

beforeEach(inject(function(_$document_) {
$document = _$document_;
}));

afterEach(function() {
el.remove();
});

it('gets position with document as the relative parent', function() {
el = angular.element('<div>Foo</div>');

spyOn(el[0], 'getBoundingClientRect').and.returnValue({
width: 100,
height: 100,
top: 2,
left: 2
});

$document.find('body').append(el);

var position = $position.position(el);

expect(position).toEqual({
width: 100,
height: 100,
top: 2,
left: 2
});
});

it('gets position with another DOM as the relative parent', function() {
el = angular.element('<div id="outer" style="position:relative;"><div id="inner">Foo</div></div>');

$document.find('body').append(el);

var outerEl = angular.element(document.getElementById('outer'));
var innerEl = angular.element(document.getElementById('inner'));

spyOn(outerEl[0], 'getBoundingClientRect').and.returnValue({
width: 100,
height: 100,
top: 2,
left: 2
});
spyOn(innerEl[0], 'getBoundingClientRect').and.returnValue({
width: 20,
height: 20,
top: 5,
left: 5
});

var position = $position.position(innerEl);

expect(position).toEqual({
width: 20,
height: 20,
top: 3,
left: 3
});
});
});

describe('append-to-body: false', function() {
beforeEach(function() {
//mock position info normally queried from the DOM
Expand Down Expand Up @@ -103,4 +201,71 @@ describe('position elements', function () {
expect($position.positionElements({}, new TargetElMock(10, 10), 'right-bottom')).toBePositionedAt(120, 120);
});
});

describe('append-to-body: true', function() {
beforeEach(function() {
//mock offset info normally queried from the DOM
$position.offset = function() {
return {
width: 20,
height: 20,
top: 100,
left: 100
};
};
});

it('should position element on top-center by default', function() {
expect($position.positionElements({}, new TargetElMock(10, 10), 'other', true)).toBePositionedAt(90, 105);
expect($position.positionElements({}, new TargetElMock(10, 10), 'top', true)).toBePositionedAt(90, 105);
expect($position.positionElements({}, new TargetElMock(10, 10), 'top-center', true)).toBePositionedAt(90, 105);
});

it('should position on top-left', function() {
expect($position.positionElements({}, new TargetElMock(10, 10), 'top-left', true)).toBePositionedAt(90, 100);
});

it('should position on top-right', function() {
expect($position.positionElements({}, new TargetElMock(10, 10), 'top-right', true)).toBePositionedAt(90, 120);
});

it('should position elements on bottom-center when "bottom" specified', function() {
expect($position.positionElements({}, new TargetElMock(10, 10), 'bottom', true)).toBePositionedAt(120, 105);
expect($position.positionElements({}, new TargetElMock(10, 10), 'bottom-center', true)).toBePositionedAt(120, 105);
});

it('should position elements on bottom-left', function() {
expect($position.positionElements({}, new TargetElMock(10, 10), 'bottom-left', true)).toBePositionedAt(120, 100);
});

it('should position elements on bottom-right', function() {
expect($position.positionElements({}, new TargetElMock(10, 10), 'bottom-right', true)).toBePositionedAt(120, 120);
});

it('should position elements on left-center when "left" specified', function() {
expect($position.positionElements({}, new TargetElMock(10, 10), 'left', true)).toBePositionedAt(105, 90);
expect($position.positionElements({}, new TargetElMock(10, 10), 'left-center', true)).toBePositionedAt(105, 90);
});

it('should position elements on left-top when "left-top" specified', function() {
expect($position.positionElements({}, new TargetElMock(10, 10), 'left-top', true)).toBePositionedAt(100, 90);
});

it('should position elements on left-bottom when "left-bottom" specified', function() {
expect($position.positionElements({}, new TargetElMock(10, 10), 'left-bottom', true)).toBePositionedAt(120, 90);
});

it('should position elements on right-center when "right" specified', function() {
expect($position.positionElements({}, new TargetElMock(10, 10), 'right', true)).toBePositionedAt(105, 120);
expect($position.positionElements({}, new TargetElMock(10, 10), 'right-center', true)).toBePositionedAt(105, 120);
});

it('should position elements on right-top when "right-top" specified', function() {
expect($position.positionElements({}, new TargetElMock(10, 10), 'right-top', true)).toBePositionedAt(100, 120);
});

it('should position elements on right-top when "right-top" specified', function() {
expect($position.positionElements({}, new TargetElMock(10, 10), 'right-bottom', true)).toBePositionedAt(120, 120);
});
});
});

0 comments on commit 804fe62

Please sign in to comment.