• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1import { paramMock } from "./utils"
2
3export function mockDisplay() {
4    const displayMock = {
5        densityDPI: '[PC preview] unknow densityDPI',
6        densityPixels: '[PC preview] unknow densityPixels',
7        scaledDensity: '[PC preview] unknow scaledDensity',
8        xDPI: '[PC preview] unknow xDPI',
9        yDPI: '[PC preview] unknow yDPI',
10        width: '[PC preview] unknow width',
11        height: '[PC preview] unknow height',
12        alive: '[PC preview] unknow alive',
13        refreshRate: '[PC preview] unknow refreshRate',
14        id: '[PC preview] unknow id',
15        state: '[PC preview] unknow state',
16        rotation: '[PC preview] unknow rotation',
17        name: '[PC preview] unknow name'
18    }
19    const allDisplayMock = [{
20        densityDPI: '[PC preview] unknow densityDPI',
21        densityPixels: '[PC preview] unknow densityPixels',
22        scaledDensity: '[PC preview] unknow scaledDensity',
23        xDPI: '[PC preview] unknow xDPI',
24        yDPI: '[PC preview] unknow yDPI',
25        width: '[PC preview] unknow width',
26        height: '[PC preview] unknow height',
27        alive: '[PC preview] unknow alive',
28        refreshRate: '[PC preview] unknow refreshRate',
29        id: '[PC preview] unknow id',
30        state: '[PC preview] unknow state',
31        rotation: '[PC preview] unknow rotation',
32        name: '[PC preview] unknow name'
33    }]
34    global.systemplugin.display = {
35        getDefaultDisplay: function (...args) {
36            console.warn("display.getDefaultDisplay interface mocked in the Previewer. How this interface works on the Previewer" +
37                " may be different from that on a real device.")
38            const len = args.length
39            if (typeof args[len - 1] === 'function') {
40                args[len - 1].call(this, paramMock.businessErrorMock, displayMock)
41            } else {
42                return new Promise((resolve, reject) => {
43                    resolve(displayMock)
44                })
45            }
46        },
47        getAllDisplay: function (...args) {
48            console.warn("display.getAllDisplay interface mocked in the Previewer. How this interface works on the Previewer" +
49                " may be different from that on a real device.")
50            const len = args.length
51            if (typeof args[len - 1] === 'function') {
52                args[len - 1].call(this, paramMock.businessErrorMock, allDisplayMock)
53            } else {
54                return new Promise((resolve, reject) => {
55                    resolve(allDisplayMock)
56                })
57            }
58        },
59        on: function (...args) {
60            console.warn("display.on interface mocked in the Previewer. How this interface works on the Previewer may be" +
61                " different from that on a real device.")
62            const len = args.length
63            args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock)
64        },
65        off: function (...args) {
66            console.warn("display.off interface mocked in the Previewer. How this interface works on the Previewer may be" +
67                " different from that on a real device.")
68            const len = args.length
69            args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock)
70        },
71    }
72}