Skip to content

Commit

Permalink
feat(task-details): show notification selected task is deleted
Browse files Browse the repository at this point in the history
Related to CAM-7058
  • Loading branch information
zeropaper committed Jan 30, 2017
1 parent e35a161 commit bc0adc7
Show file tree
Hide file tree
Showing 4 changed files with 233 additions and 0 deletions.
66 changes: 66 additions & 0 deletions ui/tasklist/client/scripts/task/directives/cam-tasklist-task.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ module.exports = [ function() {
'$q',
'$location',
'$translate',
// not using $timeout here (although it would be better) because... well... i'd rather not give my opinion
// https://github.com/angular/protractor/blob/master/docs/timeouts.md#waiting-for-angular
'$interval',
'camAPI',
'Notifications',
'Views',
'search',
Expand All @@ -28,6 +32,8 @@ module.exports = [ function() {
$q,
$location,
$translate,
$interval,
camAPI,
Notifications,
Views,
search
Expand Down Expand Up @@ -230,6 +236,66 @@ module.exports = [ function() {
setDefaultTaskDetailTab($scope.taskDetailTabs);
});










var stop;
var taskResource = camAPI.resource('task');

$scope.dismissTask = function(notification) {
clearTask(true);
Notifications.clear(notification.status);
};

function removedNotification(src) {
$translate(src).then(function(status) {
$translate('DISMISS').then(function(dismiss) {
Notifications.addMessage({
type: 'warning',
status: status,
unsafe: true,
message: '<a href class="dismiss" ng-click="notification.scope.dismissTask(notification)">' + dismiss + '</a>',
exclusive: true,
scope: $scope
});
});
});
}

function killTimeout() {
if (stop) {
$interval.cancel(stop);
stop = undefined;
}
}

function processPollingResponse(err) {
if (err) {
var src = enhanceErrorMessage(err.message);
removedNotification(src, err);
killTimeout();
}
}

function pollExistence() {
killTimeout();
if (!$scope.task || !$scope.task.id) {
return;
}
stop = $interval(function() {
taskResource.get($scope.task.id, processPollingResponse);
}, 2000);
}

$scope.$watch('task.id', pollExistence);

$scope.$on('$destroy', killTimeout);
}]
};
}];
2 changes: 2 additions & 0 deletions ui/tasklist/client/scripts/task/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
"Failure",
"FINISHED":
"Finished",
"DISMISS":
"Dismiss",
"INIT_GROUPS_FAILURE":
"Loading the groups of the selected task failed. Try to refresh the page to try again.",
"ADD_GROUP_FAILED":
Expand Down
102 changes: 102 additions & 0 deletions ui/tasklist/tests/specs/task-vanishing-setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
'use strict';

var factory = require('../../../common/tests/setup-factory.js'),
readResource = factory.readResource,
combine = factory.combine,
operation = factory.operation;

var setup1 = combine(
operation('filter', 'create', [{
name: 'All',
query: {},
resourceType: 'Task',
properties: {
variables: [{
name: 'testVar',
label: 'Test Variable'
},
{
name: 'testString',
label:'String Variable'
}]
}
}]),

operation('user', 'create', [{
id: 'test',
firstName: 'Montgomery',
lastName: 'QA',
password: 'test'
},
{
id: 'otheruser',
firstName: 'Other',
lastName: 'User',
password: 'otheruser'
}]),

operation('authorization', 'create', [{
type : 1,
permissions: ['ALL'],
userId: 'test',
groupId: null,
resourceType: 0,
resourceId: 'tasklist'
},
{
type : 1,
permissions: ['ALL'],
userId: 'test',
groupId: null,
resourceType: 5,
resourceId: '*'
},
{
type : 1,
permissions: ['READ'],
userId: 'test',
groupId: null,
resourceType: 7,
resourceId: '*'
},

{
type : 1,
permissions: ['ALL'],
userId: 'otheruser',
groupId: null,
resourceType: 0,
resourceId: 'tasklist'
},
{
type : 1,
permissions: ['ALL'],
userId: 'otheruser',
groupId: null,
resourceType: 5,
resourceId: '*'
},
{
type : 1,
permissions: ['READ'],
userId: 'otheruser',
groupId: null,
resourceType: 7,
resourceId: '*'
}]),

operation('task', 'create', [{
id: '1',
name: 'Task 1'
}]),

operation('task', 'assignee', [{
taskId: '1',
userId: 'test'
}])
);


module.exports = {
setup1: setup1
};
63 changes: 63 additions & 0 deletions ui/tasklist/tests/specs/task-vanishing-spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
'use strict';

var testHelper = require('../../../common/tests/test-helper');
var setupFile = require('./task-vanishing-setup');
var dashboardPage = require('../pages/dashboard');

describe('Task Vanishing Spec', function() {
describe('a task that has been removed or completed', function() {
var tasklistItems;

before(function() {
return testHelper(setupFile.setup1, function() {
dashboardPage.navigateToWebapp('Tasklist');
dashboardPage.authentication.userLogin('test', 'test');

tasklistItems = element.all(by.css('.tasks-list > li'));
tasklistItems.first().element(by.css('.clickable')).click();
});
});


it('disapears from list and shows a notification', function() {
expect(tasklistItems.count()).to.eventually.eql(1);
expect(element(by.css('.task-details .names > h2')).getText()).to.eventually.eql('Task 1');

// simulates a background resolution
browser.executeAsyncScript(function() {
var callback = arguments[arguments.length - 1];
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
callback();
}
};
xhr.open('POST', '/camunda/api/engine/engine/default/task/1/submit-form', true);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.send('{"variables":{}}');
})
.then(function() {
browser.sleep(2500);

// refresh!
tasklistItems = element.all(by.css('.tasks-list > li'));
expect(tasklistItems.count()).to.eventually.eql(1);

expect(element(by.css('.task-details .names > h2')).isPresent()).to.eventually.eql(true);

var status = element(by.css('.page-notifications .status'));
expect(status.isPresent()).to.eventually.eql(true);
expect(status.getText()).to.eventually.eql('The task does not exist anymore');

var dismissButton = element(by.css('.page-notifications a.dismiss'));
dismissButton.click();

// refresh!
tasklistItems = element.all(by.css('.tasks-list > li'));
expect(tasklistItems.count()).to.eventually.eql(0);

expect(element(by.css('.task-details .names > h2')).isPresent()).to.eventually.eql(false);
});
});
});
});

0 comments on commit bc0adc7

Please sign in to comment.