api-screen-spec.ts 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. import { expect } from 'chai';
  2. import { Display, screen } from 'electron/main';
  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.getCursorScreenPoint()', () => {
  16. it('returns a point object', () => {
  17. const point = screen.getCursorScreenPoint();
  18. expect(point.x).to.be.a('number');
  19. expect(point.y).to.be.a('number');
  20. });
  21. });
  22. describe('screen.getPrimaryDisplay()', () => {
  23. let display: Display | null = null;
  24. beforeEach(() => {
  25. display = screen.getPrimaryDisplay();
  26. });
  27. afterEach(() => {
  28. display = null;
  29. });
  30. it('returns a display object', () => {
  31. expect(display).to.be.an('object');
  32. });
  33. it('has the correct non-object properties', function () {
  34. expect(display).to.have.property('accelerometerSupport').that.is.a('string');
  35. expect(display).to.have.property('colorDepth').that.is.a('number');
  36. expect(display).to.have.property('colorSpace').that.is.a('string');
  37. expect(display).to.have.property('depthPerComponent').that.is.a('number');
  38. expect(display).to.have.property('detected').that.is.a('boolean');
  39. expect(display).to.have.property('displayFrequency').that.is.a('number');
  40. expect(display).to.have.property('id').that.is.a('number');
  41. expect(display).to.have.property('internal').that.is.a('boolean');
  42. expect(display).to.have.property('label').that.is.a('string');
  43. expect(display).to.have.property('monochrome').that.is.a('boolean');
  44. expect(display).to.have.property('scaleFactor').that.is.a('number');
  45. expect(display).to.have.property('rotation').that.is.a('number');
  46. expect(display).to.have.property('touchSupport').that.is.a('string');
  47. });
  48. it('has a maximumCursorSize object property', () => {
  49. expect(display).to.have.property('maximumCursorSize').that.is.an('object');
  50. const { maximumCursorSize } = display!;
  51. expect(maximumCursorSize).to.have.property('width').that.is.a('number');
  52. expect(maximumCursorSize).to.have.property('height').that.is.a('number');
  53. });
  54. it('has a nativeOrigin object property', () => {
  55. expect(display).to.have.property('nativeOrigin').that.is.an('object');
  56. const { nativeOrigin } = display!;
  57. expect(nativeOrigin).to.have.property('x').that.is.a('number');
  58. expect(nativeOrigin).to.have.property('y').that.is.a('number');
  59. });
  60. it('has a size object property', () => {
  61. expect(display).to.have.property('size').that.is.an('object');
  62. const { size } = display!;
  63. if (process.platform === 'linux') {
  64. expect(size).to.have.property('width').that.is.a('number');
  65. expect(size).to.have.property('height').that.is.a('number');
  66. } else {
  67. expect(size).to.have.property('width').that.is.greaterThan(0);
  68. expect(size).to.have.property('height').that.is.greaterThan(0);
  69. }
  70. });
  71. it('has a workAreaSize object property', () => {
  72. expect(display).to.have.property('workAreaSize').that.is.an('object');
  73. const { workAreaSize } = display!;
  74. if (process.platform === 'linux') {
  75. expect(workAreaSize).to.have.property('width').that.is.a('number');
  76. expect(workAreaSize).to.have.property('height').that.is.a('number');
  77. } else {
  78. expect(workAreaSize).to.have.property('width').that.is.greaterThan(0);
  79. expect(workAreaSize).to.have.property('height').that.is.greaterThan(0);
  80. }
  81. });
  82. it('has a bounds object property', () => {
  83. expect(display).to.have.property('bounds').that.is.an('object');
  84. const { bounds } = display!;
  85. expect(bounds).to.have.property('x').that.is.a('number');
  86. expect(bounds).to.have.property('y').that.is.a('number');
  87. if (process.platform === 'linux') {
  88. expect(bounds).to.have.property('width').that.is.a('number');
  89. expect(bounds).to.have.property('height').that.is.a('number');
  90. } else {
  91. expect(bounds).to.have.property('width').that.is.greaterThan(0);
  92. expect(bounds).to.have.property('height').that.is.greaterThan(0);
  93. }
  94. });
  95. it('has a workArea object property', () => {
  96. expect(display).to.have.property('workArea').that.is.an('object');
  97. const { workArea } = display!;
  98. expect(workArea).to.have.property('x').that.is.a('number');
  99. expect(workArea).to.have.property('y').that.is.a('number');
  100. expect(workArea).to.have.property('width').that.is.greaterThan(0);
  101. expect(workArea).to.have.property('height').that.is.greaterThan(0);
  102. });
  103. });
  104. });