Matteo Scandolo | 974c0e4 | 2016-05-25 16:02:16 -0700 | [diff] [blame^] | 1 | /** |
| 2 | * © OpenCORD |
| 3 | * |
| 4 | * Created by teone on 5/25/16. |
| 5 | */ |
| 6 | |
| 7 | (function () { |
| 8 | 'use strict'; |
| 9 | |
| 10 | let element, scope, isolatedScope, rootScope, compile; |
| 11 | const compileElement = () => { |
| 12 | |
| 13 | if(!scope){ |
| 14 | scope = rootScope.$new(); |
| 15 | } |
| 16 | |
| 17 | element = angular.element('<xos-field name="name" field="field" ng-model="ngModel"></xos-field>'); |
| 18 | compile(element)(scope); |
| 19 | scope.$digest(); |
| 20 | isolatedScope = element.isolateScope().vm; |
| 21 | } |
| 22 | |
| 23 | describe('The xos.helper module', function(){ |
| 24 | |
| 25 | describe('The xosField component', () => { |
| 26 | |
| 27 | beforeEach(module('xos.helpers')); |
| 28 | |
| 29 | beforeEach(inject(function ($compile, $rootScope) { |
| 30 | compile = $compile; |
| 31 | rootScope = $rootScope; |
| 32 | })); |
| 33 | |
| 34 | it('should throw an error if no name is passed', inject(($compile, $rootScope) => { |
| 35 | function errorFunctionWrapper(){ |
| 36 | // setup the parent scope |
| 37 | scope = $rootScope.$new(); |
| 38 | scope.field = { |
| 39 | label: 'Label', |
| 40 | type: 'number', |
| 41 | validators: {} |
| 42 | }; |
| 43 | scope.ngModel = { |
| 44 | label: 1 |
| 45 | }; |
| 46 | compileElement(); |
| 47 | } |
| 48 | expect(errorFunctionWrapper).toThrow(new Error('[xosField] Please provide a field name')); |
| 49 | })); |
| 50 | |
| 51 | it('should throw an error if no field definition is passed', inject(($compile, $rootScope) => { |
| 52 | function errorFunctionWrapper(){ |
| 53 | // setup the parent scope |
| 54 | scope = $rootScope.$new(); |
| 55 | scope.name = 'label'; |
| 56 | scope.ngModel = { |
| 57 | label: 1 |
| 58 | }; |
| 59 | compileElement(); |
| 60 | } |
| 61 | expect(errorFunctionWrapper).toThrow(new Error('[xosField] Please provide a field definition')); |
| 62 | })); |
| 63 | |
| 64 | it('should throw an error if no field model is passed', inject(($compile, $rootScope) => { |
| 65 | function errorFunctionWrapper(){ |
| 66 | // setup the parent scope |
| 67 | scope = $rootScope.$new(); |
| 68 | scope.name = 'label'; |
| 69 | scope.field = { |
| 70 | label: 'Label', |
| 71 | type: 'number', |
| 72 | validators: {} |
| 73 | }; |
| 74 | compileElement(); |
| 75 | } |
| 76 | expect(errorFunctionWrapper).toThrow(new Error('[xosField] Please provide an ng-model')); |
| 77 | })); |
| 78 | }); |
| 79 | }); |
| 80 | })(); |