refactor: 确立独立子工程架构 (backend, admin, mpuniapp) 并同步更新 AGENTS.md 规范
这个提交包含在:
@@ -0,0 +1,26 @@
|
||||
const PAGE_PATH = '/pages/API/get-element-by-id/get-element-by-id-get-bounding-client-rect'
|
||||
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
|
||||
const isMP = platformInfo.startsWith('mp')
|
||||
describe('transform-DOMRect', () => {
|
||||
if (isMP) {
|
||||
it('skip mp', () => {
|
||||
expect(1).toBe(1)
|
||||
})
|
||||
return
|
||||
}
|
||||
let page
|
||||
beforeAll(async () => {
|
||||
page = await program.reLaunch(PAGE_PATH)
|
||||
await page.waitFor(500);
|
||||
})
|
||||
|
||||
it('x, y, width, height', async () => {
|
||||
const node1Info = await page.callMethod('getNode1Info')
|
||||
const node2Info = await page.callMethod('getNode2Info')
|
||||
|
||||
expect(node1Info.x).toBeLessThan(node2Info.x)
|
||||
expect(node1Info.y).toBeGreaterThan(node2Info.y)
|
||||
expect(node1Info.width).toBeGreaterThan(node2Info.width)
|
||||
expect(node1Info.height).toBeGreaterThan(node2Info.height)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,72 @@
|
||||
<template>
|
||||
<view class="container">
|
||||
<view id="node1" class="node node1">
|
||||
这里是 transfrom 之后的节点
|
||||
</view>
|
||||
|
||||
<view id="node2" class="node node2">
|
||||
这里是没有 transfrom 的节点
|
||||
</view>
|
||||
|
||||
<button @click="getNode1Info">
|
||||
getNode1Info
|
||||
</button>
|
||||
|
||||
<button @click="getNode2Info">
|
||||
getNode2Info
|
||||
</button>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
function getNode1Info() : DOMRect {
|
||||
const info = uni.getElementById('node1')?.getBoundingClientRect()
|
||||
if (info != null) {
|
||||
// console.log('info: ', info.toJSON());
|
||||
return info
|
||||
}
|
||||
return {
|
||||
x: 0,
|
||||
y: 0,
|
||||
height: 0,
|
||||
width: 0
|
||||
} as DOMRect
|
||||
}
|
||||
function getNode2Info() : DOMRect {
|
||||
|
||||
const info = uni.getElementById('node2')?.getBoundingClientRect()
|
||||
if (info != null) {
|
||||
// console.log('info: ', info.toJSON());
|
||||
return info
|
||||
}
|
||||
return {
|
||||
x: 0,
|
||||
y: 0,
|
||||
height: 0,
|
||||
width: 0
|
||||
} as DOMRect
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
getNode1Info,
|
||||
getNode2Info
|
||||
})
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.container {
|
||||
flex: 1;
|
||||
background-color: #f8f8f8;
|
||||
}
|
||||
|
||||
.node {
|
||||
margin: 20rpx;
|
||||
background-color: white;
|
||||
padding: 40rpx;
|
||||
border-radius: 10rpx;
|
||||
}
|
||||
|
||||
.node1 {
|
||||
transform: translateY(500px) scale(1.5);
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,26 @@
|
||||
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
|
||||
const isMP = platformInfo.startsWith('mp')
|
||||
|
||||
const PAGE_PATH = "/pages/API/get-element-by-id/get-element-by-id-multiple-root-node";
|
||||
let page;
|
||||
|
||||
describe("getElementByIdForMultipleRootNode", () => {
|
||||
beforeAll(async () => {
|
||||
page = await program.reLaunch(PAGE_PATH);
|
||||
await page.waitFor('view');
|
||||
});
|
||||
it("getElementByNotExistId", async () => {
|
||||
const res = await page.callMethod("getElementByNotExistId");
|
||||
expect(res).toBe(null);
|
||||
});
|
||||
it("changeStyle", async () => {
|
||||
if (!isMP) {
|
||||
await page.callMethod("changePageHeadBackgroundColor");
|
||||
}
|
||||
await page.callMethod("changeTextColor");
|
||||
await page.callMethod("changeViewStyle");
|
||||
await page.waitFor(500);
|
||||
const image = await program.screenshot({fullPage: true});
|
||||
expect(image).toSaveImageSnapshot();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,48 @@
|
||||
<template>
|
||||
<page-head id="page-head" title="getElementById-multiple-root-node"></page-head>
|
||||
<view class="uni-padding-wrap">
|
||||
<text id="text">this is text</text>
|
||||
<view id="view" class="uni-common-mt" style="border: 1px solid red">this is view</view>
|
||||
<button class="uni-btn" @click="changePageHeadBackgroundColor">
|
||||
修改 page-head 背景色
|
||||
</button>
|
||||
<button class="uni-btn" @click="changeTextColor">修改 text 字体颜色</button>
|
||||
<button class="uni-btn" @click="changeViewStyle">
|
||||
修改 view 宽高及背景色
|
||||
</button>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
|
||||
// Methods
|
||||
function getElementByNotExistId() : Element | null {
|
||||
return uni.getElementById('not-exist-id')
|
||||
}
|
||||
|
||||
function changePageHeadBackgroundColor() {
|
||||
const pageHead = uni.getElementById('page-head')!
|
||||
pageHead.style.setProperty('background-color', 'red')
|
||||
}
|
||||
|
||||
function changeTextColor() {
|
||||
const text = uni.getElementById('text')!
|
||||
text.style.setProperty('color', 'red')
|
||||
}
|
||||
|
||||
function changeViewStyle() {
|
||||
const view = uni.getElementById<UniViewElement>('view')
|
||||
if (view !== null) {
|
||||
view.style.setProperty('width', '90%')
|
||||
view.style.setProperty('height', '50px')
|
||||
view.style.setProperty('background-color', '#007AFF')
|
||||
}
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
getElementByNotExistId,
|
||||
changePageHeadBackgroundColor,
|
||||
changeTextColor,
|
||||
changeViewStyle
|
||||
})
|
||||
</script>
|
||||
@@ -0,0 +1,37 @@
|
||||
describe("getElementById", () => {
|
||||
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
|
||||
const isMP = platformInfo.startsWith('mp')
|
||||
const PAGE_PATH = "/pages/API/get-element-by-id/get-element-by-id";
|
||||
let page;
|
||||
beforeAll(async () => {
|
||||
page = await program.reLaunch(PAGE_PATH);
|
||||
await page.waitFor('view');
|
||||
});
|
||||
it("getElementByNotExistId", async () => {
|
||||
const res = await page.callMethod("getElementByNotExistId");
|
||||
expect(res).toBe(null);
|
||||
});
|
||||
it("changeStyle", async () => {
|
||||
if (!isMP) {
|
||||
await page.callMethod("changePageHeadBackgroundColor");
|
||||
}
|
||||
await page.callMethod("changeTextColor");
|
||||
await page.callMethod("changeViewStyle");
|
||||
await page.callMethod("changeImageStyle");
|
||||
await page.callMethod("changeScrollViewStyle");
|
||||
await page.waitFor(500);
|
||||
const image = await program.screenshot({fullPage: true});
|
||||
expect(image).toSaveImageSnapshot();
|
||||
});
|
||||
|
||||
if(isMP) {
|
||||
return
|
||||
}
|
||||
/**
|
||||
* 检测元素offsetLeft属性值域
|
||||
*/
|
||||
it("checkElementOffsetLeft", async() => {
|
||||
const res = await page.callMethod("getTextOffsetLeft");
|
||||
expect(res).toBe(0);
|
||||
})
|
||||
});
|
||||
@@ -0,0 +1,94 @@
|
||||
<template>
|
||||
<page-head id="page-head" title="getElementById"></page-head>
|
||||
<view style="margin: 0 15px;">
|
||||
<text id="text">this is text</text>
|
||||
<view id="view" class="uni-common-mt" style="border: 1px solid red">this is view</view>
|
||||
<image id="image" class="uni-common-mt" src="/static/test-image/logo.png" style="width: 50px; height: 50px;"></image>
|
||||
<scroll-view id="scroll-view" class="uni-common-mt" style="width: 100px; height: 50px; background-color: #f0f0f0; border: 1px solid #ccc;">
|
||||
<text>this is scroll-view</text>
|
||||
</scroll-view>
|
||||
<button class="uni-btn" @click="changePageHeadBackgroundColor">
|
||||
修改 page-head 背景色
|
||||
</button>
|
||||
<button class="uni-btn" @click="changeTextColor">
|
||||
修改 text 字体颜色
|
||||
</button>
|
||||
<button class="uni-btn" @click="changeViewStyle">
|
||||
修改 view 宽高及背景色
|
||||
</button>
|
||||
<button class="uni-btn" @click="changeImageStyle">
|
||||
修改 image 宽高及边框
|
||||
</button>
|
||||
<button class="uni-btn" @click="changeScrollViewStyle">
|
||||
修改 scroll-view 宽高及背景色
|
||||
</button>
|
||||
<button class="uni-btn" @click="goMultipleRootNode">
|
||||
跳转多根节点示例
|
||||
</button>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
const getElementByNotExistId = (): Element | null => {
|
||||
return uni.getElementById('not-exist-id')
|
||||
}
|
||||
|
||||
const changePageHeadBackgroundColor = () => {
|
||||
const pageHead = uni.getElementById('page-head')!
|
||||
pageHead.style.setProperty('background-color', 'red')
|
||||
}
|
||||
|
||||
const changeTextColor = () => {
|
||||
const text = uni.getElementById('text')!
|
||||
text.style.setProperty('color', 'red')
|
||||
}
|
||||
|
||||
const changeViewStyle = () => {
|
||||
const view = uni.getElementById<UniViewElement>('view')
|
||||
if (view !== null) {
|
||||
view.style.setProperty('width', '90%')
|
||||
view.style.setProperty('height', '50px')
|
||||
view.style.setProperty('background-color', '#007AFF')
|
||||
}
|
||||
}
|
||||
|
||||
const changeImageStyle = () => {
|
||||
const image = uni.getElementById<UniImageElement>('image')
|
||||
if (image !== null) {
|
||||
image.style.setProperty('width', '100px')
|
||||
image.style.setProperty('height', '100px')
|
||||
image.style.setProperty('border', '3px solid blue')
|
||||
image.style.setProperty('border-radius', '10px')
|
||||
}
|
||||
}
|
||||
|
||||
const changeScrollViewStyle = () => {
|
||||
const scrollView = uni.getElementById<UniElement>('scroll-view')
|
||||
if (scrollView !== null) {
|
||||
scrollView.style.setProperty('width', '200px')
|
||||
scrollView.style.setProperty('height', '60px')
|
||||
scrollView.style.setProperty('background-color', '#e3f2fd')
|
||||
scrollView.style.setProperty('border', '2px solid #007AFF')
|
||||
}
|
||||
}
|
||||
|
||||
const goMultipleRootNode = () => {
|
||||
uni.navigateTo({ url: '/pages/API/get-element-by-id/get-element-by-id-multiple-root-node' })
|
||||
}
|
||||
|
||||
//自动化测试获取text元素的offsetLeft属性值
|
||||
const getTextOffsetLeft = (): number => {
|
||||
const text = uni.getElementById('text')!
|
||||
return text.offsetLeft
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
getElementByNotExistId,
|
||||
changePageHeadBackgroundColor,
|
||||
changeTextColor,
|
||||
changeViewStyle,
|
||||
changeImageStyle,
|
||||
changeScrollViewStyle,
|
||||
getTextOffsetLeft
|
||||
})
|
||||
</script>
|
||||
在新工单中引用
屏蔽一个用户