• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1export function mockNetwork() {
2  const data = {
3    metered: true,
4    type: "5g"
5  }
6  global.systemplugin.network = {
7    getType: function (...args) {
8      console.warn("network.getType interface mocked in the Previewer. How this interface works on the Previewer may" +
9        " be different from that on a real device.")
10      args[0].success(data)
11      args[0].complete()
12    },
13    subscribe: function (...args) {
14      console.warn("network.subscribe interface mocked in the Previewer. How this interface works on the Previewer" +
15        " may be different from that on a real device.")
16      if (!this.unsubscribeNetwork) {
17        this.unsubscribeNetwork = setInterval(() => {
18          args[0].success(data)
19        }, 3000)
20      }
21    },
22    unsubscribe: function () {
23      console.warn("network.unsubscribe interface mocked in the Previewer. How this interface works on the Previewer" +
24        " may be different from that on a real device.")
25      clearInterval(this.unsubscribeNetwork)
26      delete this.unsubscribeNetwork
27    }
28  }
29}