From dbdb67561f6d4cb8aff51af101cc3e04326e0346 Mon Sep 17 00:00:00 2001 From: yangpeng85 Date: Mon, 27 Dec 2021 17:01:48 +0800 Subject: [PATCH] add napi mock for settingsdata link https://gitee.com/openharmony/applications_settings/issues/I4MBU6 Signed-off-by: yangpeng85 --- runtime/main/extend/systemplugin/index.js | 2 - .../main/extend/systemplugin/napi/index.js | 3 + .../main/extend/systemplugin/napi/settings.js | 22 ++++++ runtime/main/extend/systemplugin/settings.js | 69 ------------------- 4 files changed, 25 insertions(+), 71 deletions(-) create mode 100644 runtime/main/extend/systemplugin/napi/settings.js delete mode 100644 runtime/main/extend/systemplugin/settings.js diff --git a/runtime/main/extend/systemplugin/index.js b/runtime/main/extend/systemplugin/index.js index c5775c5c..abadbf3e 100644 --- a/runtime/main/extend/systemplugin/index.js +++ b/runtime/main/extend/systemplugin/index.js @@ -73,7 +73,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' @@ -160,7 +159,6 @@ export function mockSystemPlugin() { mockStorageInfoManager() mockContact() mockScreenLock() - mockSettings() mockAppAbilityManager() mockAppAccount() mockOsAccount() diff --git a/runtime/main/extend/systemplugin/napi/index.js b/runtime/main/extend/systemplugin/napi/index.js index 6638257f..cce47c67 100644 --- a/runtime/main/extend/systemplugin/napi/index.js +++ b/runtime/main/extend/systemplugin/napi/index.js @@ -33,6 +33,7 @@ import { mockWifi } from './wifi' import { mockUsb } from './usb' import { mockBundle } from './bundle' import { mockInnerBundle } from './innerBundleManager' +import { mockSettings } from './settings' export function mockRequireNapiFun() { global.requireNapi = function (...args) { @@ -107,6 +108,8 @@ export function mockRequireNapiFun() { return mockBundle(); case "bundle.innerBundleManager": return mockInnerBundle(); + case "settings": + return mockSettings(); default: return global.requireNapiPreview(...args); } diff --git a/runtime/main/extend/systemplugin/napi/settings.js b/runtime/main/extend/systemplugin/napi/settings.js new file mode 100644 index 00000000..8c00c530 --- /dev/null +++ b/runtime/main/extend/systemplugin/napi/settings.js @@ -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; +} diff --git a/runtime/main/extend/systemplugin/settings.js b/runtime/main/extend/systemplugin/settings.js deleted file mode 100644 index a1e008d1..00000000 --- a/runtime/main/extend/systemplugin/settings.js +++ /dev/null @@ -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); - }) - } - }, - } -} \ No newline at end of file