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

Commit fe2edbf

Browse files
author
Kamil Kisiela
committed
test(radio): add basic tests
1 parent e91ed1b commit fe2edbf

File tree

2 files changed

+110
-1
lines changed

2 files changed

+110
-1
lines changed

package.js

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

tests/client/types/radio-spec.js

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
describe("formlyMaterial - radio 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 optionsElements;
14+
let field;
15+
16+
//
17+
// helpers
18+
//
19+
20+
function compile(options) {
21+
$scope = $rootScope.$new();
22+
$scope.fields = [angular.merge({}, {
23+
key: 'testField',
24+
type: 'radio',
25+
templateOptions: {
26+
label: 'test field',
27+
options: [
28+
{name: 'first', nameUp: 'FIRST', value: 'f', valueUp: 'F'},
29+
{name: 'second', nameUp: 'SECOND', value: 's', valueUp: 'S'}
30+
]
31+
}
32+
}, options)];
33+
34+
form = $compile(testUtils.formTemplate)($scope);
35+
$scope.$digest();
36+
field = $scope.fields[0];
37+
element = form.find('[ng-model]');
38+
optionsElements = element.find('md-radio-button');
39+
}
40+
41+
//
42+
// tests
43+
//
44+
45+
beforeEach(() => {
46+
angular.module('testApp', ['angular-meteor', 'formly', 'formlyMaterial']);
47+
module('testApp');
48+
49+
inject((_$compile_, _$rootScope_, _formlyConfig_) => {
50+
$compile = _$compile_;
51+
$rootScope = _$rootScope_;
52+
formlyConfig = _formlyConfig_;
53+
});
54+
55+
const types = ['radio'];
56+
57+
types.forEach((type) => {
58+
testUtils.fixTypeTemplateUrl(formlyConfig, type);
59+
});
60+
});
61+
62+
it('should be md-radio-group element', () => {
63+
compile();
64+
expect(element[0].nodeName).toBe('MD-RADIO-GROUP');
65+
});
66+
67+
it('should have options with default properties for name and value', () => {
68+
compile();
69+
expect(optionsElements.length).toBe(field.templateOptions.options.length);
70+
71+
field.templateOptions.options.forEach((option, key) => {
72+
let el = angular.element(optionsElements[key]);
73+
expect(el.attr('value')).toBe(option.value);
74+
expect(el.find('.md-label > span')[0].innerText).toContain(option.name);
75+
});
76+
});
77+
78+
it('should handle valueProp', () => {
79+
compile({
80+
templateOptions: {
81+
valueProp: 'valueUp'
82+
}
83+
});
84+
expect(optionsElements.length).toBe(field.templateOptions.options.length);
85+
86+
field.templateOptions.options.forEach((option, key) => {
87+
let el = angular.element(optionsElements[key]);
88+
expect(el.attr('value')).toBe(option.valueUp);
89+
expect(el.find('.md-label > span')[0].innerText).toContain(option.name);
90+
});
91+
});
92+
93+
it('should handle labelProp', () => {
94+
compile({
95+
templateOptions: {
96+
labelProp: 'nameUp'
97+
}
98+
});
99+
expect(optionsElements.length).toBe(field.templateOptions.options.length);
100+
101+
field.templateOptions.options.forEach((option, key) => {
102+
let el = angular.element(optionsElements[key]);
103+
expect(el.attr('value')).toBe(option.value);
104+
expect(el.find('.md-label > span')[0].innerText).toContain(option.nameUp);
105+
});
106+
});
107+
108+
});

0 commit comments

Comments
 (0)