|
| 1 | +import testUtils from './../test-utils'; |
| 2 | + |
| 3 | +describe("formlyMaterial - divider wrapper", () => { |
| 4 | + |
| 5 | + // |
| 6 | + // vars |
| 7 | + // |
| 8 | + let formlyConfig; |
| 9 | + let $compile; |
| 10 | + let $rootScope; |
| 11 | + let $scope; |
| 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: 'checkbox', |
| 24 | + wrapper: ['divider'] |
| 25 | + }, options)]; |
| 26 | + |
| 27 | + let form = $compile(testUtils.getFormTemplate())($scope); |
| 28 | + $scope.$digest(); |
| 29 | + element = form.find('md-divider'); |
| 30 | + field = $scope.fields[0]; |
| 31 | + } |
| 32 | + |
| 33 | + // |
| 34 | + // tests |
| 35 | + // |
| 36 | + |
| 37 | + beforeEach(() => { |
| 38 | + window.module('formlyMaterial'); |
| 39 | + |
| 40 | + inject((_$compile_, _$rootScope_, _formlyConfig_) => { |
| 41 | + $compile = _$compile_; |
| 42 | + $rootScope = _$rootScope_; |
| 43 | + formlyConfig = _formlyConfig_; |
| 44 | + }); |
| 45 | + }); |
| 46 | + |
| 47 | + it('should exist', () => { |
| 48 | + compile(); |
| 49 | + expect(element.length).toBe(1); |
| 50 | + }); |
| 51 | + |
| 52 | + it("should be after the field by default", () => { |
| 53 | + compile(); |
| 54 | + // not transcluded inner |
| 55 | + expect(element.find('md-checkbox').length).toBe(0); |
| 56 | + // checkbox transcluded before |
| 57 | + expect(element.prev('.ng-scope').children('md-checkbox').length).toBe(1); |
| 58 | + }); |
| 59 | + |
| 60 | + it("should be before the field when divider option equals 'before'", () => { |
| 61 | + compile({ |
| 62 | + templateOptions: { |
| 63 | + divider: 'before' |
| 64 | + } |
| 65 | + }); |
| 66 | + // not transcluded inner |
| 67 | + expect(element.find('md-checkbox').length).toBe(0); |
| 68 | + // checkbox transcluded before |
| 69 | + expect(element.next('.ng-scope').children('md-checkbox').length).toBe(1); |
| 70 | + }); |
| 71 | + |
| 72 | +}); |
0 commit comments