From f822fb9682d93f4614ffc1667d77dbe819d04a1e Mon Sep 17 00:00:00 2001 From: zhangyushuai Date: Mon, 22 Aug 2022 09:44:28 +0000 Subject: [PATCH] add input and wallpaper API Signed-off-by: zhangyushuai --- .../src/main/ets/test/inputMethodJSUnit.ets | 141 +++++++++++++++--- .../entry/src/main/ets/test/wallpaperTest.ets | 49 +++++- 2 files changed, 170 insertions(+), 20 deletions(-) diff --git a/inputmethod/InputMethodTest_ets/entry/src/main/ets/test/inputMethodJSUnit.ets b/inputmethod/InputMethodTest_ets/entry/src/main/ets/test/inputMethodJSUnit.ets index 19e639635..358d696e5 100644 --- a/inputmethod/InputMethodTest_ets/entry/src/main/ets/test/inputMethodJSUnit.ets +++ b/inputmethod/InputMethodTest_ets/entry/src/main/ets/test/inputMethodJSUnit.ets @@ -23,7 +23,7 @@ export default function inputMethodJSUnit() { let inputMethodSetting = inputMethod.getInputMethodSetting(); console.info("inputmethoh_test_001 result:" + JSON.stringify(inputMethodSetting)); inputMethodSetting.listInputMethod((arr) => { - console.info("inputmethoh_test_001 listInputMethod result---" + JSON.stringify(arr)); + console.info("appInfoTest_input_2 listInputMethod result---" + JSON.stringify(arr)); expect(1==1).assertTrue(); }); done(); @@ -32,17 +32,19 @@ export default function inputMethodJSUnit() { it('inputmethoh_test_002', 0, async function (done) { let inputMethodSetting = inputMethod.getInputMethodSetting(); console.info("inputmethoh_test_002 result:" + JSON.stringify(inputMethodSetting)); - let promise = inputMethodSetting.listInputMethod(); - console.info("inputmethoh_test_002 listInputMethod result---" + JSON.stringify(promise)); - if (promise.length > 0){ - let obj = promise[0] - console.info("inputmethoh_test_002 listInputMethod obj---" + JSON.stringify(obj)); - expect(obj.packageName != null).assertTrue(); - expect(obj.methodId != null).assertTrue(); - }else{ - console.info("inputmethoh_test_002 listInputMethod is null"); - except().assertFail() - } + inputMethodSetting.listInputMethod().then(inputMethodProperty => { + if (inputMethodProperty.length > 0){ + let obj = inputMethodProperty[0] + console.info("inputmethoh_test_002 listInputMethod obj---" + JSON.stringify(obj)); + expect(obj.packageName != null).assertTrue(); + expect(obj.methodId != null).assertTrue(); + }else{ + console.info("inputmethoh_test_002 listInputMethod is null"); + expect().assertFail() + } + }).catch(err => { + console.info("inputmethoh_test_002 listInputMethod is err: " + JSON.stringify(err)); + }); done(); }); @@ -58,9 +60,13 @@ export default function inputMethodJSUnit() { it('inputmethoh_test_004', 0, async function (done) { let inputMethodSetting = inputMethod.getInputMethodSetting(); console.info("inputmethoh_test_004 result:" + JSON.stringify(inputMethodSetting)); - let promise = inputMethodSetting.displayOptionalInputMethod(); - console.info("inputmethoh_test_004 displayOptionalInputMethod result---" + JSON.stringify(promise)); - expect(promise).assertEqual(undefined) + inputMethodSetting.displayOptionalInputMethod().then(() => { + console.info("inputmethoh_test_004 displayOptionalInputMethod is called"); + expect(true).assertTrue() + }).catch(err => { + console.info("inputmethoh_test_004 displayOptionalInputMethod is err: " + JSON.stringify(err)); + expect().assertFail() + }); done(); }); @@ -76,9 +82,13 @@ export default function inputMethodJSUnit() { it('inputmethoh_test_006', 0, async function (done) { let inputMethodCtrl = inputMethod.getInputMethodController(); console.info("inputmethoh_test_006 result:" + JSON.stringify(inputMethodCtrl)); - let promise = inputMethodCtrl.stopInput(); - console.info("inputmethoh_test_006 inputMethodCtrl stopInput result---" + JSON.stringify(promise)); - expect(promise).assertEqual(true) + inputMethodCtrl.stopInput().then(data => { + console.info("inputmethoh_test_006 stopInput result----" + data); + expect(data == true).assertTrue() + }).catch(err => { + console.info("inputmethoh_test_006 stopInput is err: " + JSON.stringify(err)); + expect().assertFail() + }); done(); }); @@ -96,6 +106,29 @@ export default function inputMethodJSUnit() { done(); }); + /* + * @tc.number inputmethod_test_switchInputMethod_001 + * @tc.name Test Indicates the input method which will replace the current one. + * @tc.desc Function test + * @tc.level 2 + */ + it('inputmethod_test_switchInputMethod_001', 0, async function (done) { + console.info("************* inputmethod_test_switchInputMethod_001 Test start*************"); + let inputMethodProperty = { + packageName:"com.example.kikakeyboard", + methodId:"ServiceExtAbility" + } + + inputMethod.switchInputMethod(inputMethodProperty).then(data => { + console.info("inputmethod_test_switchInputMethod_001 data:" + data) + expect(data == true).assertTrue(); + }).catch( err=> { + console.info("inputmethod_test_switchInputMethod_001 err:" + err) + }) + console.info("************* inputmethod_test_switchInputMethod_001 Test end*************"); + done(); + }); + /* * @tc.number inputmethod_test_switchInputMethod_002 * @tc.name Test Indicates the input method which will replace the current one. @@ -119,5 +152,77 @@ export default function inputMethodJSUnit() { console.info("************* inputmethod_test_switchInputMethod_002 Test end*************"); done(); }); + + /* + * @tc.number inputmethod_test_showSoftKeyboard_001 + * @tc.name Test Indicates the input method which will show softboard with calback. + * @tc.desc Function test + * @tc.level 2 + */ + it('inputmethod_test_showSoftKeyboard_001', 0, async function (done) { + let inputMethodCtrl = inputMethod.getInputMethodController() + inputMethodCtrl.showSoftKeyboard((data)=>{ + if(data == undefined){ + console.info("showSoftKeyboard callbace success" ); + }else{ + console.info('showSoftKeyboard callbace failed : ' + JSON.stringify(err)) + } + }); + console.info("************* inputmethod_test_showSoftKeyboard_001 Test end*************"); + done(); + }); + + /* + * @tc.number inputmethod_test_showSoftKeyboard_001 + * @tc.name Test Indicates the input method which will show softboard with Promise. + * @tc.desc Function test + * @tc.level 2 + */ + it('inputmethod_test_showSoftKeyboard_002', 0, async function (done) { + let inputMethodCtrl = inputMethod.getInputMethodController() + inputMethodCtrl.showSoftKeyboard().then((data) =>{ + console.info("showSoftKeyboard promise success" ); + }).catch((err) => { + console.info('showSoftKeyboard promise failed : ' + JSON.stringify(err)) + }) + console.info("************* inputmethod_test_showSoftKeyboard_002 Test end*************"); + done(); + }); + + /* + * @tc.number inputmethod_test_showSoftKeyboard_001 + * @tc.name Test Indicates the input method which will hide softboard with calback. + * @tc.desc Function test + * @tc.level 2 + */ + it('inputmethod_test_hideSoftKeyboard_001', 0, async function (done) { + let inputMethodCtrl = inputMethod.getInputMethodController() + inputMethodCtrl.hideSoftKeyboard((data)=>{ + if(data == undefined){ + console.info("hideSoftKeyboard callbace success" ); + }else{ + console.info('hideSoftKeyboard callbace failed : ' + JSON.stringify(err)) + } + }); + console.info("************* inputmethod_test_hideSoftKeyboard_001 Test end*************"); + done(); + }); + + /* + * @tc.number inputmethod_test_showSoftKeyboard_001 + * @tc.name Test Indicates the input method which will hide softboard with Promise. + * @tc.desc Function test + * @tc.level 2 + */ + it('inputmethod_test_hideSoftKeyboard_002', 0, async function (done) { + let inputMethodCtrl = inputMethod.getInputMethodController() + inputMethodCtrl.hideSoftKeyboard().then((data) =>{ + console.info("hideSoftKeyboard promise success" ); + }).catch((err) => { + console.info('hideSoftKeyboard promise failed : ' + JSON.stringify(err)) + }) + console.info("************* inputmethod_test_hideSoftKeyboard_002 Test end*************"); + done(); + }); }) } diff --git a/theme/wallpaper_ets/entry/src/main/ets/test/wallpaperTest.ets b/theme/wallpaper_ets/entry/src/main/ets/test/wallpaperTest.ets index 12120ba79..a7a0faa44 100755 --- a/theme/wallpaper_ets/entry/src/main/ets/test/wallpaperTest.ets +++ b/theme/wallpaper_ets/entry/src/main/ets/test/wallpaperTest.ets @@ -73,15 +73,20 @@ export default function wallpaperJSUnit() { * @tc.level 0 */ it('testGetColorsCallbackSystem101', 0, async function (done) { + await wallpaper.getColors(WALLPAPER_SYSTEM, function (err, data) { + let RgbaColor = { + red:data[0][0], + green:data[0][1], + blue:data[0][2], + alpha:data[0][3] + } console.info('wallpaperXTS ===> testGetColorsCallbackSystem err : ' + JSON.stringify(err)); console.info('wallpaperXTS ===> testGetColorsCallbackSystem data : ' + JSON.stringify(data)); console.info('wallpaperXTS ===> testGetColorsCallbackSystem data : ' + data[0][0]); console.info('wallpaperXTS ===> testGetColorsCallbackSystem data : ' + data[0][1]); console.info('wallpaperXTS ===> testGetColorsCallbackSystem data : ' + data[0][2]); console.info('wallpaperXTS ===> testGetColorsCallbackSystem data : ' + data[0][3]); - - if (err) { expect(null).assertFail(); } @@ -610,5 +615,45 @@ export default function wallpaperJSUnit() { }) done(); }) + + /* + * @tc.number testGetFileCallback101 + * @tc.name Obtains a file of the wallpaper of the specified type. + * @tc.desc Function test + * @tc.level 0 + */ + it('testGetFileCallback101', 0, async function (done) { + wallpaper.getFile(WALLPAPER_SYSTEM, (error, data) => { + if (error) { + console.error("callback failed to getFile because: " + JSON.stringify(error)); + expect().assertFail() + }else{ + expect(typeof data == "number").assertTrue(); + expect(!isNaN(data)).assertTrue(); + console.info("callback success to getFile: " + JSON.stringify(data)); + done() + } + }); + done(); + }) + + /* + * @tc.number testGetFilePromise101 + * @tc.name Obtains a file of the wallpaper of the specified type. + * @tc.desc Function test + * @tc.level 0 + */ + it('testGetFilePromise101', 0, async function (done) { + wallpaper.getFile(WALLPAPER_SYSTEM).then((data) => { + expect(typeof data == "number").assertTrue(); + expect(!isNaN(data)).assertTrue(); + console.info("promise success to getFile: " + JSON.stringify(data)); + done() + }).catch((error) => { + console.error("promise failed to getFile because: " + JSON.stringify(error)); + expect().assertFail() + }); + done(); + }) }) } -- GitLab