!69 add napi mock for settingsdata

Merge pull request !69 from yangpeng85/master
This commit is contained in:
openharmony_ci
2022-01-05 09:38:27 +00:00
committed by Gitee
4 changed files with 25 additions and 71 deletions
@@ -72,7 +72,6 @@ import { mockDeviceManager } from './deviceManager'
import { mockScreenshot } from './screenshot'
import {mockContact} from './contact'
import {mockScreenLock} from "./screenLock"
import {mockSettings} from "./settings"
import { mockAppAccount} from './ohos/appAccount'
import { mockOsAccount} from './ohos/osAccount'
import { mockOhosGeolocation } from './ohos/geolocation'
@@ -158,7 +157,6 @@ export function mockSystemPlugin() {
mockStorageInfoManager()
mockContact()
mockScreenLock()
mockSettings()
mockAppAbilityManager()
mockAppAccount()
mockOsAccount()
@@ -38,6 +38,7 @@ import { mockInnerBundle } from './innerBundleManager'
import { mockUri } from './uri'
import { mockXml } from './xml'
import { mockStatfs } from './statfs'
import { mockSettings } from './settings'
export function mockRequireNapiFun() {
global.requireNapi = function (...args) {
@@ -122,6 +123,8 @@ export function mockRequireNapiFun() {
return mockXml();
case "statfs":
return mockStatfs();
case "settings":
return mockSettings();
default:
return global.requireNapiPreview(...args);
}
@@ -0,0 +1,22 @@
import { paramMock } from "../utils"
export function mockSettings() {
const settingsMock = {
getUri: function (...args) {
console.warn("settings.getUri interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.");
return paramMock.paramStringMock;
},
getValue: function (...args) {
console.warn("settings.getValue interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.");
return paramMock.paramStringMock;
},
setValue: function (...args) {
console.warn("settings.setValue interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.");
return paramMock.paramBooleanMock;
},
};
return settingsMock;
}
@@ -1,69 +0,0 @@
import { paramMock } from "./utils"
export function mockSettings () {
const mockInfo = {
URI : "[PC Preview] unknow string"
}
global.systemplugin.settings = {
getURI: function (...args) {
console.warn("settings.getURI interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
const len = args.length
if (typeof args[len - 1] === 'function') {
args[len - 1].call(this, paramMock.businessErrorMock, mockInfo)
} else {
return new Promise((resolve) => {
resolve(mockInfo);
})
}
},
getValue: function (...args) {
console.warn("settings.getValue interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
const len = args.length
if (typeof args[len - 1] === 'function') {
args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock)
} else {
return new Promise((resolve) => {
resolve(paramMock.paramStringMock);
})
}
},
setValue: function (...args) {
console.warn("settings.setValue interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
const len = args.length
if (typeof args[len - 1] === 'function') {
args[len - 1].call(this, paramMock.businessErrorMock)
} else {
return new Promise((resolve) => {
resolve();
})
}
},
enableAirplaneMode: function (...args) {
console.warn("settings.enableAirplaneMode interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
const len = args.length
if (typeof args[len - 1] === 'function') {
args[len - 1].call(this, paramMock.businessErrorMock)
} else {
return new Promise((resolve) => {
resolve();
})
}
},
canShowFloating: function (...args) {
console.warn("settings.canShowFloating interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
const len = args.length
if (typeof args[len - 1] === 'function') {
args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock)
} else {
return new Promise((resolve) => {
resolve(paramMock.paramBooleanMock);
})
}
},
}
}