|
| 1 | +describe('Directive: pfABoutModal', function () { |
| 2 | + var $scope; |
| 3 | + var $compile; |
| 4 | + |
| 5 | + // load the controller's module |
| 6 | + beforeEach(module( |
| 7 | + 'patternfly.modals', |
| 8 | + 'modals/about-modal.html' |
| 9 | + )); |
| 10 | + |
| 11 | + beforeEach(inject(function (_$compile_, _$rootScope_) { |
| 12 | + $compile = _$compile_; |
| 13 | + $scope = _$rootScope_; |
| 14 | + })); |
| 15 | + |
| 16 | + var compileHtml = function (markup, scope) { |
| 17 | + var element = angular.element(markup); |
| 18 | + $compile(element)(scope); |
| 19 | + scope.$digest(); |
| 20 | + return element; |
| 21 | + }; |
| 22 | + |
| 23 | + var closeModal = function(scope) { |
| 24 | + scope.isOpen = false; |
| 25 | + scope.$digest(); |
| 26 | + |
| 27 | + // Although callbacks are executed properly, the modal is not removed in this |
| 28 | + // environment -- must remove it manually to mimic UI Bootstrap. |
| 29 | + var modal = getModal(); |
| 30 | + if (modal) { |
| 31 | + modal.remove(); |
| 32 | + } |
| 33 | + var modalBackdrop = angular.element(document.querySelector('.modal-backdrop')); |
| 34 | + if (modalBackdrop) { |
| 35 | + modalBackdrop.remove(); |
| 36 | + } |
| 37 | + }; |
| 38 | + |
| 39 | + // Modal elements are located in a template, so wait until modal is shown. |
| 40 | + var getModal = function () { |
| 41 | + return angular.element(document.querySelector('.modal')); |
| 42 | + }; |
| 43 | + |
| 44 | + var openModal = function(scope) { |
| 45 | + scope.isOpen = true; |
| 46 | + scope.$digest(); |
| 47 | + }; |
| 48 | + |
| 49 | + beforeEach(function () { |
| 50 | + closeModal($scope); |
| 51 | + $scope.copyright = "Copyright Information"; |
| 52 | + $scope.imgAlt = "Patternfly Symbol"; |
| 53 | + $scope.imgSrc = "img/logo-alt.svg"; |
| 54 | + $scope.title = "Product Title"; |
| 55 | + $scope.isOpen = true; |
| 56 | + $scope.productInfo = [ |
| 57 | + { product: 'Label', version: 'Version' }, |
| 58 | + { product: 'Label', version: 'Version' }, |
| 59 | + { product: 'Label', version: 'Version' }, |
| 60 | + { product: 'Label', version: 'Version' }, |
| 61 | + { product: 'Label', version: 'Version' }, |
| 62 | + { product: 'Label', version: 'Version' }, |
| 63 | + { product: 'Label', version: 'Version' }]; |
| 64 | + $scope.open = function () { |
| 65 | + $scope.isOpen = true; |
| 66 | + } |
| 67 | + $scope.onClose = function() { |
| 68 | + $scope.isOpen = false; |
| 69 | + } |
| 70 | + }); |
| 71 | + |
| 72 | + it('should invoke the onClose callback when close button is clicked', function () { |
| 73 | + var modalHtml = '<div pf-about-modal is-open="isOpen" on-close="onClose()" title="title" copyright="copyright" img-alt="imgAlt" img-src="imgSrc" product-info="productInfo"></div>'; |
| 74 | + compileHtml(modalHtml, $scope); |
| 75 | + var closeButton = angular.element(getModal()).find('button'); |
| 76 | + eventFire(closeButton[0], 'click'); |
| 77 | + $scope.$digest(); |
| 78 | + expect($scope.isOpen).toBe(false); |
| 79 | + }); |
| 80 | + |
| 81 | + it('should open the about modal via an external button click', function () { |
| 82 | + $scope.isOpen = false; |
| 83 | + var modalHtml = '<div pf-about-modal is-open="isOpen" on-close="onClose()" title="title" copyright="copyright" img-alt="imgAlt" img-src="imgSrc" product-info="productInfo"></div>'; |
| 84 | + compileHtml(modalHtml, $scope); |
| 85 | + var buttonHtml = '<button ng-click="open()" class="btn btn-default">Launch about modal</button>'; |
| 86 | + var closeButton = compileHtml(buttonHtml, $scope); |
| 87 | + eventFire(closeButton[0], 'click'); |
| 88 | + $scope.$digest(); |
| 89 | + expect($scope.isOpen).toBe(true); |
| 90 | + expect(angular.element(getModal()).find('h1').length).toBe(1); |
| 91 | + }); |
| 92 | + |
| 93 | + it('should open the about modal programmatically', function () { |
| 94 | + $scope.isOpen = false; |
| 95 | + var modalHtml = '<div pf-about-modal is-open="isOpen" on-close="onClose()" title="title" copyright="copyright" img-alt="imgAlt" img-src="imgSrc" product-info="productInfo"></div>'; |
| 96 | + compileHtml(modalHtml, $scope); |
| 97 | + expect(angular.element(getModal()).find('h1').length).toBe(0); |
| 98 | + openModal($scope); |
| 99 | + expect(angular.element(getModal()).find('h1').length).toBe(1); |
| 100 | + }); |
| 101 | + |
| 102 | + it('should not open the about modal', function () { |
| 103 | + var modalHtml = '<div pf-about-modal is-open="false" on-close="onClose()" title="title" copyright="copyright" img-alt="imgAlt" img-src="imgSrc" product-info="productInfo"></div>'; |
| 104 | + compileHtml(modalHtml, $scope); |
| 105 | + expect(angular.element(getModal()).find('h1').length).toBe(0); |
| 106 | + expect(angular.element(getModal()).find('.trademark-pf').length).toBe(0); |
| 107 | + }); |
| 108 | + |
| 109 | + it('should set the product title', function () { |
| 110 | + var modalHtml = '<div pf-about-modal is-open="isOpen" on-close="onClose()" title="title" copyright="copyright" img-alt="imgAlt" img-src="imgSrc" product-info="productInfo"></div>'; |
| 111 | + compileHtml(modalHtml, $scope); |
| 112 | + expect(angular.element(getModal()).find('h1').html()).toBe('Product Title'); |
| 113 | + }); |
| 114 | + |
| 115 | + it('should not show product title when a title is not supplied', function () { |
| 116 | + var modalHtml = '<div pf-about-modal is-open="isOpen" on-close="onClose()" copyright="copyright" img-alt="imgAlt" img-src="imgSrc" product-info="productInfo"></div>'; |
| 117 | + compileHtml(modalHtml, $scope); |
| 118 | + expect(angular.element(getModal()).find('h1').length).toBe(0); |
| 119 | + }); |
| 120 | + |
| 121 | + it('should set the product copyright', function () { |
| 122 | + var modalHtml = '<div pf-about-modal is-open="isOpen" on-close="onClose()" title="title" copyright="copyright" img-alt="imgAlt" img-src="imgSrc" product-info="productInfo"></div>'; |
| 123 | + compileHtml(modalHtml, $scope); |
| 124 | + expect(angular.element(getModal()).find('.trademark-pf').html()).toBe('Copyright Information'); |
| 125 | + }); |
| 126 | + |
| 127 | + it('should not show product copyright when a copyright is not supplied', function () { |
| 128 | + var modalHtml = '<div pf-about-modal is-open="isOpen" on-close="onClose()" title="title" img-alt="imgAlt" img-src="imgSrc" product-info="productInfo"></div>'; |
| 129 | + compileHtml(modalHtml, $scope); |
| 130 | + expect(angular.element(getModal()).find('.trademark-pf').length).toBe(0); |
| 131 | + }); |
| 132 | + |
| 133 | + it('should set the corner graphic alt text', function () { |
| 134 | + var modalHtml = '<div pf-about-modal is-open="isOpen" on-close="onClose()" title="title" copyright="copyright" img-alt="imgAlt" img-src="imgSrc" product-info="productInfo"></div>'; |
| 135 | + compileHtml(modalHtml, $scope); |
| 136 | + var footer = angular.element(getModal()).find('.modal-footer'); |
| 137 | + expect(angular.element(footer).find('img').attr('alt')).toBe('Patternfly Symbol'); |
| 138 | + }); |
| 139 | + |
| 140 | + it('should not show alt text for corner graphic when imgAlt is not supplied', function () { |
| 141 | + var modalHtml = '<div pf-about-modal is-open="isOpen" on-close="onClose()" title="title" copyright="copyright" img-src="imgSrc" product-info="productInfo"></div>'; |
| 142 | + compileHtml(modalHtml, $scope); |
| 143 | + var footer = angular.element(getModal()).find('.modal-footer'); |
| 144 | + expect(angular.element(footer).find('img').attr('alt').length).toBe(0); |
| 145 | + }); |
| 146 | + |
| 147 | + it('should set the corner graphic src', function () { |
| 148 | + var modalHtml = '<div pf-about-modal is-open="isOpen" on-close="onClose()" title="title" copyright="copyright" img-alt="imgAlt" img-src="imgSrc" product-info="productInfo"></div>'; |
| 149 | + compileHtml(modalHtml, $scope); |
| 150 | + var footer = angular.element(getModal()).find('.modal-footer'); |
| 151 | + expect(angular.element(footer).find('img').attr('src')).toBe('img/logo-alt.svg'); |
| 152 | + }); |
| 153 | + |
| 154 | + it('should not show corner graphic when imgSrc is not supplied', function () { |
| 155 | + var modalHtml = '<div pf-about-modal is-open="isOpen" on-close="onClose()" title="title" copyright="copyright" img-alt="imgAlt" product-info="productInfo"></div>'; |
| 156 | + compileHtml(modalHtml, $scope); |
| 157 | + var footer = angular.element(getModal()).find('.modal-footer'); |
| 158 | + expect(angular.element(footer).find('img').length).toBe(0); |
| 159 | + }); |
| 160 | + |
| 161 | + it('should show simple content', function () { |
| 162 | + var modalHtml = '<div pf-about-modal is-open="isOpen" on-close="onClose()" title="title" copyright="copyright" img-alt="imgAlt" img-src="imgSrc" product-info="productInfo"></div>'; |
| 163 | + compileHtml(modalHtml, $scope); |
| 164 | + var transclude = angular.element(getModal()).find('.product-versions-pf'); |
| 165 | + expect(angular.element(transclude).find('ul').length).toBe(1); |
| 166 | + }); |
| 167 | + |
| 168 | + it('should show custom content', function () { |
| 169 | + var modalHtml = '<div pf-about-modal is-open="isOpen" on-close="onClose()" title="title" copyright="copyright" img-alt="imgAlt" img-src="imgSrc"><ul class="list-unstyled"><li><strong>Label</strong> Version</li></ul></div>'; |
| 170 | + compileHtml(modalHtml, $scope); |
| 171 | + var transclude = angular.element(getModal()).find('.product-versions-pf'); |
| 172 | + expect(angular.element(transclude).find('ul').length).toBe(1); |
| 173 | + }); |
| 174 | + |
| 175 | + it('should not show content', function () { |
| 176 | + var modalHtml = '<div pf-about-modal is-open="isOpen" on-close="onClose()" title="title" copyright="copyright" img-alt="imgAlt" img-src="imgSrc"></div>'; |
| 177 | + compileHtml(modalHtml, $scope); |
| 178 | + var transclude = angular.element(getModal()).find('.product-versions-pf'); |
| 179 | + expect(angular.element(transclude).find('ul').length).toBe(0); |
| 180 | + }); |
| 181 | +}); |
0 commit comments