Skip to content
This repository was archived by the owner on Jun 26, 2020. It is now read-only.

Commit abbb68f

Browse files
author
Piotr Jasiun
authored
Merge pull request #242 from ckeditor/t/241
Feature: Added optional notification title. Closes #241.
2 parents 737b55f + 10299b4 commit abbb68f

File tree

2 files changed

+94
-10
lines changed

2 files changed

+94
-10
lines changed

src/notification/notification.js

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,23 @@ export default class Notification extends Plugin {
5252
* } );
5353
*
5454
* will fire `show:success:upload:image` event.
55+
* Title of the notification can be provided:
56+
*
57+
* showSuccess( 'Image is uploaded.', {
58+
* title: 'Image upload success'
59+
* });
5560
*
5661
* @param {String} message Content of the notification.
5762
* @param {Object} [data={}] Additional data.
5863
* @param {String} [data.namespace] Additional event namespace.
64+
* @param {String} [data.title] Title of the notification.
5965
*/
6066
showSuccess( message, data = {} ) {
6167
this._showNotification( {
6268
message,
6369
type: 'success',
64-
namespace: data.namespace
70+
namespace: data.namespace,
71+
title: data.title
6572
} );
6673
}
6774

@@ -76,16 +83,23 @@ export default class Notification extends Plugin {
7683
* } );
7784
*
7885
* will fire `show:info:editor:status` event.
86+
* Title of the notification can be provided:
87+
*
88+
* showInfo( 'Editor is offline.', {
89+
* title: 'Network information'
90+
* });
7991
*
8092
* @param {String} message Content of the notification.
8193
* @param {Object} [data={}] Additional data.
8294
* @param {String} [data.namespace] Additional event namespace.
95+
* @param {String} [data.title] Title of the notification.
8396
*/
8497
showInfo( message, data = {} ) {
8598
this._showNotification( {
8699
message,
87100
type: 'info',
88-
namespace: data.namespace
101+
namespace: data.namespace,
102+
title: data.title
89103
} );
90104
}
91105

