|
| 1 | +describe("formlyMaterial - slider type", () => { |
| 2 | + |
| 3 | + // |
| 4 | + // vars |
| 5 | + // |
| 6 | + let formlyConfig; |
| 7 | + let $compile; |
| 8 | + let $rootScope; |
| 9 | + let $scope; |
| 10 | + let form; |
| 11 | + let element; |
| 12 | + let field; |
| 13 | + // |
| 14 | + // helpers |
| 15 | + // |
| 16 | + |
| 17 | + function compile(options) { |
| 18 | + $scope = $rootScope.$new(); |
| 19 | + $scope.fields = [angular.merge({}, { |
| 20 | + key: 'testField', |
| 21 | + type: 'slider', |
| 22 | + templateOptions: { |
| 23 | + label: 'test field', |
| 24 | + min: 1, |
| 25 | + max: 5, |
| 26 | + step: 0.5, |
| 27 | + discrete: true |
| 28 | + } |
| 29 | + }, options)]; |
| 30 | + |
| 31 | + form = $compile(testUtils.formTemplate)($scope); |
| 32 | + $scope.$digest(); |
| 33 | + field = $scope.fields[0]; |
| 34 | + element = form.find('[ng-model]'); |
| 35 | + } |
| 36 | + |
| 37 | + // |
| 38 | + // tests |
| 39 | + // |
| 40 | + |
| 41 | + beforeEach(() => { |
| 42 | + angular.module('testApp', ['angular-meteor', 'formly', 'formlyMaterial']); |
| 43 | + module('testApp'); |
| 44 | + |
| 45 | + inject((_$compile_, _$rootScope_, _formlyConfig_) => { |
| 46 | + $compile = _$compile_; |
| 47 | + $rootScope = _$rootScope_; |
| 48 | + formlyConfig = _formlyConfig_; |
| 49 | + }); |
| 50 | + |
| 51 | + const types = ['slider']; |
| 52 | + |
| 53 | + types.forEach((type) => { |
| 54 | + testUtils.fixTypeTemplateUrl(formlyConfig, type); |
| 55 | + }); |
| 56 | + |
| 57 | + compile(); |
| 58 | + }); |
| 59 | + |
| 60 | + it('should be md-slider element', () => { |
| 61 | + expect(element[0].nodeName).toBe('MD-SLIDER'); |
| 62 | + }); |
| 63 | + |
| 64 | + it('should support min option', () => { |
| 65 | + expect(parseFloat(element.attr('min'))).toEqual(field.templateOptions.min); |
| 66 | + }); |
| 67 | + |
| 68 | + it('should support max option', () => { |
| 69 | + expect(parseFloat(element.attr('max'))).toEqual(field.templateOptions.max); |
| 70 | + }); |
| 71 | + |
| 72 | + it('should support step option', () => { |
| 73 | + expect(parseFloat(element.attr('step'))).toEqual(field.templateOptions.step); |
| 74 | + }); |
| 75 | + |
| 76 | + it('should support discrete option', () => { |
| 77 | + expect(element.attr('md-discrete')).toEqual("options.templateOptions['discrete']"); |
| 78 | + }); |
| 79 | + |
| 80 | +}); |
0 commit comments