api-screen-spec.ts 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import { expect } from 'chai';
  2. import { screen } from 'electron/main';
  3. import { ifit } from './lib/spec-helpers';
  4. describe('screen module', () => {
  5. describe('methods reassignment', () => {
  6. it('works for a selected method', () => {
  7. const originalFunction = screen.getPrimaryDisplay;
  8. try {
  9. (screen as any).getPrimaryDisplay = () => null;
  10. expect(screen.getPrimaryDisplay()).to.be.null();
  11. } finally {
  12. screen.getPrimaryDisplay = originalFunction;
  13. }
  14. });
  15. });
  16. describe('screen.getCursorScreenPoint()', () => {
  17. it('returns a point object', () => {
  18. const point = screen.getCursorScreenPoint();
  19. expect(point.x).to.be.a('number');
  20. expect(point.y).to.be.a('number');
  21. });
  22. });
  23. describe('screen.getPrimaryDisplay()', () => {
  24. it('returns a display object', () => {
  25. const display = screen.getPrimaryDisplay();
  26. expect(display).to.be.an('object');
  27. });
  28. ifit(process.platform !== 'linux')('has the correct non-object properties', function () {
  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. ifit(process.platform !== 'linux')('has a size object property', function () {
  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. ifit(process.platform !== 'linux')('has a workAreaSize object property', function () {
  51. const display = screen.getPrimaryDisplay();
  52. expect(display).to.have.property('workAreaSize').that.is.an('object');
  53. const workAreaSize = display.workAreaSize;
  54. expect(workAreaSize).to.have.property('width').that.is.greaterThan(0);
  55. expect(workAreaSize).to.have.property('height').that.is.greaterThan(0);
  56. });
  57. ifit(process.platform !== 'linux')('has a bounds object property', function () {
  58. const display = screen.getPrimaryDisplay();
  59. expect(display).to.have.property('bounds').that.is.an('object');
  60. const bounds = display.bounds;
  61. expect(bounds).to.have.property('x').that.is.a('number');
  62. expect(bounds).to.have.property('y').that.is.a('number');
  63. expect(bounds).to.have.property('width').that.is.greaterThan(0);
  64. expect(bounds).to.have.property('height').that.is.greaterThan(0);
  65. });
  66. it('has a workArea object property', function () {
  67. const display = screen.getPrimaryDisplay();
  68. expect(display).to.have.property('workArea').that.is.an('object');
  69. const workArea = display.workArea;
  70. expect(workArea).to.have.property('x').that.is.a('number');
  71. expect(workArea).to.have.property('y').that.is.a('number');
  72. expect(workArea).to.have.property('width').that.is.greaterThan(0);
  73. expect(workArea).to.have.property('height').that.is.greaterThan(0);
  74. });
  75. });
  76. });