api-screen-spec.ts 3.7 KB

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