Skip to content

Commit 8559966

Browse files
committed
Merge branch 't/12955' into major
2 parents e1a4833 + 377324b commit 8559966

File tree

6 files changed

+117
-3
lines changed

6 files changed

+117
-3
lines changed

plugins/notificationaggregator/plugin.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,8 @@
336336
this._doneWeights -= task._doneWeight;
337337
}
338338

339+
this._totalWeights -= task._weight;
340+
339341
this._tasks.splice( index, 1 );
340342
// And we also should inform the UI about this change.
341343
this.update();

tests/plugins/notificationaggregator/aggregator.js

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,65 @@
299299
assert.areSame( 20, instance._doneWeights, 'instance._doneWeights reduced' );
300300
},
301301

302+
'test cancel() subtracts from totalWeight': function() {
303+
var aggregator = new Aggregator( this.editor, '' ),
304+
task1 = aggregator.createTask( { weight: 10 } ),
305+
task2 = aggregator.createTask( { weight: 10 } );
306+
307+
aggregator.createTask( { weight: 10 } ); // task 3
308+
aggregator.createTask( { weight: 10 } ); // task 4
309+
310+
task1.done();
311+
312+
assert.areSame( 25, Math.round( aggregator.getPercentage() * 100 ) );
313+
314+
task2.cancel();
315+
316+
assert.areSame( 33, Math.round( aggregator.getPercentage() * 100 ) );
317+
},
318+
319+
'test cancel() subtracts from totalWeight and doneWeight': function() {
320+
var aggregator = new Aggregator( this.editor, '' ),
321+
task1 = aggregator.createTask( { weight: 10 } ),
322+
task2 = aggregator.createTask( { weight: 10 } );
323+
324+
aggregator.createTask( { weight: 10 } ); // task 3
325+
aggregator.createTask( { weight: 10 } ); // task 4
326+
327+
task1.done();
328+
task2.update( 6 );
329+
330+
// 16 / 40
331+
assert.areSame( 40, Math.round( aggregator.getPercentage() * 100 ) );
332+
333+
task2.cancel();
334+
335+
// 10 / 30
336+
assert.areSame( 33, Math.round( aggregator.getPercentage() * 100 ) );
337+
},
338+
339+
'test canceling the last task finishes aggregator': function() {
340+
var aggregator = new Aggregator( this.editor, '' ),
341+
task1 = aggregator.createTask( { weight: 10 } ),
342+
task2 = aggregator.createTask( { weight: 10 } ),
343+
finishedSpy = sinon.spy();
344+
345+
aggregator.on( 'finished', finishedSpy );
346+
347+
task1.done();
348+
task2.update( 5 );
349+
350+
// 15 / 20
351+
assert.areSame( 75, Math.round( aggregator.getPercentage() * 100 ) );
352+
353+
task2.cancel();
354+
355+
// 10 / 10
356+
assert.areSame( 100, Math.round( aggregator.getPercentage() * 100 ) );
357+
assert.isTrue( aggregator.isFinished(), 'isFinished()' );
358+
assert.isTrue( finishedSpy.calledOnce, 'finished was fired' );
359+
},
360+
302361
// Ensure that subsequent remove attempt for the same task won't result with an error.
303362
'test _removeTask subsequent': function() {
304363
var instance = new Aggregator( this.editor, '' );
@@ -406,4 +465,4 @@
406465
}
407466
} );
408467

409-
} )();
468+
} )();

tests/plugins/notificationaggregator/manual/complex/multitask.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@bender-tags: notification
1+
@bender-tags: notification, tc, 4.5.0
22
@bender-ui: collapsed
33
@bender-ckeditor-plugins: wysiwygarea, toolbar, undo, notificationaggregator
44

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<div id="editor1">
2+
<p>Foo foo foo</p>
3+
</div>
4+
<script>
5+
var editor = CKEDITOR.replace( 'editor1' );
6+
7+
function createAggregator() {
8+
// Init notification aggregator.
9+
var aggregator = notification = new CKEDITOR.plugins.notificationAggregator(
10+
editor,
11+
'Loading {current} of {max}... {percentage}%'
12+
),
13+
// Create 2 tasks.
14+
tasks = [
15+
aggregator.createTask( { weight: 10 } ),
16+
aggregator.createTask( { weight: 10 } )
17+
],
18+
testActions = [
19+
function() {
20+
tasks[ 0 ].done();
21+
},
22+
function() {
23+
tasks[ 1 ].cancel();
24+
}
25+
];
26+
27+
execute( testActions );
28+
}
29+
30+
function execute( actions ) {
31+
var action = actions.shift();
32+
33+
if ( !action )
34+
return;
35+
36+
setTimeout( function() {
37+
action();
38+
execute( actions );
39+
}, 2000 );
40+
}
41+
</script>
42+
<p>
43+
<input onclick="createAggregator();" type="button" value="Init aggregator">
44+
</p>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@bender-tags: notification, tc, 4.5.0
2+
@bender-ui: collapsed
3+
@bender-ckeditor-plugins: wysiwygarea, toolbar, notificationaggregator
4+
5+
---
6+
7+
1. Click "Init aggregator" button.
8+
1. Expected status after 2 seconds: "1 of 2... 50%".
9+
1. Expected status after 4 seconds: "1 of 1... 100%".

tests/plugins/notificationaggregator/manual/complex/weight.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@bender-tags: notification
1+
@bender-tags: notification, tc, 4.5.0
22
@bender-ui: collapsed
33
@bender-ckeditor-plugins: wysiwygarea, toolbar, undo, notificationaggregator
44

0 commit comments

Comments
 (0)