Skip to content

Commit

Permalink
Merge branch 't/12955' into major
Browse files Browse the repository at this point in the history
  • Loading branch information
Reinmar committed Mar 30, 2015
2 parents e1a4833 + 377324b commit 8559966
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 3 deletions.
2 changes: 2 additions & 0 deletions plugins/notificationaggregator/plugin.js
Expand Up @@ -336,6 +336,8 @@
this._doneWeights -= task._doneWeight;
}

this._totalWeights -= task._weight;

this._tasks.splice( index, 1 );
// And we also should inform the UI about this change.
this.update();
Expand Down
61 changes: 60 additions & 1 deletion tests/plugins/notificationaggregator/aggregator.js
Expand Up @@ -299,6 +299,65 @@
assert.areSame( 20, instance._doneWeights, 'instance._doneWeights reduced' );
},

'test cancel() subtracts from totalWeight': function() {
var aggregator = new Aggregator( this.editor, '' ),
task1 = aggregator.createTask( { weight: 10 } ),
task2 = aggregator.createTask( { weight: 10 } );

aggregator.createTask( { weight: 10 } ); // task 3
aggregator.createTask( { weight: 10 } ); // task 4

task1.done();

assert.areSame( 25, Math.round( aggregator.getPercentage() * 100 ) );

task2.cancel();

assert.areSame( 33, Math.round( aggregator.getPercentage() * 100 ) );
},

'test cancel() subtracts from totalWeight and doneWeight': function() {
var aggregator = new Aggregator( this.editor, '' ),
task1 = aggregator.createTask( { weight: 10 } ),
task2 = aggregator.createTask( { weight: 10 } );

aggregator.createTask( { weight: 10 } ); // task 3
aggregator.createTask( { weight: 10 } ); // task 4

task1.done();
task2.update( 6 );

// 16 / 40
assert.areSame( 40, Math.round( aggregator.getPercentage() * 100 ) );

task2.cancel();

// 10 / 30
assert.areSame( 33, Math.round( aggregator.getPercentage() * 100 ) );
},

'test canceling the last task finishes aggregator': function() {
var aggregator = new Aggregator( this.editor, '' ),
task1 = aggregator.createTask( { weight: 10 } ),
task2 = aggregator.createTask( { weight: 10 } ),
finishedSpy = sinon.spy();

aggregator.on( 'finished', finishedSpy );

task1.done();
task2.update( 5 );

// 15 / 20
assert.areSame( 75, Math.round( aggregator.getPercentage() * 100 ) );

task2.cancel();

// 10 / 10
assert.areSame( 100, Math.round( aggregator.getPercentage() * 100 ) );
assert.isTrue( aggregator.isFinished(), 'isFinished()' );
assert.isTrue( finishedSpy.calledOnce, 'finished was fired' );
},

// Ensure that subsequent remove attempt for the same task won't result with an error.
'test _removeTask subsequent': function() {
var instance = new Aggregator( this.editor, '' );
Expand Down Expand Up @@ -406,4 +465,4 @@
}
} );

} )();
} )();
@@ -1,4 +1,4 @@
@bender-tags: notification
@bender-tags: notification, tc, 4.5.0
@bender-ui: collapsed
@bender-ckeditor-plugins: wysiwygarea, toolbar, undo, notificationaggregator

Expand Down
44 changes: 44 additions & 0 deletions tests/plugins/notificationaggregator/manual/complex/removing.html
@@ -0,0 +1,44 @@
<div id="editor1">
<p>Foo foo foo</p>
</div>
<script>
var editor = CKEDITOR.replace( 'editor1' );

function createAggregator() {
// Init notification aggregator.
var aggregator = notification = new CKEDITOR.plugins.notificationAggregator(
editor,
'Loading {current} of {max}... {percentage}%'
),
// Create 2 tasks.
tasks = [
aggregator.createTask( { weight: 10 } ),
aggregator.createTask( { weight: 10 } )
],
testActions = [
function() {
tasks[ 0 ].done();
},
function() {
tasks[ 1 ].cancel();
}
];

execute( testActions );
}

function execute( actions ) {
var action = actions.shift();

if ( !action )
return;

setTimeout( function() {
action();
execute( actions );
}, 2000 );
}
</script>
<p>
<input onclick="createAggregator();" type="button" value="Init aggregator">
</p>
@@ -0,0 +1,9 @@
@bender-tags: notification, tc, 4.5.0
@bender-ui: collapsed
@bender-ckeditor-plugins: wysiwygarea, toolbar, notificationaggregator

---

1. Click "Init aggregator" button.
1. Expected status after 2 seconds: "1 of 2... 50%".
1. Expected status after 4 seconds: "1 of 1... 100%".
@@ -1,4 +1,4 @@
@bender-tags: notification
@bender-tags: notification, tc, 4.5.0
@bender-ui: collapsed
@bender-ckeditor-plugins: wysiwygarea, toolbar, undo, notificationaggregator

Expand Down

0 comments on commit 8559966

Please sign in to comment.