angular.directive.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. describe('angular easypiechart directive', function() {
  2. var $compile, $rootScope, scope;
  3. beforeEach(module('easypiechart'));
  4. beforeEach(inject(function(_$compile_, $rootScope){
  5. scope = $rootScope;
  6. $compile = _$compile_;
  7. }));
  8. it('should have percentage default value 0', function (done) {
  9. scope.percent = null;
  10. var element = angular.element('<div easypiechart percent="percent" options="options"></div>');
  11. $compile(element)(scope);
  12. scope.$digest();
  13. expect(element.isolateScope().percent).toBe(0);
  14. });
  15. it('inserts the element with a canvas element', function() {
  16. scope.percent = -45;
  17. scope.options = {};
  18. var element = angular.element('<div easypiechart percent="percent" options="options"></div>');
  19. $compile(element)(scope);
  20. scope.$digest();
  21. expect(element.html()).toContain('canvas');
  22. });
  23. it('gets the options right', function (done) {
  24. scope.percent = 0;
  25. scope.options = {
  26. animate:{
  27. duration:0,
  28. enabled:false
  29. },
  30. barColor:'#2C3E50',
  31. scaleColor:false,
  32. lineWidth:20,
  33. lineCap:'circle'
  34. };
  35. var element = angular.element('<div easypiechart percent="percent" options="options"></div>');
  36. $compile(element)(scope);
  37. scope.$digest();
  38. expect(element.isolateScope().options.animate.duration).toBe(0);
  39. expect(element.isolateScope().options.lineCap).toBe('circle');
  40. });
  41. it('has its own default options', function (done) {
  42. scope.percent = 0;
  43. scope.options = {};
  44. var element = angular.element('<div easypiechart percent="percent" options="options"></div>');
  45. $compile(element)(scope);
  46. scope.$digest();
  47. expect(element.isolateScope().options.size).toBe(110);
  48. expect(element.isolateScope().options.animate.enabled).toBe(true);
  49. });
  50. it('takes size option the right way', function() {
  51. scope.percent = 0;
  52. scope.options = {
  53. size: 200
  54. };
  55. var element = angular.element('<div easypiechart percent="percent" options="options"></div>');
  56. $compile(element)(scope);
  57. scope.$digest();
  58. expect(element.html()).toContain('height="200"');
  59. expect(element.html()).toContain('width="200"');
  60. });
  61. });