Skip to content
Permalink
Browse files

Merge branch 't/12955' into major

  • Loading branch information...
Reinmar committed Mar 30, 2015
2 parents e1a4833 + 377324b commit 85599661377f140d3c9c9eb44812e19c583e722c
@@ -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();
@@ -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, '' );
@@ -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

@@ -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

0 comments on commit 8559966

Please sign in to comment.
You can’t perform that action at this time.