|
| 1 | +describe('Directive: pfWizard', function () { |
| 2 | + var $scope, |
| 3 | + $rootScope, |
| 4 | + $compile, |
| 5 | + $httpBackend, |
| 6 | + $templateCache, |
| 7 | + $timeout, |
| 8 | + element; |
| 9 | + |
| 10 | + // load the controller's module |
| 11 | + beforeEach(module( |
| 12 | + 'patternfly.wizard', |
| 13 | + 'wizard/wizard-substep.html', |
| 14 | + 'wizard/wizard-step.html', |
| 15 | + 'wizard/wizard-review-page.html', |
| 16 | + 'wizard/wizard.html', |
| 17 | + 'form/form-group/form-group.html', |
| 18 | + 'test/wizard/deployment.html', |
| 19 | + 'test/wizard/detail-page.html', |
| 20 | + 'test/wizard/review-second-template.html', |
| 21 | + 'test/wizard/review-template.html', |
| 22 | + 'test/wizard/summary.html', |
| 23 | + 'test/wizard/wizard-container.html' |
| 24 | + )); |
| 25 | + |
| 26 | + beforeEach(inject(function (_$compile_, _$rootScope_, _$httpBackend_, _$templateCache_, _$timeout_) { |
| 27 | + $compile = _$compile_; |
| 28 | + $scope = _$rootScope_; |
| 29 | + $rootScope = _$rootScope_; |
| 30 | + $httpBackend = _$httpBackend_; |
| 31 | + $templateCache = _$templateCache_; |
| 32 | + $timeout = _$timeout_; |
| 33 | + })); |
| 34 | + |
| 35 | + var compileHtml = function (markup, scope) { |
| 36 | + var element = angular.element(markup); |
| 37 | + $compile(element)(scope); |
| 38 | + scope.$digest(); |
| 39 | + return element; |
| 40 | + }; |
| 41 | + |
| 42 | + var setupWizardScope = function () { |
| 43 | + var initializeWizard = function () { |
| 44 | + $scope.data = { |
| 45 | + name: '', |
| 46 | + description: '', |
| 47 | + lorem: 'default setting', |
| 48 | + ipsum: '' |
| 49 | + }; |
| 50 | + $scope.hideIndicators = false; |
| 51 | + |
| 52 | + $scope.secondaryLoadInformation = 'ipsum dolor sit amet, porta at suspendisse ac, ut wisi vivamus, lorem sociosqu eget nunc amet.'; |
| 53 | + $timeout(function () { |
| 54 | + $scope.deployReady = true; |
| 55 | + }); |
| 56 | + $scope.nextButtonTitle = "Next >"; |
| 57 | + }; |
| 58 | + |
| 59 | + var startDeploy = function () { |
| 60 | + $timeout(function() { }, 2000); |
| 61 | + $scope.deployInProgress = true; |
| 62 | + }; |
| 63 | + |
| 64 | + $scope.data = {}; |
| 65 | + |
| 66 | + $scope.nextCallback = function () { |
| 67 | + return true; |
| 68 | + }; |
| 69 | + |
| 70 | + $scope.backCallback = function () { |
| 71 | + return true; |
| 72 | + }; |
| 73 | + |
| 74 | + $scope.$on("wizard:stepChanged", function (e, parameters) { |
| 75 | + if (parameters.step.stepId === 'review-summary') { |
| 76 | + $scope.nextButtonTitle = "Deploy"; |
| 77 | + } else if (parameters.step.stepId === 'review-progress') { |
| 78 | + $scope.nextButtonTitle = "Close"; |
| 79 | + } else { |
| 80 | + $scope.nextButtonTitle = "Next >"; |
| 81 | + } |
| 82 | + }); |
| 83 | + |
| 84 | + $scope.cancelDeploymentWizard = function () { |
| 85 | + $rootScope.$emit('wizard.done', 'cancel'); |
| 86 | + }; |
| 87 | + |
| 88 | + $scope.finishedWizard = function () { |
| 89 | + $rootScope.$emit('wizard.done', 'done'); |
| 90 | + return true; |
| 91 | + }; |
| 92 | + initializeWizard(); |
| 93 | + }; |
| 94 | + |
| 95 | + beforeEach(function () { |
| 96 | + setupWizardScope(); |
| 97 | + var modalHtml = $templateCache.get('test/wizard/wizard-container.html'); |
| 98 | + element = compileHtml(modalHtml, $scope); |
| 99 | + $scope.$digest(); |
| 100 | + |
| 101 | + // there are two dependent timeouts in the wizard that need to be flushed |
| 102 | + $timeout.flush(); |
| 103 | + $timeout.flush(); |
| 104 | + }); |
| 105 | + |
| 106 | + it('should dispatch the cancel event on the close button click', function () { |
| 107 | + var closeButton = element.find('.close'); |
| 108 | + $rootScope.$on('wizard.done', function (event, data) { |
| 109 | + expect(data).toBe('cancel'); |
| 110 | + }); |
| 111 | + spyOn($rootScope, '$emit'); |
| 112 | + eventFire(closeButton[0], 'click'); |
| 113 | + $scope.$digest(); |
| 114 | + |
| 115 | + expect($rootScope.$emit).toHaveBeenCalled(); |
| 116 | + }); |
| 117 | + |
| 118 | + it('should have three step indicators in the header', function () { |
| 119 | + var stepsIndicator = element.find('.wizard-pf-steps .wizard-pf-step'); |
| 120 | + expect(stepsIndicator.length).toBe(3); |
| 121 | + }); |
| 122 | + |
| 123 | + it('should have two sections in the left-hand pane', function () { |
| 124 | + var stepsIndicator = element.find('.wizard-pf-sidebar .list-group-item'); |
| 125 | + var hiddenStepsIndicator = element.find('section.ng-hide .wizard-pf-sidebar .list-group-item'); |
| 126 | + |
| 127 | + //find all hidden steps and remove them from total step count to make sure correct number are visible |
| 128 | + expect(stepsIndicator.length - hiddenStepsIndicator.length).toBe(2); |
| 129 | + }); |
| 130 | + |
| 131 | + it('should have disabled the next button', function () { |
| 132 | + var checkDisabled = element.find('.wizard-pf-next').attr('disabled'); |
| 133 | + expect(checkDisabled).toBe('disabled'); |
| 134 | + }); |
| 135 | + |
| 136 | + it('should have enabled the next button after input and allowed navigation', function () { |
| 137 | + var nextButton = element.find('.wizard-pf-next'); |
| 138 | + var nameBox = element.find('#new-name'); |
| 139 | + nameBox.val('test').triggerHandler('input'); |
| 140 | + eventFire(nextButton[0], 'click'); |
| 141 | + var stepIndicator = element.find('.wizard-pf-sidebar .list-group-item.active .wizard-pf-substep-number'); |
| 142 | + expect(stepIndicator.text()).toBe('1B.'); |
| 143 | + }); |
| 144 | + |
| 145 | + it('should have allowed moving back to first page after input and allowed navigation', function () { |
| 146 | + var nextButton = element.find('.wizard-pf-next'); |
| 147 | + var nameBox = element.find('#new-name'); |
| 148 | + nameBox.val('test').triggerHandler('input'); |
| 149 | + eventFire(nextButton[0], 'click'); |
| 150 | + var stepIndicator = element.find('.wizard-pf-sidebar .list-group-item.active .wizard-pf-substep-number'); |
| 151 | + expect(stepIndicator.text()).toBe('1B.'); |
| 152 | + |
| 153 | + var backButton = element.find('#backButton'); |
| 154 | + eventFire(backButton[0], 'click'); |
| 155 | + var stepIndicator = element.find('.wizard-pf-sidebar .list-group-item.active .wizard-pf-substep-number'); |
| 156 | + expect(stepIndicator.text()).toBe('1A.'); |
| 157 | + }); |
| 158 | + |
| 159 | + it('should have allowed navigation to review page', function () { |
| 160 | + var nextButton = element.find('.wizard-pf-next'); |
| 161 | + var nameBox = element.find('#new-name'); |
| 162 | + nameBox.val('test').triggerHandler('input'); |
| 163 | + $scope.$digest(); |
| 164 | + |
| 165 | + $scope.currentStep = 'Review'; |
| 166 | + $scope.$digest(); |
| 167 | + $timeout.flush(); |
| 168 | + $timeout.flush(); |
| 169 | + |
| 170 | + var stepIndicator = element.find('section.current .wizard-pf-sidebar .list-group-item.active .wizard-pf-substep-number'); |
| 171 | + expect(stepIndicator.text()).toBe('3A.'); |
| 172 | + }); |
| 173 | + |
| 174 | + it('should hide indicators if the property is set', function () { |
| 175 | + var modalHtml = $templateCache.get('test/wizard/wizard-container.html'); |
| 176 | + element = compileHtml(modalHtml, $scope); |
| 177 | + $scope.hideIndicators = true; |
| 178 | + $scope.$digest(); |
| 179 | + var indicators = element.find('.wizard-pf-steps'); |
| 180 | + expect(indicators.children().length).toBe(0); |
| 181 | + |
| 182 | + // make sure indicators can be turned back on |
| 183 | + $scope.hideIndicators = false; |
| 184 | + $scope.$digest(); |
| 185 | + var indicators = element.find('.wizard-pf-steps'); |
| 186 | + expect(indicators.children().length).toBe(1); |
| 187 | + }); |
| 188 | + |
| 189 | + it('clicking indicators should navigate wizard', function () { |
| 190 | + var indicator = element.find('.wizard-pf-steps .wizard-pf-step a'); |
| 191 | + var nameBox = element.find('#new-name'); |
| 192 | + nameBox.val('test').triggerHandler('input'); |
| 193 | + |
| 194 | + eventFire(indicator[1], 'click'); |
| 195 | + $scope.$digest(); |
| 196 | + |
| 197 | + var selectedSectionTitle = element.find('.wizard-pf-row section.current').attr("step-title"); |
| 198 | + expect(selectedSectionTitle).toBe('Second Step'); |
| 199 | + }); |
| 200 | + |
| 201 | + it('clicking indicators should not navigate wizard if prevented from doing so', function () { |
| 202 | + var indicator = element.find('.wizard-pf-steps .wizard-pf-step a'); |
| 203 | + eventFire(indicator[1], 'click'); |
| 204 | + $scope.$digest(); |
| 205 | + |
| 206 | + var selectedSectionTitle = element.find('.wizard-pf-row section.current').attr("step-title"); |
| 207 | + expect(selectedSectionTitle).not.toBe('Second Step'); |
| 208 | + }); |
| 209 | +}); |
0 commit comments