Matteo Scandolo | ebf4fad | 2016-04-22 12:05:37 -0700 | [diff] [blame] | 1 | /** |
| 2 | * © OpenCORD |
| 3 | * |
| 4 | * Created by teone on 4/15/16. |
| 5 | */ |
| 6 | |
| 7 | (function () { |
| 8 | 'use strict'; |
| 9 | |
| 10 | describe('The xos.helper module', function(){ |
| 11 | describe('The xos-validation component', () => { |
| 12 | |
| 13 | let element, scope, isolatedScope; |
| 14 | |
| 15 | beforeEach(module('xos.helpers')); |
| 16 | |
| 17 | beforeEach(inject(($compile, $rootScope) => { |
| 18 | |
| 19 | scope = $rootScope.$new(); |
| 20 | |
| 21 | scope.errors = {}; |
| 22 | |
| 23 | element = angular.element(`<xos-validation errors="errors"></xos-validation>`); |
| 24 | $compile(element)(scope); |
| 25 | scope.$digest(); |
| 26 | isolatedScope = element.isolateScope().vm; |
| 27 | })); |
| 28 | |
| 29 | it('should not show an alert', () => { |
| 30 | expect($(element).find('xos-alert > .alert')[0]).toHaveClass('ng-hide'); |
| 31 | }); |
| 32 | |
| 33 | let availableErrors = [ |
| 34 | { |
Matteo Scandolo | b3d686f | 2016-04-22 14:14:03 -0700 | [diff] [blame] | 35 | type: 'required', |
| 36 | message: 'Field required' |
| 37 | }, |
| 38 | { |
Matteo Scandolo | ebf4fad | 2016-04-22 12:05:37 -0700 | [diff] [blame] | 39 | type: 'email', |
| 40 | message: 'This is not a valid email' |
| 41 | }, |
| 42 | { |
| 43 | type: 'minlength', |
| 44 | message: 'Too short' |
| 45 | }, |
| 46 | { |
| 47 | type: 'maxlength', |
| 48 | message: 'Too long' |
| 49 | }, |
| 50 | { |
| 51 | type: 'custom', |
| 52 | message: 'Field invalid' |
| 53 | }, |
| 54 | ]; |
| 55 | |
| 56 | // use a loop to generate similar test |
| 57 | availableErrors.forEach((e, i) => { |
| 58 | it(`should show an alert for ${e.type} errors`, () => { |
| 59 | scope.errors[e.type] = true; |
| 60 | scope.$digest(); |
| 61 | let alert = $(element).find('xos-alert > .alert')[i]; |
| 62 | expect(alert).not.toHaveClass('ng-hide'); |
| 63 | expect(alert).toHaveText(e.message); |
| 64 | }); |
| 65 | }); |
| 66 | }); |
| 67 | }); |
| 68 | })(); |