blob: e4c33f1ec7a6ed2f4508a2985ce734258f25f4ed [file] [log] [blame]
Matteo Scandolo9e6c6fc2016-04-14 14:59:09 -07001/**
2 * © OpenCORD
3 *
4 * Created by teone on 3/24/16.
5 */
6
7(function () {
8 'use strict';
9
10 describe('The xos.helper module', function(){
11 describe('The xos-table component', () => {
12
13 beforeEach(module('xos.helpers'));
14
15 it('should throw an error if no config is specified', inject(($compile, $rootScope) => {
16 function errorFunctionWrapper(){
17 $compile(angular.element('<xos-table></xos-table>'))($rootScope);
18 $rootScope.$digest();
19 }
20 expect(errorFunctionWrapper).toThrow(new Error('[xosTable] Please provide a configuration via the "config" attribute'));
21 }));
22
23 it('should throw an error if no config columns are specified', inject(($compile, $rootScope) => {
24 function errorFunctionWrapper(){
25 // setup the parent scope
26 let scope = $rootScope.$new();
27 scope.config = 'green';
28 $compile(angular.element('<xos-table config="config"></xos-table>'))(scope);
29 $rootScope.$digest();
30 }
31 expect(errorFunctionWrapper).toThrow(new Error('[xosTable] Please provide a columns list in the configuration'));
32 }));
33
34 });
35
36 describe('when correctly configured', function() {
37 var scope, element, isolatedScope;
38
39 beforeEach(inject(function ($compile, $rootScope) {
40 scope = $rootScope.$new();
41
42 scope.config = {
43 columns: [
44 {
45 label: 'Label 1',
46 prop: 'label-1'
47 },
48 {
49 label: 'Label 2',
50 prop: 'label-2'
51 }
52 ]
53 };
54
55 scope.data = [
56 {
57 'label-1': 'Sample 1.1',
58 'label-2': 'Sample 1.2'
59 },
60 {
61 'label-1': 'Sample 2.1',
62 'label-2': 'Sample 2.2'
63 }
64 ]
65
66 element = angular.element('<xos-table config="config" data="data"></xos-table>');
67 $compile(element)(scope);
68 // scope.$apply();
69 element.scope().$apply();
70 isolatedScope = element.isolateScope();
71 console.log(element, isolatedScope);
72 }));
73
74 xit('should contain 2 columns', function() {
75 console.log('aaa', isolatedScope);
76
77 // one is the filter, the other two are the products, one is the pagination
78 expect(isolatedScope.columns).toEqual(2);
79 });
80 });
81 });
82})();
83