api-screen-spec.ts 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. import { Display, screen, desktopCapturer } from 'electron/main';
  2. import { expect } from 'chai';
  3. describe('screen module', () => {
  4. describe('methods reassignment', () => {
  5. it('works for a selected method', () => {
  6. const originalFunction = screen.getPrimaryDisplay;
  7. try {
  8. (screen as any).getPrimaryDisplay = () => null;
  9. expect(screen.getPrimaryDisplay()).to.be.null();
  10. } finally {
  11. screen.getPrimaryDisplay = originalFunction;
  12. }
  13. });
  14. });
  15. describe('screen.getAllDisplays', () => {
  16. it('returns an array of displays', () => {
  17. const displays = screen.getAllDisplays();
  18. expect(displays).to.be.an('array').with.lengthOf.at.least(1);
  19. for (const display of displays) {
  20. expect(display).to.be.an('object');
  21. }
  22. });
  23. it('returns displays with IDs matching desktopCapturer source display IDs', async () => {
  24. const displayIds = screen.getAllDisplays().map(d => `${d.id}`);
  25. const sources = await desktopCapturer.getSources({ types: ['screen'] });
  26. const sourceIds = sources.map(s => s.display_id);
  27. expect(displayIds).to.have.length(sources.length);
  28. expect(displayIds).to.have.same.members(sourceIds);
  29. });
  30. });
  31. describe('screen.getCursorScreenPoint()', () => {
  32. it('returns a point object', () => {
  33. const point = screen.getCursorScreenPoint();
  34. expect(point.x).to.be.a('number');
  35. expect(point.y).to.be.a('number');
  36. });
  37. });
  38. describe('screen.getPrimaryDisplay()', () => {
  39. let display: Display | null = null;
  40. beforeEach(() => {
  41. display = screen.getPrimaryDisplay();
  42. });
  43. afterEach(() => {
  44. display = null;
  45. });
  46. it('returns a display object', () => {
  47. expect(display).to.be.an('object');
  48. });
  49. it('has the correct non-object properties', function () {
  50. expect(display).to.have.property('accelerometerSupport').that.is.a('string');
  51. expect(display).to.have.property('colorDepth').that.is.a('number');
  52. expect(display).to.have.property('colorSpace').that.is.a('string');
  53. expect(display).to.have.property('depthPerComponent').that.is.a('number');
  54. expect(display).to.have.property('detected').that.is.a('boolean');
  55. expect(display).to.have.property('displayFrequency').that.is.a('number');
  56. expect(display).to.have.property('id').that.is.a('number');
  57. expect(display).to.have.property('internal').that.is.a('boolean');
  58. expect(display).to.have.property('label').that.is.a('string');
  59. expect(display).to.have.property('monochrome').that.is.a('boolean');
  60. expect(display).to.have.property('scaleFactor').that.is.a('number');
  61. expect(display).to.have.property('rotation').that.is.a('number');
  62. expect(display).to.have.property('touchSupport').that.is.a('string');
  63. });
  64. it('has a maximumCursorSize object property', () => {
  65. expect(display).to.have.property('maximumCursorSize').that.is.an('object');
  66. const { maximumCursorSize } = display!;
  67. expect(maximumCursorSize).to.have.property('width').that.is.a('number');
  68. expect(maximumCursorSize).to.have.property('height').that.is.a('number');
  69. });
  70. it('has a nativeOrigin object property', () => {
  71. expect(display).to.have.property('nativeOrigin').that.is.an('object');
  72. const { nativeOrigin } = display!;
  73. expect(nativeOrigin).to.have.property('x').that.is.a('number');
  74. expect(nativeOrigin).to.have.property('y').that.is.a('number');
  75. });
  76. it('has a size object property', () => {
  77. expect(display).to.have.property('size').that.is.an('object');
  78. const { size } = display!;
  79. if (process.platform === 'linux') {
  80. expect(size).to.have.property('width').that.is.a('number');
  81. expect(size).to.have.property('height').that.is.a('number');
  82. } else {
  83. expect(size).to.have.property('width').that.is.greaterThan(0);
  84. expect(size).to.have.property('height').that.is.greaterThan(0);
  85. }
  86. });
  87. it('has a workAreaSize object property', () => {
  88. expect(display).to.have.property('workAreaSize').that.is.an('object');
  89. const { workAreaSize } = display!;
  90. if (process.platform === 'linux') {
  91. expect(workAreaSize).to.have.property('width').that.is.a('number');
  92. expect(workAreaSize).to.have.property('height').that.is.a('number');
  93. } else {
  94. expect(workAreaSize).to.have.property('width').that.is.greaterThan(0);
  95. expect(workAreaSize).to.have.property('height').that.is.greaterThan(0);
  96. }
  97. });
  98. it('has a bounds object property', () => {
  99. expect(display).to.have.property('bounds').that.is.an('object');
  100. const { bounds } = display!;
  101. expect(bounds).to.have.property('x').that.is.a('number');
  102. expect(bounds).to.have.property('y').that.is.a('number');
  103. if (process.platform === 'linux') {
  104. expect(bounds).to.have.property('width').that.is.a('number');
  105. expect(bounds).to.have.property('height').that.is.a('number');
  106. } else {
  107. expect(bounds).to.have.property('width').that.is.greaterThan(0);
  108. expect(bounds).to.have.property('height').that.is.greaterThan(0);
  109. }
  110. });
  111. it('has a workArea object property', () => {
  112. expect(display).to.have.property('workArea').that.is.an('object');
  113. const { workArea } = display!;
  114. expect(workArea).to.have.property('x').that.is.a('number');
  115. expect(workArea).to.have.property('y').that.is.a('number');
  116. expect(workArea).to.have.property('width').that.is.greaterThan(0);
  117. expect(workArea).to.have.property('height').that.is.greaterThan(0);
  118. });
  119. });
  120. });