api-notification-spec.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. import { expect } from 'chai';
  2. import { Notification } from 'electron/main';
  3. import { emittedOnce } from './events-helpers';
  4. import { ifit } from './spec-helpers';
  5. describe('Notification module', () => {
  6. it('is supported', () => {
  7. expect(Notification.isSupported()).to.be.a('boolean');
  8. });
  9. it('inits, gets and sets basic string properties correctly', () => {
  10. const n = new Notification({
  11. title: 'title',
  12. subtitle: 'subtitle',
  13. body: 'body',
  14. replyPlaceholder: 'replyPlaceholder',
  15. sound: 'sound',
  16. closeButtonText: 'closeButtonText'
  17. });
  18. expect(n.title).to.equal('title');
  19. n.title = 'title1';
  20. expect(n.title).to.equal('title1');
  21. expect(n.subtitle).equal('subtitle');
  22. n.subtitle = 'subtitle1';
  23. expect(n.subtitle).equal('subtitle1');
  24. expect(n.body).to.equal('body');
  25. n.body = 'body1';
  26. expect(n.body).to.equal('body1');
  27. expect(n.replyPlaceholder).to.equal('replyPlaceholder');
  28. n.replyPlaceholder = 'replyPlaceholder1';
  29. expect(n.replyPlaceholder).to.equal('replyPlaceholder1');
  30. expect(n.sound).to.equal('sound');
  31. n.sound = 'sound1';
  32. expect(n.sound).to.equal('sound1');
  33. expect(n.closeButtonText).to.equal('closeButtonText');
  34. n.closeButtonText = 'closeButtonText1';
  35. expect(n.closeButtonText).to.equal('closeButtonText1');
  36. });
  37. it('inits, gets and sets basic boolean properties correctly', () => {
  38. const n = new Notification({
  39. title: 'title',
  40. body: 'body',
  41. silent: true,
  42. hasReply: true
  43. });
  44. expect(n.silent).to.be.true('silent');
  45. n.silent = false;
  46. expect(n.silent).to.be.false('silent');
  47. expect(n.hasReply).to.be.true('has reply');
  48. n.hasReply = false;
  49. expect(n.hasReply).to.be.false('has reply');
  50. });
  51. it('inits, gets and sets actions correctly', () => {
  52. const n = new Notification({
  53. title: 'title',
  54. body: 'body',
  55. actions: [
  56. {
  57. type: 'button',
  58. text: '1'
  59. }, {
  60. type: 'button',
  61. text: '2'
  62. }
  63. ]
  64. });
  65. expect(n.actions.length).to.equal(2);
  66. expect(n.actions[0].type).to.equal('button');
  67. expect(n.actions[0].text).to.equal('1');
  68. expect(n.actions[1].type).to.equal('button');
  69. expect(n.actions[1].text).to.equal('2');
  70. n.actions = [
  71. {
  72. type: 'button',
  73. text: '3'
  74. }, {
  75. type: 'button',
  76. text: '4'
  77. }
  78. ];
  79. expect(n.actions.length).to.equal(2);
  80. expect(n.actions[0].type).to.equal('button');
  81. expect(n.actions[0].text).to.equal('3');
  82. expect(n.actions[1].type).to.equal('button');
  83. expect(n.actions[1].text).to.equal('4');
  84. });
  85. it('can be shown and closed', () => {
  86. const n = new Notification({
  87. title: 'test notification',
  88. body: 'test body',
  89. silent: true
  90. });
  91. n.show();
  92. n.close();
  93. });
  94. ifit(process.platform === 'darwin')('emits show and close events', async () => {
  95. const n = new Notification({
  96. title: 'test notification',
  97. body: 'test body',
  98. silent: true
  99. });
  100. {
  101. const e = emittedOnce(n, 'show');
  102. n.show();
  103. await e;
  104. }
  105. {
  106. const e = emittedOnce(n, 'close');
  107. n.close();
  108. await e;
  109. }
  110. });
  111. // TODO(sethlu): Find way to test init with notification icon?
  112. });