Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
775ef9eb
H
hello uni-app x
项目概览
DCloud
/
hello uni-app x
通知
5992
Star
90
Fork
162
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
18
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello uni-app x
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
18
Issue
18
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
775ef9eb
编写于
5月 22, 2024
作者:
Anne_LXM
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
新增web端editor测试例
上级
b27bbe7c
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
189 addition
and
45 deletion
+189
-45
pages/component/editor/editor.test.js
pages/component/editor/editor.test.js
+90
-0
pages/component/editor/editor.uvue
pages/component/editor/editor.uvue
+99
-45
未找到文件。
pages/component/editor/editor.test.js
0 → 100644
浏览文件 @
775ef9eb
// uni-app自动化测试教程: uni-app自动化测试教程: https://uniapp.dcloud.net.cn/worktile/auto/hbuilderx-extension/
jest
.
setTimeout
(
60000
);
describe
(
'
editor.uvue
'
,
()
=>
{
if
(
!
process
.
env
.
uniTestPlatformInfo
.
startsWith
(
'
web
'
))
{
it
(
'
app
'
,
()
=>
{
expect
(
1
).
toBe
(
1
)
})
return
}
let
page
,
editor
,
options
=
[];
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
"
/pages/component/editor/editor
"
);
await
page
.
waitFor
(
'
view
'
);
editor
=
await
page
.
$
(
'
#editor
'
);
await
page
.
waitFor
(
3000
);
await
page
.
setData
({
autoTest
:
true
})
});
it
(
'
editor-wrapper
'
,
async
()
=>
{
expect
(
await
editor
.
attribute
(
"
placeholder
"
)).
toBe
(
"
开始输入...
"
)
expect
(
await
editor
.
attribute
(
"
read-only
"
)).
toBe
(
"
false
"
)
});
it
(
'
editor-toolbar
'
,
async
()
=>
{
const
iconfontsEl
=
await
page
.
$$
(
'
.iconfont
'
);
for
(
var
i
=
0
;
i
<
iconfontsEl
.
length
-
7
;
i
++
)
{
await
iconfontsEl
[
i
].
tap
()
// await page.waitFor(500)
const
getFormats
=
await
page
.
data
(
'
formats
'
)
const
name
=
await
iconfontsEl
[
i
].
attribute
(
'
data-name
'
)
options
.
push
({
insert
:
'
文本内容
'
+
name
,
attributes
:
getFormats
})
await
page
.
callMethod
(
'
setContents
'
,
options
)
await
page
.
setData
({
formats
:
{}
})
await
iconfontsEl
[
i
].
tap
()
}
});
it
(
'
editor-screenshot
'
,
async
()
=>
{
expect
(
await
program
.
screenshot
()).
toSaveImageSnapshot
();
await
page
.
waitFor
(
500
);
})
it
(
'
clear
'
,
async
()
=>
{
await
page
.
callMethod
(
'
clear
'
)
await
page
.
waitFor
(
500
)
expect
(
await
editor
.
attribute
(
"
placeholder
"
)).
toBe
(
"
开始输入...
"
)
})
it
(
'
undo-redo
'
,
async
()
=>
{
await
page
.
callMethod
(
'
insertDate
'
)
await
page
.
callMethod
(
'
insertDivider
'
)
await
page
.
waitFor
(
500
)
await
page
.
callMethod
(
'
undo
'
)
await
page
.
waitFor
(
500
)
expect
(
await
page
.
data
(
'
undoTest
'
)).
toBe
(
true
)
await
page
.
callMethod
(
'
redo
'
)
await
page
.
waitFor
(
500
)
expect
(
await
page
.
data
(
'
redoTest
'
)).
toBe
(
true
)
})
it
(
'
insertImage
'
,
async
()
=>
{
await
page
.
callMethod
(
'
insertImage
'
,
'
https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/uni-app.png
'
)
await
page
.
waitFor
(
500
)
expect
(
await
program
.
screenshot
()).
toSaveImageSnapshot
();
})
it
(
'
removeFormat
'
,
async
()
=>
{
const
bgcolorEl
=
await
page
.
$
(
'
.icon-fontbgcolor
'
);
await
bgcolorEl
.
tap
()
await
page
.
waitFor
(
500
)
const
getFormats
=
await
page
.
data
(
'
formats
'
)
await
page
.
callMethod
(
'
setContents
'
,
[
{
insert
:
'
设置字体样式bgcolor
'
,
attributes
:
getFormats
}
])
await
page
.
waitFor
(
500
)
await
page
.
callMethod
(
'
removeFormat
'
)
await
page
.
waitFor
(
500
)
expect
(
await
page
.
data
(
'
removeFormatTest
'
)).
toBe
(
true
)
expect
(
await
page
.
data
(
'
formats
'
)).
toEqual
({})
})
});
pages/component/editor/editor.uvue
浏览文件 @
775ef9eb
...
...
@@ -30,7 +30,7 @@
data-name="marginTop" data-value="20px"></view>
<view :class="formats.marginBottom ? 'ql-active' : ''" class="iconfont icon-723bianjiqi_duanhouju"
data-name="marginBottom" data-value="20px"></view>
<view class="iconfont icon-clearedformat" @tap="removeFormat"></view>
<view :class="formats.fontFamily ? 'ql-active' : ''" class="iconfont icon-font"
data-name="fontFamily" data-value="Pacifico"></view>
<view :class="formats.fontSize === '24px' ? 'ql-active' : ''" class="iconfont icon-fontsize"
...
...
@@ -39,27 +39,35 @@
data-name="color" data-value="#0000ff"></view>
<view :class="formats.backgroundColor === '#00ff00' ? 'ql-active' : ''"
class="iconfont icon-fontbgcolor" data-name="backgroundColor" data-value="#00ff00"></view>
<view class="iconfont icon-date" @tap="insertDate"></view>
<view class="iconfont icon--checklist" data-name="list" data-value="check"></view>
<view :class="formats.list === 'ordered' ? 'ql-active' : ''" class="iconfont icon-youxupailie"
data-name="list" data-value="ordered"></view>
<view :class="formats.list === 'bullet' ? 'ql-active' : ''" class="iconfont icon-wuxupailie"
data-name="list" data-value="bullet"></view>
<view class="iconfont icon-undo" @tap="undo"></view>
<view class="iconfont icon-redo" @tap="redo"></view>
<view class="iconfont icon-outdent" data-name="indent" data-value="-1"></view>
<view class="iconfont icon-indent" data-name="indent" data-value="+1"></view>
<view class="iconfont icon-fengexian" @tap="insertDivider"></view>
<view class="iconfont icon-charutupian" @tap="insertImage"></view>
<view :class="formats.header === 1 ? 'ql-active' : ''" class="iconfont icon-format-header-1"
data-name="header" :data-value="1"></view>
<view :class="formats.script === 'sub' ? 'ql-active' : ''" class="iconfont icon-zitixiabiao"
data-name="script" data-value="sub"></view>
<view :class="formats.script === 'super' ? 'ql-active' : ''" class="iconfont icon-zitishangbiao"
data-name="script" data-value="super"></view>
<view class="iconfont icon-shanchu" @tap="clear"></view>
<view :class="formats.direction === 'rtl' ? 'ql-active' : ''" class="iconfont icon-direction-rtl"
data-name="direction" data-value="rtl"></view>
<view class="iconfont icon-date" @tap="insertDate"></view>
<view class="iconfont icon-fengexian" @tap="insertDivider"></view>
<view class="iconfont icon-charutupian" @tap="chooseInsertImage"></view>
<view class="iconfont icon-clearedformat" @tap="removeFormat"></view>
<view class="iconfont icon-undo" @tap="undo"></view>
<view class="iconfont icon-redo" @tap="redo"></view>
<view class="iconfont icon-shanchu" @tap="clearShowModal"></view>
</view>
<view class="editor-wrapper">
...
...
@@ -86,7 +94,12 @@
return {
readOnly: false,
formats: {},
editorCtx:{} as Context
editorCtx:{} as Context,
// 自动化测试
autoTest:false,
undoTest:false,
redoTest:false,
removeFormatTest:false
}
},
onLoad() {
...
...
@@ -110,6 +123,20 @@
this.editorCtx = res.context
}).exec()
},
// 自动化测试专用
setContents(options) {
this.editorCtx.setContents({
delta: {
ops:options
},
success: (res) => {
console.log('setContents-success', res)
},
fail: (err) => {
console.log(err)
}
})
},
getCon() {
this.editorCtx.getContents({
success: (res) => {
...
...
@@ -121,16 +148,27 @@
})
},
undo() {
this.editorCtx.undo()
this.editorCtx.undo({
success: (res) => {
this.undoTest = true
},
fail: (err) => {
this.undoTest = false
}
})
},
redo() {
this.editorCtx.redo()
this.editorCtx.redo({
success: (res) => {
this.redoTest = true
},
fail: (err) => {
this.redoTest = false
}
})
},
format(e) {
let {
name,
value
} = e.target.dataset
let {name,value} = e.target.dataset
if (!name) return
// console.log('format', name, value)
this.editorCtx.format(name, value)
...
...
@@ -146,23 +184,34 @@
}
})
},
clear() {
uni.showModal({
title: '清空编辑器',
content: '确定清空编辑器全部内容?',
success: res => {
if (res.confirm) {
this.editorCtx.clear({
success: function(res) {
console.log("clear success")
}
})
}
}
})
clear() {
this.editorCtx.clear({
success: function(res) {
console.log("clear success")
}
})
},
clearShowModal() {
uni.showModal({
title: '清空编辑器',
content: '确定清空编辑器全部内容?',
success: res => {
if (res.confirm) {
this.clear()
}
}
})
},
removeFormat() {
this.editorCtx.removeFormat()
this.editorCtx.removeFormat({
success: (res) => {
console.log('removeFormat-success', res)
this.removeFormatTest = true
},
fail: (err) => {
this.removeFormatTest = false
}
})
},
insertDate() {
const date = new Date()
...
...
@@ -171,19 +220,22 @@
text: formatDate
})
},
insertImage() {
uni.chooseImage({
count: 1,
success: (res) => {
this.editorCtx.insertImage({
src: res.tempFilePaths[0],
alt: '图像',
success: function() {
console.log('insert image success')
}
})
}
})
insertImage(image){
this.editorCtx.insertImage({
src:image,
alt: '图像',
success: function() {
console.log('insert image success')
}
})
},
chooseInsertImage() {
uni.chooseImage({
count: 1,
success: (res) => {
this.insertImage(res.tempFilePaths[0])
}
})
}
}
}
...
...
@@ -201,17 +253,18 @@
}
.editor-wrapper {
height: calc(100vh - var(--window-top) - var(--status-bar-height) -
8
0px - 46px);
height: calc(100vh - var(--window-top) - var(--status-bar-height) -
14
0px - 46px);
background: #fff;
}
.iconfont {
display: inline-block;
padding: 8px 8px;
width: 30px;
height: 30px;
cursor: pointer;
font-size: 20px;
margin: 0px 6px;
align-content: center;
}
.toolbar {
...
...
@@ -220,7 +273,8 @@
font-family: 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif;
flex-direction: row;
flex-wrap: wrap;
height: 110px;
height: 140px;
padding-left: 10px;
}
.ql-container {
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录