blob: 782f03f63c2d6d8981764122bbac047512521211 [file] [log] [blame]
Matteo Scandoloebf4fad2016-04-22 12:05:37 -07001/**
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 Scandolob3d686f2016-04-22 14:14:03 -070035 type: 'required',
36 message: 'Field required'
37 },
38 {
Matteo Scandoloebf4fad2016-04-22 12:05:37 -070039 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})();