提交 67a9abbc 编写于 作者: DCloud_iOS_XHY's avatar DCloud_iOS_XHY

添加 rich-text.test 示例,测试动态修改内容组件高度是否正确

上级 136171b1
const PAGE_PATH = '/pages/component/rich-text/rich-text'
describe('rich-text-test', () => {
// 先屏蔽 android 及 web 平台
if (process.env.uniTestPlatformInfo.startsWith('android') || process.env.uniTestPlatformInfo.startsWith('web')) {
it('other platform', () => {
expect(1).toBe(1)
})
return
}
let page
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor(1000);
})
it('richt-text-height', async () => {
let beforeValue = await page.data('richTextHeight')
await page.callMethod('changeText')
await page.waitFor(500)
await page.callMethod('changeText')
await page.waitFor(500)
let afterValue = await page.data('richTextHeight')
console.log('beforeValue:', beforeValue)
console.log('afterValue:', afterValue)
expect(beforeValue).toBe(afterValue)
})
})
......@@ -16,14 +16,48 @@
<text class="uni-subtitle-text">selectable</text>
</view>
<view class="text-box">
<rich-text :selectable="true"
nodes="<span>hello uni-app x!</span><br/><span>uni-app x,终极跨平台方案</span>"></rich-text>
<rich-text id="richtext" @click="changeText" style="border: 1px; border-style: solid; border-color: red;" :selectable="true"
:nodes="text"></rich-text>
</view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
text: "<span>hello uni-app x!</span><br/><span>uni-app x,终极跨平台方案</span>",
richTextHeight: 0,
richTextElement: null as UniElement | null
}
},
onReady() {
this.richTextElement = uni.getElementById('richtext') as UniElement
setTimeout(() => {
this.updateRichTextHeight()
}, 500)
},
methods: {
changeText() {
if (this.text === "<span>hello uni-app x!</span><br/><span>uni-app x,终极跨平台方案</span>") {
this.text = "<h1>hello uni-app x!</h1><br/><h2>uni-app x,终极跨平台方案</h2>"
} else {
this.text = "<span>hello uni-app x!</span><br/><span>uni-app x,终极跨平台方案</span>"
}
setTimeout(() => {
this.updateRichTextHeight()
}, 200)
},
updateRichTextHeight() {
if (this.richTextElement != null) {
const elRect = this.richTextElement!.getBoundingClientRect()
this.richTextHeight = elRect.height
console.log('richTextHeight:', this.richTextHeight)
}
}
}
}
</script>
<style>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册