@@ -100,6 +114,11 @@ export default class Notification extends Plugin {
100114
* } );
101115
*
102116
* will fire `show:warning:upload:image` event.
117+
* Title of the notification can be provided:
118+
*
119+
* showWarning( 'Image upload error.', {
120+
* title: 'Upload failed'
121+
* });
103122
*
104123
* Note that each unhandled and not stopped `warning` notification will be displayed as system alert.
105124
* Plugin responsible for displaying warnings should `stop()` the event to prevent of displaying it as alert:
@@ -127,12 +146,14 @@ export default class Notification extends Plugin {
127146
* @param {String} message Content of the notification.
128147
* @param {Object} [data={}] Additional data.
129148
* @param {String} [data.namespace] Additional event namespace.
149+
* @param {String} [data.title] Title of the notification.
130150
*/
131151
showWarning( message, data = {} ) {
132152
this._showNotification( {
133153
message,
134154
type: 'warning',
135-
namespace: data.namespace
155+
namespace: data.namespace,
156+
title: data.title
136157
} );
137158
}
138159

@@ -144,13 +165,15 @@ export default class Notification extends Plugin {
144165
* @param {String} data.message Content of the notification.
145166
* @param {'success'|'info'|'warning'} data.type Type of message.
146167
* @param {String} [data.namespace] Additional event namespace.
168+
* @param {String} [data.title=''] Title of the notification.
147169
*/
148170
_showNotification( data ) {
149171
const event = `show:${ data.type }` + ( data.namespace ? `:${ data.namespace }` : '' );
150172

151173
this.fire( event, {
152174
message: data.message,
153-
type: data.type
175+
type: data.type,
176+
title: data.title || ''
154177
} );
155178
}
156179

@@ -160,6 +183,7 @@ export default class Notification extends Plugin {
160183
* @event show
161184
* @param {Object} data Notification data.
162185
* @param {String} data.message Content of the notification.
186+
* @param {String} data.title Title of the notification.
163187
* @param {'success'|'info'|'warning'} data.type Type of notification.
164188
*/
165189

@@ -169,6 +193,7 @@ export default class Notification extends Plugin {
169193
* @event show:success
170194
* @param {Object} data Notification data.
171195
* @param {String} data.message Content of the notification.
196+
* @param {String} data.title Title of the notification.
172197
* @param {'success'} data.type Type of notification.
173198
*/
174199

@@ -178,6 +203,7 @@ export default class Notification extends Plugin {
178203
* @event show:info
179204
* @param {Object} data Notification data.
180205
* @param {String} data.message Content of the notification.
206+
* @param {String} data.title Title of the notification.
181207
* @param {'info'} data.type Type of notification.
182208
*/
183209

@@ -190,6 +216,7 @@ export default class Notification extends Plugin {
190216
* @event show:warning
191217
* @param {Object} data Notification data.
192218
* @param {String} data.message Content of the notification.
219+
* @param {String} data.title Title of the notification.
193220
* @param {'warning'} data.type Type of notification.
194221
*/
195222
}

tests/notification/notification.js

Lines changed: 63 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ describe( 'Notification', () => {
4242
sinon.assert.calledOnce( spy );
4343
expect( spy.firstCall.args[ 1 ] ).to.deep.equal( {
4444
message: 'foo bar',
45-
type: 'success'
45+
type: 'success',
46+
title: ''
4647
} );
4748
} );
4849

@@ -58,7 +59,25 @@ describe( 'Notification', () => {
5859
sinon.assert.calledOnce( spy );
5960
expect( spy.firstCall.args[ 1 ] ).to.deep.equal( {
6061
message: 'foo bar',
61-
type: 'success'
62+
type: 'success',
63+
title: ''
64+
} );
65+
} );
66+
67+
it( 'should fire `show:success` event with title', () => {
68+
const spy = testUtils.sinon.spy();
69+
70+
notification.on( 'show:success', spy );
71+
72+
notification.showSuccess( 'foo bar', {
73+
title: 'foo bar baz'
74+
} );
75+
76+
sinon.assert.calledOnce( spy );
77+
expect( spy.firstCall.args[ 1 ] ).to.deep.equal( {
78+
message: 'foo bar',
79+
type: 'success',
80+
title: 'foo bar baz'
6281
} );
6382
} );
6483
} );
@@ -74,7 +93,8 @@ describe( 'Notification', () => {
7493
sinon.assert.calledOnce( spy );
7594
expect( spy.firstCall.args[ 1 ] ).to.deep.equal( {
7695
message: 'foo bar',
77-
type: 'info'
96+
type: 'info',
97+
title: ''
7898
} );
7999
} );
80100

@@ -90,7 +110,25 @@ describe( 'Notification', () => {
90110
sinon.assert.calledOnce( spy );
91111
expect( spy.firstCall.args[ 1 ] ).to.deep.equal( {
92112
message: 'foo bar',
93-
type: 'info'
113+
type: 'info',
114+
title: ''
115+
} );
116+
} );
117+
118+
it( 'should fire `show:info` event with title', () => {
119+
const spy = testUtils.sinon.spy();
120+
121+
notification.on( 'show:info', spy );
122+
123+
notification.showInfo( 'foo bar', {
124+
title: 'foo bar baz'
125+
} );
126+
127+
sinon.assert.calledOnce( spy );
128+
expect( spy.firstCall.args[ 1 ] ).to.deep.equal( {
129+
message: 'foo bar',
130+
type: 'info',
131+
title: 'foo bar baz'
94132
} );
95133
} );
96134
} );
@@ -112,7 +150,8 @@ describe( 'Notification', () => {
112150
sinon.assert.calledOnce( spy );
113151
expect( spy.firstCall.args[ 1 ] ).to.deep.equal( {
114152
message: 'foo bar',
115-
type: 'warning'
153+
type: 'warning',
154+
title: ''
116155
} );
117156
} );
118157

@@ -128,7 +167,25 @@ describe( 'Notification', () => {
128167
sinon.assert.calledOnce( spy );
129168
expect( spy.firstCall.args[ 1 ] ).to.deep.equal( {
130169
message: 'foo bar',
131-
type: 'warning'
170+
type: 'warning',
171+
title: ''
172+
} );
173+
} );
174+
175+
it( 'should fire `show:warning` event with title', () => {
176+
const spy = testUtils.sinon.spy();
177+
178+
notification.on( 'show:warning', spy );
179+
180+
notification.showWarning( 'foo bar', {
181+
title: 'foo bar baz'
182+
} );
183+
184+
sinon.assert.calledOnce( spy );
185+
expect( spy.firstCall.args[ 1 ] ).to.deep.equal( {
186+
message: 'foo bar',
187+
type: 'warning',
188+
title: 'foo bar baz'
132189
} );
133190
} );
134191

0 commit comments

Comments
 (0)