refactor: 确立独立子工程架构 (backend, admin, mpuniapp) 并同步更新 AGENTS.md 规范
这个提交包含在:
@@ -0,0 +1,166 @@
|
||||
jest.setTimeout(30000)
|
||||
|
||||
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
|
||||
const isAndroid = platformInfo.startsWith('android')
|
||||
const isIos = platformInfo.startsWith('ios')
|
||||
const isHarmony = platformInfo.startsWith('harmony')
|
||||
const isApp = isAndroid || isIos || isHarmony
|
||||
const isWeb = platformInfo.startsWith('web')
|
||||
const isAppWebView = process.env.UNI_AUTOMATOR_APP_WEBVIEW == 'true'
|
||||
const isMP = platformInfo.startsWith('mp')
|
||||
|
||||
describe('API-toast', () => {
|
||||
if ( isMP) {
|
||||
it('skip', async () => {
|
||||
expect(1).toBe(1);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const PAGE_PATH = '/pages/API/toast/toast'
|
||||
let page;
|
||||
let deviceShotOptions = {}
|
||||
beforeAll(async () => {
|
||||
page = await program.reLaunch(PAGE_PATH)
|
||||
await page.waitFor("view");
|
||||
await page.waitFor(1000);
|
||||
const windowInfo = await program.callUniMethod('getWindowInfo');
|
||||
let topSafeArea = windowInfo.safeAreaInsets.top;
|
||||
if (isAppWebView) {
|
||||
if (isIos) {
|
||||
topSafeArea = 59
|
||||
if (platformInfo.includes('26')) {
|
||||
topSafeArea = 62
|
||||
}
|
||||
} else if (isAndroid) {
|
||||
topSafeArea = 24
|
||||
windowInfo.safeArea.bottom = 867
|
||||
if (platformInfo.startsWith('android 5')) {
|
||||
topSafeArea = 25
|
||||
}if (platformInfo.startsWith('android 6')) {
|
||||
windowInfo.safeArea.bottom = 592
|
||||
}if (platformInfo.startsWith('android 8')) {
|
||||
windowInfo.safeArea.bottom = 534
|
||||
} else if (platformInfo.startsWith('android 11')) {
|
||||
topSafeArea = 52
|
||||
} else if (platformInfo.startsWith('android 12')) {
|
||||
topSafeArea = 24
|
||||
windowInfo.safeArea.bottom = 716
|
||||
} else if (platformInfo.startsWith('android 13') || platformInfo.startsWith('android 15')) {
|
||||
topSafeArea = 49
|
||||
windowInfo.safeArea.bottom = 891
|
||||
} else if (platformInfo.startsWith('android 14')) {
|
||||
windowInfo.safeArea.bottom = 891
|
||||
}
|
||||
} else if (isHarmony) {
|
||||
topSafeArea = 39
|
||||
if (platformInfo.includes('nova_12')) {
|
||||
topSafeArea = 35
|
||||
}
|
||||
}
|
||||
}
|
||||
const top = topSafeArea + 44
|
||||
const bottom = Math.min(top + windowInfo.windowHeight, windowInfo.safeArea.bottom)
|
||||
const left = windowInfo.safeArea.left
|
||||
const right = windowInfo.safeArea.right - 10
|
||||
deviceShotOptions = {
|
||||
deviceShot: true,
|
||||
area: {
|
||||
x: left,
|
||||
y: top,
|
||||
width: right - left,
|
||||
height: bottom - top
|
||||
},
|
||||
}
|
||||
});
|
||||
|
||||
async function screenShot(imgName) {
|
||||
const image = await program.screenshot(deviceShotOptions);
|
||||
const options = {customSnapshotIdentifier() {
|
||||
return imgName
|
||||
}
|
||||
}
|
||||
if (!isAppWebView) {
|
||||
expect(image).toMatchImageSnapshot({ ...options,
|
||||
failureThresholdType: 'percent',
|
||||
failureThreshold: 0.002,
|
||||
});
|
||||
}
|
||||
expect(image).toSaveImageSnapshot(options)
|
||||
await page.waitFor(500);
|
||||
}
|
||||
|
||||
it("onload-toast-test", async () => {
|
||||
await screenShot('toast-onload')
|
||||
await page.waitFor(2000);
|
||||
})
|
||||
|
||||
it("icon-toast-test", async () => {
|
||||
const icons = await page.$$('.radio-icon')
|
||||
for (let i = 0; i < icons.length; i++) {
|
||||
await icons[i].tap()
|
||||
await page.waitFor(500);
|
||||
await page.callMethod('toast1Tap')
|
||||
await page.waitFor(500);
|
||||
const iconText = await icons[i].text()
|
||||
const iconValue = await icons[i].attribute('value')
|
||||
const isLoadingIcon = iconValue == 'loading' || iconText.includes('加载')
|
||||
await screenShot(`${iconText}-toast`)
|
||||
}
|
||||
})
|
||||
|
||||
it("icon=none-mask=true-toast-test", async () => {
|
||||
await page.setData({data:{maskSelect: true}})
|
||||
await page.callMethod('toast3Tap')
|
||||
await page.waitFor(300);
|
||||
await screenShot('icon=none-mask=true-toast-image')
|
||||
})
|
||||
|
||||
it("image-toast-test", async () => {
|
||||
await page.setData({data:{imageSelect: true}})
|
||||
await page.waitFor(300);
|
||||
await page.callMethod('toast1Tap')
|
||||
await page.waitFor(500);
|
||||
await screenShot('toast-image')
|
||||
})
|
||||
|
||||
it("duration-toast-test", async () => {
|
||||
await page.setData({data:{intervalSelect: 4000}})
|
||||
await page.callMethod('toast1Tap')
|
||||
await page.waitFor(2000);
|
||||
await screenShot('toast-duration-2000')
|
||||
await page.waitFor(1000);
|
||||
await page.callMethod('hideToast')
|
||||
await page.waitFor(300);
|
||||
await screenShot('toast-duration-end')
|
||||
})
|
||||
|
||||
if(isWeb){
|
||||
return
|
||||
}
|
||||
|
||||
it("position-toast-test", async () => {
|
||||
if (isIos) {
|
||||
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
|
||||
if (
|
||||
platformInfo.indexOf('14.5') != -1 ||
|
||||
platformInfo.indexOf('13.7') != -1 ||
|
||||
platformInfo.indexOf('12.4') != -1
|
||||
) {
|
||||
expect(1).toBe(1)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
const positions = await page.$$('.radio-position')
|
||||
for (let i = 0;i < positions.length;i++) {
|
||||
// 等待上一个 toast 消失
|
||||
await page.waitFor(2000);
|
||||
await positions[i].tap()
|
||||
const positionsText = await positions[i].attribute('value')
|
||||
await page.callMethod('toast2Tap')
|
||||
await page.waitFor(500);
|
||||
await screenShot(`toast-position-${positionsText}`)
|
||||
}
|
||||
})
|
||||
});
|
||||
218
mpuniapp/pages/API/toast/toast.uvue
普通文件
218
mpuniapp/pages/API/toast/toast.uvue
普通文件
@@ -0,0 +1,218 @@
|
||||
<template>
|
||||
<!-- #ifdef APP -->
|
||||
<scroll-view direction="vertical" style="flex:1">
|
||||
<!-- #endif -->
|
||||
<page-head :title="data.title"></page-head>
|
||||
<view class="uni-padding-wrap">
|
||||
<view class="uni-padding-wrap">
|
||||
<text class="uni-title-text uni-common-mb">设置icon</text>
|
||||
</view>
|
||||
<view class="uni-list uni-common-pl">
|
||||
<radio-group @change="radioChangeIcon">
|
||||
<radio class="uni-list-cell uni-list-cell-pd radio-icon" v-for="(icon, index) in data.icon_enum" :key="icon.value"
|
||||
:class="index < data.icon_enum.length - 1 ? 'uni-list-cell-line' : ''" :value="icon.value"
|
||||
:checked="index === data.icon_current">{{icon.name}}</radio>
|
||||
</radio-group>
|
||||
</view>
|
||||
<view class="uni-list-cell uni-list-cell-padding">
|
||||
<view class="uni-list-cell-db">是否显示自定义图标</view>
|
||||
<switch :checked="data.imageSelect" @change="change_image_boolean" />
|
||||
</view>
|
||||
<view class="uni-list-cell uni-list-cell-padding">
|
||||
<view class="uni-list-cell-db">是否显示透明蒙层-屏蔽点击事件</view>
|
||||
<switch :checked="data.maskSelect" @change="change_mask_boolean" />
|
||||
</view>
|
||||
<view class="uni-title uni-list-cell-padding">提示的延迟时间,默认:1500(单位毫秒)</view>
|
||||
<view class="uni-list-cell-padding">
|
||||
<slider @change="sliderChange" foreColor="#007AFF" :value="data.intervalSelect" :min="1500" :max="5000"
|
||||
:show-value="true" />
|
||||
</view>
|
||||
<view class="uni-btn-v">
|
||||
<button type="default" @tap="toast1Tap" id="btn-toast-default">点击弹出toast</button>
|
||||
<button type="default" @tap="hideToast" id="btn-toast-hide">点击隐藏toast</button>
|
||||
</view>
|
||||
<!-- #ifdef APP -->
|
||||
<view class="uni-padding-wrap uni-common-mt">
|
||||
<text class="uni-title-text uni-common-mb"> 设置position,仅App生效 </text>
|
||||
</view>
|
||||
<view class="uni-list uni-common-pl">
|
||||
<radio-group @change="radioChangePosition">
|
||||
<radio class="uni-list-cell uni-list-cell-pd radio-position" v-for="(position, index) in data.position_enum"
|
||||
:key="position.value" :class="index < data.position_enum.length - 1 ? 'uni-list-cell-line' : ''"
|
||||
:value="position.value" :checked="index === data.position_current">{{position.name}}</radio>
|
||||
</radio-group>
|
||||
</view>
|
||||
<button class="uni-btn uni-common-mb" type="default" @tap="toast2Tap">点击弹出设置position的toast</button>
|
||||
<!-- #endif -->
|
||||
<text>{{data.exeRet}}</text>
|
||||
</view>
|
||||
<!-- #ifdef APP -->
|
||||
</scroll-view>
|
||||
<!-- #endif -->
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
type IconItemType = {
|
||||
value : "success" | "error" | "fail" | "exception" | "loading" | "none";
|
||||
name : string
|
||||
}
|
||||
type PositionItemType = {
|
||||
value : "top" | "center" | "bottom";
|
||||
name : string
|
||||
}
|
||||
|
||||
type DataType = {
|
||||
title: string;
|
||||
exeRet: string;
|
||||
imageSelect: boolean;
|
||||
maskSelect: boolean;
|
||||
intervalSelect: number;
|
||||
position_current: number;
|
||||
position_enum: PositionItemType[];
|
||||
icon_current: number;
|
||||
icon_enum: IconItemType[];
|
||||
}
|
||||
|
||||
// 使用reactive包装数据,避免ref数据在自动化测试中无法获取
|
||||
const data = reactive({
|
||||
title: 'toast',
|
||||
exeRet: '',
|
||||
imageSelect: false,
|
||||
maskSelect: false,
|
||||
intervalSelect: 1500,
|
||||
position_current: 0,
|
||||
position_enum: [
|
||||
{ "value": "top", "name": "top: 居上显示(Android 暂不支持)" },
|
||||
{ "value": "center", "name": "center: 居中显示(Android 暂不支持)" },
|
||||
{ "value": "bottom", "name": "bottom: 居底显示" },
|
||||
],
|
||||
icon_current: 0,
|
||||
icon_enum: [
|
||||
{
|
||||
value: 'success',
|
||||
name: '显示成功图标',
|
||||
},
|
||||
{
|
||||
value: 'error',
|
||||
name: '显示错误图标',
|
||||
},
|
||||
{
|
||||
value: 'loading',
|
||||
name: '显示加载图标',
|
||||
},
|
||||
{
|
||||
value: 'none',
|
||||
name: '不显示图标',
|
||||
},
|
||||
],
|
||||
} as DataType)
|
||||
|
||||
onMounted(() => {
|
||||
uni.showToast({
|
||||
title: 'onMounted 调用示例,3秒后消失',
|
||||
duration: 3000
|
||||
})
|
||||
setTimeout(function () {
|
||||
uni.hideToast()
|
||||
}, 3000);
|
||||
})
|
||||
|
||||
//自动化测试例专用
|
||||
const jest_getWindowInfo = () : GetWindowInfoResult => {
|
||||
return uni.getWindowInfo();
|
||||
}
|
||||
|
||||
const radioChangeIcon = (e : UniRadioGroupChangeEvent) => {
|
||||
for (let i = 0; i < data.icon_enum.length; i++) {
|
||||
if (data.icon_enum[i].value === e.detail.value) {
|
||||
data.icon_current = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const change_image_boolean = (e : UniSwitchChangeEvent) => {
|
||||
data.imageSelect = e.detail.value
|
||||
}
|
||||
|
||||
const change_mask_boolean = (e : UniSwitchChangeEvent) => {
|
||||
data.maskSelect = e.detail.value
|
||||
}
|
||||
|
||||
const sliderChange = (e : UniSliderChangeEvent) => {
|
||||
data.intervalSelect = e.detail.value
|
||||
}
|
||||
|
||||
const radioChangePosition = (e : UniRadioGroupChangeEvent) => {
|
||||
for (let i = 0; i < data.position_enum.length; i++) {
|
||||
if (data.position_enum[i].value === e.detail.value) {
|
||||
data.position_current = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const toast1Tap = () => {
|
||||
uni.showToast({
|
||||
title: "默认",
|
||||
icon: data.icon_enum[data.icon_current].value,
|
||||
duration: data.intervalSelect,
|
||||
image: data.imageSelect ? "/static/test-image/logo.png" : null,
|
||||
mask: data.maskSelect,
|
||||
success: (res) => {
|
||||
// console.log('success:',res)
|
||||
data.exeRet = "success:" + JSON.stringify(res)
|
||||
},
|
||||
fail: (res) => {
|
||||
data.exeRet = "fail:" + JSON.stringify(res)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
const toast3Tap = () => {
|
||||
uni.showToast({
|
||||
title: "默认",
|
||||
icon: 'none',
|
||||
duration: data.intervalSelect,
|
||||
image: data.imageSelect ? "/static/test-image/logo.png" : null,
|
||||
mask: data.maskSelect,
|
||||
success: (res) => {
|
||||
// console.log('success:',res)
|
||||
data.exeRet = "success:" + JSON.stringify(res)
|
||||
},
|
||||
fail: (res) => {
|
||||
data.exeRet = "fail:" + JSON.stringify(res)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// #ifdef APP
|
||||
const toast2Tap = () => {
|
||||
let positionValue = data.position_enum[data.position_current].value
|
||||
uni.showToast({
|
||||
title: "显示一段轻提示,position:" + positionValue,
|
||||
position: positionValue,
|
||||
success: (res) => {
|
||||
data.exeRet = "success:" + JSON.stringify(res)
|
||||
},
|
||||
fail: (res) => {
|
||||
data.exeRet = "fail:" + JSON.stringify(res)
|
||||
},
|
||||
})
|
||||
}
|
||||
// #endif
|
||||
|
||||
const hideToast = () => {
|
||||
uni.hideToast()
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
data,
|
||||
toast1Tap,
|
||||
toast3Tap,
|
||||
// #ifdef APP
|
||||
toast2Tap,
|
||||
// #endif
|
||||
hideToast
|
||||
})
|
||||
</script>
|
||||
在新工单中引用
屏蔽一个用户