Skip to content

Commit 1852bf8

Browse files
authored
refactor: 代码优化 & 补全 e2e 测试 (#161)
* refactor: 移除 package-option.js * refactor: 将 enableWhen 从 mixin 改造成纯函数 * refactor: 移除 mixin-hidden * refactor: 调整层级 * fix: typo * refactor: 优化 transform-content 函数 * refactor: 优化初始化 options & value 的函数 * refactor: 明确 updateForm 的合并逻辑 * refactor: getFormValue * refactor: 移除掉无用操作 updateOptions * fix: 补回 inputFormat 功能 * test: 补充 e2e 测试 * fix: outputFormat 返回值是 Object 时应该覆盖到上一层 * chore: 移除不必要的 clonedeep
1 parent ab4c4e4 commit 1852bf8

34 files changed

Lines changed: 677 additions & 534 deletions
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
semi: false
22
singleQuote: true
33
bracketSpacing: false
4+
trailingComma: all

cypress/integration/basic.spec.js

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,25 @@
11
/// <reference types="Cypress" />
22

3-
describe('测试 github page 文档', function() {
3+
describe('测试 basic 示例', function() {
44
beforeEach(() => {
55
cy.visit('/')
6-
cy.get('li')
7-
.contains('basic')
8-
.click()
6+
cy.$goto('basic')
97
})
10-
it('basic 示例', function() {
8+
it('基础用例', function() {
119
cy.contains('basic')
1210
cy.contains('submit').click()
1311
cy.contains('miss name')
14-
const getInput = (label, el = 'input') =>
15-
cy.contains('.el-form-item', label).find(el)
16-
17-
getInput('name').type('name')
18-
getInput('area').click()
12+
cy.$getFormItemInput('name').type('name')
13+
cy.$getFormItemInput('area').click()
1914
cy.contains('area1').click()
20-
getInput('date').click()
15+
cy.$getFormItemInput('date').click()
2116
cy.contains('此刻').click()
2217
cy.contains('typeA').click()
2318
cy.contains('resourceA').click()
24-
getInput('desc', 'textarea').type('desc')
19+
cy.$getFormItemInput('desc', 'textarea').type('desc')
2520
cy.contains('submit').click()
2621
cy.contains('submit!')
2722
cy.contains('reset').click()
28-
getInput('name').should('be.empty')
23+
cy.$getFormItemInput('name').should('be.empty')
2924
})
3025
})
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/// <reference types="Cypress" />
2+
3+
describe('测试 component 示例', function() {
4+
beforeEach(() => {
5+
cy.visit('/')
6+
cy.$goto('component')
7+
})
8+
it('基础用例', function() {
9+
cy.contains('component')
10+
cy.get('.el-form-renderer input')
11+
.type('1')
12+
.should('have.value', 'v1') // 不能用 contains,这里取属性
13+
.blur()
14+
.should('have.value', 'v1.0.0')
15+
})
16+
})
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/// <reference types="Cypress" />
2+
3+
describe('测试 disabled 示例', function() {
4+
beforeEach(() => {
5+
cy.visit('/')
6+
cy.$goto('disabled')
7+
})
8+
it('禁用全部', function() {
9+
cy.contains('disabled')
10+
cy.$getFormItemInput('name').should('be.enabled')
11+
cy.contains('禁用全部').click()
12+
cy.$getFormItemInput('name').should('be.disabled')
13+
})
14+
})
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/// <reference types="Cypress" />
2+
3+
describe('测试 get-form-value 示例', function() {
4+
beforeEach(() => {
5+
cy.visit('/')
6+
cy.$goto('get-form-value')
7+
})
8+
it('基础用例', function() {
9+
cy.get('pre').contains('{}')
10+
cy.contains('print').click()
11+
cy.get('pre').contains('"name": "alvin"')
12+
})
13+
})

cypress/integration/hidden.spec.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/// <reference types="Cypress" />
2+
3+
describe('测试 hidden 示例', function() {
4+
beforeEach(() => {
5+
cy.visit('/')
6+
cy.$goto('hidden')
7+
})
8+
it('切换 hidden', function() {
9+
cy.contains('idol').should('not.be.visible') // 不是 not.exist 哦
10+
cy.$getFormItemInput('hobby').click()
11+
cy.contains('basketball').click()
12+
cy.contains('idol').should('be.visible') // invisible 也是 contains
13+
})
14+
})

cypress/integration/on.spec.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/// <reference types="Cypress" />
2+
3+
describe('测试 on 示例', function() {
4+
beforeEach(() => {
5+
cy.visit('/')
6+
cy.$goto('on')
7+
})
8+
it('测试所有事件', function() {
9+
cy.$getFormItemInput('fullName').focus()
10+
cy.$getFormItemInput('display').should(
11+
'have.value',
12+
'focus: [object FocusEvent]',
13+
)
14+
cy.$getFormItemInput('fullName').type(1)
15+
cy.$getFormItemInput('display').should('have.value', 'input: 1')
16+
cy.$getFormItemInput('fullName').blur()
17+
cy.$getFormItemInput('display').should(
18+
'have.value',
19+
'blur: [object FocusEvent]',
20+
)
21+
})
22+
})

cypress/integration/remote.spec.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/// <reference types="Cypress" />
2+
3+
describe('测试 remote 示例', function() {
4+
beforeEach(() => {
5+
cy.visit('/')
6+
cy.$goto('remote')
7+
})
8+
it('测试所有 remote 配置', function() {
9+
cy.$getFormItemInput('select').click()
10+
cy.contains('area1').click()
11+
cy.contains('resourceA')
12+
cy.contains('typeA')
13+
cy.$getFormItemInput('cascader').click()
14+
cy.contains('hello').click()
15+
cy.contains('world').click()
16+
cy.$getFormItemInput('cascader').should('have.value', 'hello / world')
17+
})
18+
})
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/// <reference types="Cypress" />
2+
3+
describe('测试 set-options 示例', function() {
4+
beforeEach(() => {
5+
cy.visit('/')
6+
cy.$goto('set-options')
7+
})
8+
it('基础用例', function() {
9+
cy.$getFormItemInput('select').click()
10+
cy.contains('shanghai').should('be.visible')
11+
cy.contains('beijing').should('be.visible')
12+
cy.contains('guangzhou').should('not.exist')
13+
cy.contains('hangzhou').should('not.exist')
14+
cy.contains('button', 'set').click()
15+
cy.$getFormItemInput('select').click()
16+
cy.contains('shanghai').should('not.exist')
17+
cy.contains('beijing').should('not.exist')
18+
cy.contains('guangzhou').should('be.visible')
19+
cy.contains('hangzhou').should('be.visible')
20+
})
21+
})

cypress/integration/slot.spec.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/// <reference types="Cypress" />
2+
3+
describe('测试 slot 示例', function() {
4+
beforeEach(() => {
5+
cy.visit('/')
6+
cy.$goto('slot')
7+
})
8+
it('基础用例', function() {
9+
cy.get('.el-form-item')
10+
.first()
11+
.should('contain', 'name')
12+
.next()
13+
.should('match', 'button')
14+
.should('contain', 'a button insert before age')
15+
.next()
16+
.should('contain', 'age')
17+
.next()
18+
.should('contain', 'default slot is at the bottom')
19+
})
20+
})

0 commit comments

Comments
 (0)