This repository has been archived by the owner on Jan 22, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Kamil Kisiela
committed
Jan 12, 2016
1 parent
718c172
commit d656b4c
Showing
2 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import testUtils from './../test-utils'; | ||
import angular from 'angular'; | ||
|
||
describe('formlyMaterial - className manipulator', () => { | ||
// | ||
// vars | ||
// | ||
let $compile; | ||
let $rootScope; | ||
let $scope; | ||
let element; | ||
let elementScope; | ||
|
||
// | ||
// helpers | ||
// | ||
|
||
function compile(options) { | ||
$scope = $rootScope.$new(); | ||
$scope.fields = [angular.merge({}, { | ||
key: 'testField', | ||
type: 'switch', | ||
templateOptions: { | ||
className: 'custom', | ||
label: 'test field' | ||
} | ||
}, options)]; | ||
|
||
const form = $compile(testUtils.getFormTemplate())($scope); | ||
|
||
$scope.$digest(); | ||
element = form.find('[ng-model]'); | ||
elementScope = element.scope(); | ||
} | ||
|
||
// | ||
// tests | ||
// | ||
|
||
beforeEach(() => { | ||
window.module('formlyMaterial'); | ||
|
||
inject((_$compile_, _$rootScope_) => { | ||
$compile = _$compile_; | ||
$rootScope = _$rootScope_; | ||
}); | ||
|
||
compile(); | ||
}); | ||
|
||
it('should be able to add ng-class directive', () => { | ||
compile(); | ||
expect(element.attr('ng-class')).toBe(`options.templateOptions['className']`); | ||
}); | ||
|
||
it('should pass one class as a string', () => { | ||
compile(); | ||
expect(elementScope.options.templateOptions.className).toBe('custom'); | ||
expect(element.attr('class')).toContain('custom'); | ||
}); | ||
|
||
it('should pass few classes as an array', () => { | ||
const classes = ['foo', 'bar', 'baz']; | ||
|
||
compile({ | ||
templateOptions: { | ||
className: classes | ||
} | ||
}); | ||
|
||
expect(elementScope.options.templateOptions.className).toEqual(classes); | ||
|
||
classes.forEach((clss) => { | ||
expect(element.attr('class')).toContain(clss); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
import './class-name-spec'; | ||
import './theme-spec'; |