Skip to content

Commit c885405

Browse files
authored
feat: Add fields subtitleLocKey, subtitleLocArgs for localized subtitle and arguments in notifications (#154)
1 parent b886c88 commit c885405

File tree

5 files changed

+121
-0
lines changed

5 files changed

+121
-0
lines changed

doc/notification.markdown

+2
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ This table shows the name of the setter, with the key-path of the underlying pro
9595
| `title` | `aps.alert.title` | `String` |
9696
| `titleLocKey` | `aps.alert.title-loc-key` | `String` |
9797
| `titleLocArgs` | `aps.alert.title-loc-args` | `Array` |
98+
| `subtitleLocKey` | `aps.alert.subtitle-loc-key` | `String` |
99+
| `subtitleLocArgs` | `aps.alert.subtitle-loc-args` | `Array` |
98100
| `action` | `aps.alert.action` | `String` |
99101
| `actionLocKey` | `aps.alert.action-loc-key` | `String` |
100102
| `launchImage` | `aps.launch-image` | `String` |

index.d.ts

+4
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ interface ApsAlert {
7878
title?: string
7979
"title-loc-key"?: string
8080
"title-loc-args"?: any[]
81+
"subtitle-loc-key"?: string
82+
"subtitle-loc-args"?: any[]
8183
action?: string
8284
"action-loc-key"?: string
8385
}
@@ -173,6 +175,8 @@ export interface NotificationAlertOptions {
173175
body: string;
174176
"title-loc-key"?: string;
175177
"title-loc-args"?: string[];
178+
"subtitle-loc-key"?: string;
179+
"subtitle-loc-args"?: string[];
176180
"action-loc-key"?: string;
177181
"loc-key"?: string;
178182
"loc-args"?: string[];

lib/notification/apsProperties.js

+10
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@ module.exports = {
4949
this.aps.alert['title-loc-args'] = value;
5050
},
5151

52+
set subtitleLocKey(value) {
53+
this.prepareAlert();
54+
this.aps.alert['subtitle-loc-key'] = value;
55+
},
56+
57+
set subtitleLocArgs(value) {
58+
this.prepareAlert();
59+
this.aps.alert['subtitle-loc-args'] = value;
60+
},
61+
5262
set action(value) {
5363
this.prepareAlert();
5464
this.aps.alert.action = value;

lib/notification/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ Notification.prototype = require('./apsProperties');
3636
'subtitle',
3737
'titleLocKey',
3838
'titleLocArgs',
39+
'subtitleLocKey',
40+
'subtitleLocArgs',
3941
'action',
4042
'actionLocKey',
4143
'launchImage',

test/notification/apsProperties.js

+103
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ describe('Notification', function () {
261261
});
262262
});
263263
});
264+
264265
describe('titleLocKey', function () {
265266
it('sets the aps.alert.title-loc-key property', function () {
266267
note.titleLocKey = 'Warning';
@@ -363,6 +364,108 @@ describe('Notification', function () {
363364
});
364365
});
365366

367+
describe('subtitleLocKey', function () {
368+
it('sets the aps.alert.subtitle-loc-key property', function () {
369+
note.subtitleLocKey = 'Warning';
370+
expect(compiledOutput()).to.have.nested.deep.property('aps.alert.subtitle-loc-key', 'Warning');
371+
});
372+
373+
context('alert is already an object', function () {
374+
beforeEach(function () {
375+
note.alert = { body: 'Test', 'launch-image': 'test.png' };
376+
note.subtitleLocKey = 'Warning';
377+
});
378+
379+
it('contains all expected properties', function () {
380+
expect(compiledOutput()).to.have.nested.deep.property('aps.alert').that.deep.equals({
381+
body: 'Test',
382+
'launch-image': 'test.png',
383+
'subtitle-loc-key': 'Warning',
384+
});
385+
});
386+
});
387+
388+
context('alert is already a string', function () {
389+
beforeEach(function () {
390+
note.alert = 'Hello, world';
391+
note.subtitleLocKey = 'Warning';
392+
});
393+
394+
it('retains the alert body correctly', function () {
395+
expect(compiledOutput()).to.have.nested.deep.property('aps.alert.body', 'Hello, world');
396+
});
397+
398+
it('sets the aps.alert.subtitle-loc-key property', function () {
399+
expect(compiledOutput()).to.have.nested.deep.property(
400+
'aps.alert.subtitle-loc-key',
401+
'Warning'
402+
);
403+
});
404+
});
405+
406+
describe('setAlert', function () {
407+
it('is chainable', function () {
408+
expect(note.setSubtitleLocKey('greeting')).to.equal(note);
409+
expect(compiledOutput()).to.have.nested.deep.property(
410+
'aps.alert.subtitle-loc-key',
411+
'greeting'
412+
);
413+
});
414+
});
415+
});
416+
417+
describe('subtitleLocArgs', function () {
418+
it('sets the aps.alert.subtitle-loc-args property', function () {
419+
note.subtitleLocArgs = ['arg1', 'arg2'];
420+
expect(compiledOutput())
421+
.to.have.nested.deep.property('aps.alert.subtitle-loc-args')
422+
.that.deep.equals(['arg1', 'arg2']);
423+
});
424+
425+
context('alert is already an object', function () {
426+
beforeEach(function () {
427+
note.alert = { body: 'Test', 'launch-image': 'test.png' };
428+
note.subtitleLocArgs = ['Hi there'];
429+
});
430+
431+
it('contains all expected properties', function () {
432+
expect(compiledOutput())
433+
.to.have.nested.deep.property('aps.alert')
434+
.that.deep.equals({
435+
body: 'Test',
436+
'launch-image': 'test.png',
437+
'subtitle-loc-args': ['Hi there'],
438+
});
439+
});
440+
});
441+
442+
context('alert is already a string', function () {
443+
beforeEach(function () {
444+
note.alert = 'Hello, world';
445+
note.subtitleLocArgs = ['Hi there'];
446+
});
447+
448+
it('retains the alert body', function () {
449+
expect(compiledOutput()).to.have.nested.deep.property('aps.alert.body', 'Hello, world');
450+
});
451+
452+
it('sets the aps.alert.subtitle-loc-args property', function () {
453+
expect(compiledOutput())
454+
.to.have.nested.deep.property('aps.alert.subtitle-loc-args')
455+
.that.deep.equals(['Hi there']);
456+
});
457+
});
458+
459+
describe('setTitleLocArgs', function () {
460+
it('is chainable', function () {
461+
expect(note.setTitleLocArgs(['iPhone 6s'])).to.equal(note);
462+
expect(compiledOutput())
463+
.to.have.nested.deep.property('aps.alert.title-loc-args')
464+
.that.deep.equals(['iPhone 6s']);
465+
});
466+
});
467+
});
468+
366469
describe('action', function () {
367470
it('sets the aps.alert.action property', function () {
368471
note.action = 'View';

0 commit comments

Comments
 (0)