|
| 1 | +describe("formlyMaterial - datepicker 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: 'datepicker', |
| 22 | + templateOptions: { |
| 23 | + label: 'test field', |
| 24 | + placeholder: "Pick a date", |
| 25 | + minDate: new Date(2015, 11, 19), |
| 26 | + maxDate: new Date(2015, 12, 20), |
| 27 | + filterDate: (date) => { |
| 28 | + return true; |
| 29 | + } |
| 30 | + } |
| 31 | + }, options)]; |
| 32 | + |
| 33 | + form = $compile(testUtils.formTemplate)($scope); |
| 34 | + $scope.$digest(); |
| 35 | + field = $scope.fields[0]; |
| 36 | + element = form.find('[ng-model]'); |
| 37 | + } |
| 38 | + |
| 39 | + // |
| 40 | + // tests |
| 41 | + // |
| 42 | + |
| 43 | + beforeEach(() => { |
| 44 | + angular.module('testApp', ['angular-meteor', 'formly', 'formlyMaterial']); |
| 45 | + module('testApp'); |
| 46 | + |
| 47 | + inject((_$compile_, _$rootScope_, _formlyConfig_) => { |
| 48 | + $compile = _$compile_; |
| 49 | + $rootScope = _$rootScope_; |
| 50 | + formlyConfig = _formlyConfig_; |
| 51 | + }); |
| 52 | + |
| 53 | + const types = ['datepicker']; |
| 54 | + const wrappers = ['messages']; |
| 55 | + |
| 56 | + types.forEach((type) => { |
| 57 | + testUtils.fixTypeTemplateUrl(formlyConfig, type); |
| 58 | + }); |
| 59 | + wrappers.forEach((wrapper) => { |
| 60 | + testUtils.fixWrapperTemplateUrl(formlyConfig, wrapper); |
| 61 | + }); |
| 62 | + |
| 63 | + compile(); |
| 64 | + }); |
| 65 | + |
| 66 | + it('should be md-chips element', () => { |
| 67 | + expect(element[0].nodeName).toBe('MD-DATEPICKER'); |
| 68 | + }); |
| 69 | + |
| 70 | + it('should have messages', () => { |
| 71 | + expect(form.find('[ng-messages]').length).toBe(1); |
| 72 | + }); |
| 73 | + |
| 74 | + it('should have min date', () => { |
| 75 | + expect(element.attr('md-min-date')).toBe('to.minDate'); |
| 76 | + }); |
| 77 | + |
| 78 | + it('should have max date', () => { |
| 79 | + expect(element.attr('md-max-date')).toBe('to.maxDate'); |
| 80 | + }); |
| 81 | + |
| 82 | + it('should have date filter', () => { |
| 83 | + expect(element.attr('md-date-filter')).toBe('to.filterDate'); |
| 84 | + }); |
| 85 | + |
| 86 | +}); |
0 commit comments