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

Commit d656b4c

Browse files
author
Kamil Kisiela
committed
test(): templateOptions.className
1 parent 718c172 commit d656b4c

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

tests/runs/class-name-spec.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import testUtils from './../test-utils';
2+
import angular from 'angular';
3+
4+
describe('formlyMaterial - className manipulator', () => {
5+
//
6+
// vars
7+
//
8+
let $compile;
9+
let $rootScope;
10+
let $scope;
11+
let element;
12+
let elementScope;
13+
14+
//
15+
// helpers
16+
//
17+
18+
function compile(options) {
19+
$scope = $rootScope.$new();
20+
$scope.fields = [angular.merge({}, {
21+
key: 'testField',
22+
type: 'switch',
23+
templateOptions: {
24+
className: 'custom',
25+
label: 'test field'
26+
}
27+
}, options)];
28+
29+
const form = $compile(testUtils.getFormTemplate())($scope);
30+
31+
$scope.$digest();
32+
element = form.find('[ng-model]');
33+
elementScope = element.scope();
34+
}
35+
36+
//
37+
// tests
38+
//
39+
40+
beforeEach(() => {
41+
window.module('formlyMaterial');
42+
43+
inject((_$compile_, _$rootScope_) => {
44+
$compile = _$compile_;
45+
$rootScope = _$rootScope_;
46+
});
47+
48+
compile();
49+
});
50+
51+
it('should be able to add ng-class directive', () => {
52+
compile();
53+
expect(element.attr('ng-class')).toBe(`options.templateOptions['className']`);
54+
});
55+
56+
it('should pass one class as a string', () => {
57+
compile();
58+
expect(elementScope.options.templateOptions.className).toBe('custom');
59+
expect(element.attr('class')).toContain('custom');
60+
});
61+
62+
it('should pass few classes as an array', () => {
63+
const classes = ['foo', 'bar', 'baz'];
64+
65+
compile({
66+
templateOptions: {
67+
className: classes
68+
}
69+
});
70+
71+
expect(elementScope.options.templateOptions.className).toEqual(classes);
72+
73+
classes.forEach((clss) => {
74+
expect(element.attr('class')).toContain(clss);
75+
});
76+
});
77+
});

tests/runs/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
import './class-name-spec';
12
import './theme-spec';

0 commit comments

Comments
 (0)