api-screen-spec.ts 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import { expect } from 'chai';
  2. import { 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. it('returns a display object', () => {
  24. const display = screen.getPrimaryDisplay();
  25. expect(display).to.be.an('object');
  26. });
  27. it('has the correct non-object properties', function () {
  28. if (process.platform === 'linux') this.skip();
  29. const display = screen.getPrimaryDisplay();
  30. expect(display).to.have.property('scaleFactor').that.is.a('number');
  31. expect(display).to.have.property('id').that.is.a('number');
  32. expect(display).to.have.property('label').that.is.a('string');
  33. expect(display).to.have.property('rotation').that.is.a('number');
  34. expect(display).to.have.property('touchSupport').that.is.a('string');
  35. expect(display).to.have.property('accelerometerSupport').that.is.a('string');
  36. expect(display).to.have.property('internal').that.is.a('boolean');
  37. expect(display).to.have.property('monochrome').that.is.a('boolean');
  38. expect(display).to.have.property('depthPerComponent').that.is.a('number');
  39. expect(display).to.have.property('colorDepth').that.is.a('number');
  40. expect(display).to.have.property('colorSpace').that.is.a('string');
  41. expect(display).to.have.property('displayFrequency').that.is.a('number');
  42. });
  43. it('has a size object property', function () {
  44. if (process.platform === 'linux') this.skip();
  45. const display = screen.getPrimaryDisplay();
  46. expect(display).to.have.property('size').that.is.an('object');
  47. const size = display.size;
  48. expect(size).to.have.property('width').that.is.greaterThan(0);
  49. expect(size).to.have.property('height').that.is.greaterThan(0);
  50. });
  51. it('has a workAreaSize object property', function () {
  52. if (process.platform === 'linux') this.skip();
  53. const display = screen.getPrimaryDisplay();
  54. expect(display).to.have.property('workAreaSize').that.is.an('object');
  55. const workAreaSize = display.workAreaSize;
  56. expect(workAreaSize).to.have.property('width').that.is.greaterThan(0);
  57. expect(workAreaSize).to.have.property('height').that.is.greaterThan(0);
  58. });
  59. it('has a bounds object property', function () {
  60. if (process.platform === 'linux') this.skip();
  61. const display = screen.getPrimaryDisplay();
  62. expect(display).to.have.property('bounds').that.is.an('object');
  63. const bounds = display.bounds;
  64. expect(bounds).to.have.property('x').that.is.a('number');
  65. expect(bounds).to.have.property('y').that.is.a('number');
  66. expect(bounds).to.have.property('width').that.is.greaterThan(0);
  67. expect(bounds).to.have.property('height').that.is.greaterThan(0);
  68. });
  69. it('has a workArea object property', function () {
  70. const display = screen.getPrimaryDisplay();
  71. expect(display).to.have.property('workArea').that.is.an('object');
  72. const workArea = display.workArea;
  73. expect(workArea).to.have.property('x').that.is.a('number');
  74. expect(workArea).to.have.property('y').that.is.a('number');
  75. expect(workArea).to.have.property('width').that.is.greaterThan(0);
  76. expect(workArea).to.have.property('height').that.is.greaterThan(0);
  77. });
  78. });
  79. });