blob: eb92a0550bfa1eea238c7060fcce1cc8ba867620 [file] [log] [blame]
Matteo Scandolob6bfee32016-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 {
35 type: 'email',
36 message: 'This is not a valid email'
37 },
38 {
39 type: 'minlength',
40 message: 'Too short'
41 },
42 {
43 type: 'maxlength',
44 message: 'Too long'
45 },
46 {
47 type: 'custom',
48 message: 'Field invalid'
49 },
50 ];
51
52 // use a loop to generate similar test
53 availableErrors.forEach((e, i) => {
54 it(`should show an alert for ${e.type} errors`, () => {
55 scope.errors[e.type] = true;
56 scope.$digest();
57 let alert = $(element).find('xos-alert > .alert')[i];
58 expect(alert).not.toHaveClass('ng-hide');
59 expect(alert).toHaveText(e.message);
60 });
61 });
62 });
63 });
64})();