|
| 1 | +describe("formlyMaterial - input 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 field; |
| 14 | + |
| 15 | + // |
| 16 | + // helpers |
| 17 | + // |
| 18 | + |
| 19 | + function compile(options) { |
| 20 | + $scope = $rootScope.$new(); |
| 21 | + $scope.fields = [angular.merge({}, { |
| 22 | + key: 'testField', |
| 23 | + type: 'input', |
| 24 | + templateOptions: { |
| 25 | + type: 'email', |
| 26 | + label: 'test field' |
| 27 | + } |
| 28 | + }, options)]; |
| 29 | + |
| 30 | + form = $compile(testUtils.formTemplate)($scope); |
| 31 | + $scope.$digest(); |
| 32 | + field = $scope.fields[0]; |
| 33 | + element = form.find('[ng-model]'); |
| 34 | + } |
| 35 | + |
| 36 | + // |
| 37 | + // tests |
| 38 | + // |
| 39 | + |
| 40 | + beforeEach(() => { |
| 41 | + angular.module('testApp', ['angular-meteor', 'formly', 'formlyMaterial']); |
| 42 | + module('testApp'); |
| 43 | + |
| 44 | + inject((_$compile_, _$rootScope_, _formlyConfig_) => { |
| 45 | + $compile = _$compile_; |
| 46 | + $rootScope = _$rootScope_; |
| 47 | + formlyConfig = _formlyConfig_; |
| 48 | + }); |
| 49 | + |
| 50 | + const types = ['input']; |
| 51 | + const wrappers = ['messages', 'label', 'inputContainer']; |
| 52 | + |
| 53 | + types.forEach((type) => { |
| 54 | + testUtils.fixTypeTemplateUrl(formlyConfig, type); |
| 55 | + }); |
| 56 | + wrappers.forEach((wrapper) => { |
| 57 | + testUtils.fixWrapperTemplateUrl(formlyConfig, wrapper); |
| 58 | + }); |
| 59 | + |
| 60 | + compile(); |
| 61 | + }); |
| 62 | + |
| 63 | + it('should be input element', () => { |
| 64 | + expect(element[0].nodeName).toBe('INPUT'); |
| 65 | + }); |
| 66 | + |
| 67 | + it('should have proper type attribute', () => { |
| 68 | + expect(element.attr('type')).toBe(field.templateOptions.type); |
| 69 | + }); |
| 70 | + |
| 71 | + it('should have messages wrapper', () => { |
| 72 | + expect(form.find('[ng-messages]').length).toBe(1); |
| 73 | + }); |
| 74 | + |
| 75 | + it('should have label wrapper', () => { |
| 76 | + let label = form.find('label'); |
| 77 | + |
| 78 | + expect(label.length).toBe(1); |
| 79 | + expect(label[0].innerText).toContain(field.templateOptions.label); |
| 80 | + }); |
| 81 | + |
| 82 | + it('should have inputContainer wrapper', () => { |
| 83 | + expect(form.find('md-input-container').length).toBe(1); |
| 84 | + }); |
| 85 | + |
| 86 | +}); |
0 commit comments