'use strict';
appDS2.controller("changeManagementManualTasksController", ["$uibModalInstance", "jobInfo", "MsoService", "COMPONENT",
- "$log", changeManagementManualTasksController]);
+ "$log", "moment", changeManagementManualTasksController]);
- function changeManagementManualTasksController($uibModalInstance, jobInfo, MsoService, COMPONENT, $log) {
+ function changeManagementManualTasksController($uibModalInstance, jobInfo, MsoService, COMPONENT, $log, moment) {
var vm = this;
vm.manualTasks = [];
return vm.manualTasks.includes(task);
};
+ vm.timeoutHumanized = function() {
+ // moment.duration() can parse ISO 8601 time-intervals,
+ // e.g. "P1Y2M10DT2H30M"
+ // https://en.wikipedia.org/wiki/ISO_8601#Time_intervals
+ let duration = moment.duration(vm.timeout);
+
+ return isDurationValid()
+ ? durationAsHoursAndMinutes() + ' hours (' + vm.timeout + ')'
+ : vm.timeout;
+
+
+ function isDurationValid() {
+ return duration.isValid() && duration.toISOString() !== 'P0D';
+ }
+
+ function durationAsHoursAndMinutes() {
+ return ''
+ + Math.floor(duration.asHours())
+ + ':'
+ + withLeadingZero(duration.minutes());
+ }
+
+ function withLeadingZero(x) {
+ return ("00" + Math.round(x)).slice(-2);
+ }
+ };
+
vm.__test_only__ = {
loadAvailableTasks: loadAvailableTasks,
};
require('./change-management-manual-tasks.controller');
const jestMock = require('jest-mock');
+const moment = require('moment');
describe('changeManagementManualTasksController testing', () => {
let $controller;
"MsoService": $MsoService,
"$uibModalInstance": $uibModalInstance,
"$log": $log,
+ "moment": moment,
"jobInfo": {
requestState: job.requestStatus.requestState,
details: job.requestStatus.statusMessage,
});
});
+ test('should humanize timeout if proper ISO-8601', () => {
+ $controller.timeout = 'PT3350S';
+ expect($controller.timeoutHumanized()).toEqual('0:55 hours (PT3350S)');
+ });
+
+ test('should humanize timeout if proper ISO-8601', () => {
+ $controller.timeout = 'P3DT1H1M';
+ expect($controller.timeoutHumanized()).toEqual('73:01 hours (P3DT1H1M)');
+ });
+
+ test('should drive-through timeout if not proper ISO-8601', () => {
+ $controller.timeout = '56 minutes';
+ expect($controller.timeoutHumanized()).toEqual('56 minutes');
+ });
+
+ test('should drive-through timeout if undefined', () => {
+ $controller.timeout = undefined;
+ expect($controller.timeoutHumanized()).toEqual(undefined);
+ });
+
test('should find manual task using isTaskAvailable', () => {
expect($controller.isTaskAvailable('abort')).toBeTruthy();
expect($controller.isTaskAvailable('resume')).toBeTruthy();
<div class="modal-body">
<span id="in-progress-modal-description" ng-if="vm.description">{{vm.description}}</span>
- <span id="in-progress-modal-timeout" ng-if="vm.timeout">({{vm.timeout}})</span>
+ <span id="in-progress-modal-timeout" ng-if="vm.timeout" class="text-danger"><strong>(task will time out in {{vm.timeoutHumanized()}})</strong></span>
</div>
<div class="modal-footer">
"errorCode": "404",
"errorMessage": "Failed in A&AI 404",
"description": "Manually restart VM id vm8776da8-4c8cbe860422, then verify logs still contain task id daf4dd84-b77a-42da-a051-3239b7a9392c",
- "timeout": "PT3000S",
+ "timeout": "P3DT1H1M",
"validResponses": [
"rollback",
"abort",