文件
OmniCard/mpuniapp/pages/API/uni-push/uni-push.test.js

80 行
2.7 KiB
JavaScript

此文件含有模棱两可的 Unicode 字符

此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。

const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isWeb = platformInfo.startsWith('web')
const isMP = platformInfo.startsWith('mp')
const isHarmony = platformInfo.startsWith('harmony')
describe('uni-push', () => {
let page;
beforeAll(async () => {
page = await program.reLaunch('/pages/API/uni-push/uni-push')
await page.waitFor('view');
await page.callMethod('updateAutoTest', true)
await page.data('autoTest')
});
// 获取cid | getPushClientId:值
it('getPushClientId', async () => {
let jestResult = await page.data('jestResult')
if (isHarmony && !jestResult.hasGetuiAppId){
console.log('getPushClientId已跳过。鸿蒙端 Push 测试依赖配置:harmony-configs/entry/src/main/module.json5 → metadata → GETUI_APPID')
return
}
await page.callMethod('handleGetClientId')
await page.waitFor(2000);
jestResult = await page.data('jestResult')
expect(jestResult.clientId.length).toBe(32);
});
if(isWeb || isMP){
// app端需要自定义基座
// 发送通知消息 | sendPushMessage:成功提示
it('sendPushMessage', async () => {
await page.callMethod('handleSendPushMessage')
await page.waitFor(1000);
expect(await page.data('jestResult.sendPushMessageRes')).toBe(0);
});
}
// 注册回调 | onPushMessage:成功
it('onPushMessage', async () => {
await page.callMethod('handleOnPushMessage')
await page.waitFor(1000);
expect(await page.data('isRegister.state')).toBe(true);
});
if(isWeb || isMP){
// 发送通知消息 | sendPushMessage:回调信息
it('sendPushMessage', async () => {
await page.callMethod('handleSendPushMessage')
await page.waitFor(1000);
expect(await page.data('jestResult.onPushMessageType')).toBe("receive");
const info = await page.data('jestResult.onPushMessageCallbackInfo')
// 使用 JSON.parse 将字符串转换回对象
const objCopy = JSON.parse(info);
expect(objCopy).toEqual({
"unipush_version": "2.0",
"payload": {
"data": "测试推送数据"
},
"title": "测试推送标题",
"content": "测试推送内容"
})
});
}
// 注销回调 | offPushMessage:注销成功
it('offPushMessage', async () => {
await page.callMethod('handleOffPushMessage')
await page.waitFor(1000);
expect(await page.data('isRegister.state')).toBe(false);
});
if(isWeb || isMP){
// 发送通知消息 | sendPushMessage:成功提示
it('sendPushMessage', async () => {
await page.callMethod('handleSendPushMessage')
await page.waitFor(300);
expect(await page.data('jestResult.sendPushMessageRes')).toBe(0);
});
}
});