blob: a679c66c627304ffca4d26fc749cd6675b511040 [file] [log] [blame]
Matteo Scandolo6872a0f2016-05-03 15:13:59 -07001/**
2 * © OpenCORD
3 *
4 * Created by teone on 3/24/16.
5 */
6
7(function () {
8 'use strict';
9
10 let mockData;
11
12 describe('The xos.helper module', function(){
13 describe('The xos-smart-pie component', () => {
14
15 var spy, scope, isolatedScope, element;
16
17 beforeEach(module('xos.helpers'));
18
19 beforeEach(function() {
20
21 // set mockData
22 mockData = [
23 {
24 id: 1,
25 first_name: 'Jon',
26 last_name: 'Snow',
27 category: 1
28 },
29 {
30 id: 2,
31 first_name: 'Danaerys',
32 last_name: 'Targaryen',
33 category: 2
34 },
35 {
36 id: 3,
37 first_name: 'Aria',
38 last_name: 'Stark',
39 category: 1
40 }
41 ]
42
43 });
44
45 // mock the service
46 beforeEach(function(){
47 module(function($provide){
48 $provide.service('MockResource', function(){
49 return {
50 query: ''
51 }
52 });
53 });
54 })
55
56 beforeEach(inject(function ($compile, $rootScope, $q, MockResource) {
57 scope = $rootScope.$new();
58
59 scope.config = {
60 resource: 'MockResource',
61 groupBy: 'category',
62 classes: 'my-test-class'
63 };
64
65 spy = MockResource;
66
67 spyOn(MockResource, 'query').and.callFake(function() {
68 var deferred = $q.defer();
69 deferred.resolve(mockData);
70 return {$promise: deferred.promise};
71 });
72
73 element = angular.element('<xos-smart-pie config="config"></xos-smart-pie>');
74 $compile(element)(scope);
75 scope.$digest();
76 isolatedScope = element.isolateScope().vm;
77 }));
78
79 it('should attach provided classes', () => {
80 expect($(element).find('canvas')).toHaveClass('my-test-class');
81 });
82
83 it('should group elements', () => {
84 let groupedData = [2, 1];
85 expect(spy.query).toHaveBeenCalled();
86 expect(isolatedScope.data).toEqual(groupedData);
87 });
88
89 });
90 });
91})();