-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1931 from CodeNow/SAN-5482-oops-url
San 5482 oops url
- Loading branch information
Showing
11 changed files
with
196 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
client/directives/components/buildUpdateNotifications/hangTightDirective.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
'use strict'; | ||
|
||
require('app') | ||
.directive('hangTight', hangTight); | ||
|
||
function hangTight( | ||
$interval, | ||
demoFlowService, | ||
watchOncePromise | ||
) { | ||
return { | ||
restrict: 'A', | ||
templateUrl: 'firstBuildNotificationView', | ||
scope: { | ||
instance: '=' | ||
}, | ||
link: function ($scope) { | ||
var instance = $scope.instance; | ||
|
||
watchOncePromise($scope, function () { | ||
return instance.status() === 'running'; | ||
}, true) | ||
.then(pollContainerUrl); | ||
|
||
function pollContainerUrl () { | ||
var timesToPoll = 15; | ||
var stopPolling = $interval(function (timesToPoll) { | ||
// zero indexed, once we've polled 15 times just go to add branch | ||
if (timesToPoll === 14 && instance.status() === 'running') { | ||
$scope.$emit('demo::dismissUrlCallout', instance.id()); | ||
return cancelPolling(stopPolling, instance); | ||
} | ||
return demoFlowService.checkStatusOnInstance(instance) | ||
.then(function (statusOK) { | ||
if (statusOK) { | ||
return cancelPolling(stopPolling, instance); | ||
} | ||
}); | ||
}, 1000, timesToPoll); | ||
} | ||
|
||
function cancelPolling (stopPolling, instance) { | ||
$interval.cancel(stopPolling); | ||
demoFlowService.setItem('hasSeenHangTightMessage', instance.id()); | ||
} | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
test/unit/directives/components/notifications/hangTightDirective.unit.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
'use strict'; | ||
|
||
var $rootScope; | ||
var $scope; | ||
var element; | ||
var $compile; | ||
var $interval; | ||
var $q; | ||
var $elScope; | ||
|
||
describe('hangTight'.bold.underline.blue, function () { | ||
|
||
var mockInstance; | ||
var demoFlowService; | ||
var mockMainACV; | ||
var mockOpenItems; | ||
|
||
beforeEach(function () { | ||
angular.mock.module('app', function ($provide) { | ||
$provide.factory('demoFlowService', function ($q) { | ||
demoFlowService = { | ||
checkStatusOnInstance: sinon.stub().returns($q.when(false)), | ||
setItem: sinon.stub() | ||
}; | ||
return demoFlowService; | ||
}); | ||
}); | ||
angular.mock.inject(function (_$compile_, _$interval_, _$rootScope_, _$q_) { | ||
$rootScope = _$rootScope_; | ||
$compile = _$compile_; | ||
$interval = _$interval_; | ||
$scope = $rootScope.$new(); | ||
$q = _$q_; | ||
sinon.stub($interval, 'cancel'); | ||
|
||
mockMainACV = { | ||
attrs: { | ||
mainACVAttrs: true | ||
} | ||
}; | ||
mockInstance = { | ||
attrs: { | ||
name: 'foo' | ||
}, | ||
restart: sinon.stub(), | ||
fetch: sinon.stub(), | ||
status: sinon.stub().returns('running'), | ||
stop: sinon.stub(), | ||
start: sinon.stub(), | ||
build: { | ||
deepCopy: sinon.stub() | ||
}, | ||
contextVersion: { | ||
getMainAppCodeVersion: sinon.stub().returns(mockMainACV) | ||
}, | ||
fetchDependencies: sinon.stub().returns({ | ||
models: [] | ||
}), | ||
id: sinon.stub().returns(1), | ||
on: sinon.stub() | ||
}; | ||
$scope.instance = mockInstance; | ||
|
||
mockOpenItems = {}; | ||
|
||
mockOpenItems.getAllFileModels = sinon.stub().returns(mockOpenItems.models); | ||
|
||
var template = directiveTemplate.attribute('hang-tight', { | ||
instance: 'instance', | ||
}); | ||
|
||
element = $compile(template)($scope); | ||
$scope.$digest(); | ||
$elScope = element.isolateScope(); | ||
}); | ||
}); | ||
|
||
describe('watching instance', function () { | ||
it('should poll the status until it retuns true', function () { | ||
$interval.flush(1000); | ||
$scope.$digest(); | ||
sinon.assert.calledOnce(demoFlowService.checkStatusOnInstance); | ||
demoFlowService.checkStatusOnInstance = sinon.stub().returns($q.when(true)); | ||
$interval.flush(1000); | ||
$scope.$digest(); | ||
sinon.assert.calledOnce($interval.cancel); | ||
sinon.assert.calledOnce(demoFlowService.setItem); | ||
}); | ||
it('should emit dismissUrlCallout when it tries 15 times', function () { | ||
var dismissStub = sinon.stub(); | ||
$rootScope.$on('demo::dismissUrlCallout', dismissStub); | ||
$interval.flush(1000); | ||
$scope.$digest(); | ||
sinon.assert.calledOnce(demoFlowService.checkStatusOnInstance); | ||
$interval.flush(15000); | ||
$scope.$digest(); | ||
sinon.assert.calledOnce(dismissStub); | ||
sinon.assert.calledWith(dismissStub, sinon.match.any, mockInstance.id()); | ||
sinon.assert.calledOnce($interval.cancel); | ||
sinon.assert.calledOnce(demoFlowService.setItem); | ||
}); | ||
}); | ||
}); |
Empty file.