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

Commit 1d1d5b8

Browse files
author
Kamil Kisiela
committed
test(label): check transclude order, label text and existance
1 parent bf843ff commit 1d1d5b8

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

package.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ Package.onTest(function(api) {
120120
'tests/client/formly-material-spec.js',
121121
// wrappers
122122
'tests/client/wrappers/input-container-spec.js',
123+
'tests/client/wrappers/label-spec.js',
123124
// types
124125
'tests/client/types/checkbox-spec.js',
125126
'tests/client/types/chips-spec.js',

tests/client/wrappers/label-spec.js

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

0 commit comments

Comments
 (0)