Skip to content
This repository was archived by the owner on Jan 22, 2018. It is now read-only.

Commit e91ed1b

Browse files
author
Kamil Kisiela
committed
test(input): all basic tests
1 parent 901fbd0 commit e91ed1b

File tree

2 files changed

+88
-1
lines changed

2 files changed

+88
-1
lines changed

package.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ Package.onTest(function(api) {
120120
// types
121121
'tests/client/types/checkbox-spec.js',
122122
'tests/client/types/chips-spec.js',
123-
'tests/client/types/datepicker-spec.js'
123+
'tests/client/types/datepicker-spec.js',
124+
'tests/client/types/input-spec.js'
124125
], client);
125126
});

tests/client/types/input-spec.js

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
describe("formlyMaterial - input type", () => {
2+
3+
//
4+
// vars
5+
//
6+
7+
let formlyConfig;
8+
let $compile;
9+
let $rootScope;
10+
let $scope;
11+
let form;
12+
let element;
13+
let field;
14+
15+
//
16+
// helpers
17+
//
18+
19+
function compile(options) {
20+
$scope = $rootScope.$new();
21+
$scope.fields = [angular.merge({}, {
22+
key: 'testField',
23+
type: 'input',
24+
templateOptions: {
25+
type: 'email',
26+
label: 'test field'
27+
}
28+
}, options)];
29+
30+
form = $compile(testUtils.formTemplate)($scope);
31+
$scope.$digest();
32+
field = $scope.fields[0];
33+
element = form.find('[ng-model]');
34+
}
35+
36+
//
37+
// tests
38+
//
39+
40+
beforeEach(() => {
41+
angular.module('testApp', ['angular-meteor', 'formly', 'formlyMaterial']);
42+
module('testApp');
43+
44+
inject((_$compile_, _$rootScope_, _formlyConfig_) => {
45+
$compile = _$compile_;
46+
$rootScope = _$rootScope_;
47+
formlyConfig = _formlyConfig_;
48+
});
49+
50+
const types = ['input'];
51+
const wrappers = ['messages', 'label', 'inputContainer'];
52+
53+
types.forEach((type) => {
54+
testUtils.fixTypeTemplateUrl(formlyConfig, type);
55+
});
56+
wrappers.forEach((wrapper) => {
57+
testUtils.fixWrapperTemplateUrl(formlyConfig, wrapper);
58+
});
59+
60+
compile();
61+
});
62+
63+
it('should be input element', () => {
64+
expect(element[0].nodeName).toBe('INPUT');
65+
});
66+
67+
it('should have proper type attribute', () => {
68+
expect(element.attr('type')).toBe(field.templateOptions.type);
69+
});
70+
71+
it('should have messages wrapper', () => {
72+
expect(form.find('[ng-messages]').length).toBe(1);
73+
});
74+
75+
it('should have label wrapper', () => {
76+
let label = form.find('label');
77+
78+
expect(label.length).toBe(1);
79+
expect(label[0].innerText).toContain(field.templateOptions.label);
80+
});
81+
82+
it('should have inputContainer wrapper', () => {
83+
expect(form.find('md-input-container').length).toBe(1);
84+
});
85+
86+
});

0 commit comments

Comments
 (0)