Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { defineConfig } from 'cypress'

export default defineConfig({
e2e: {
baseUrl: 'http://localhost:10086/#/',
specPattern: 'cypress/e2e/**/*.js',
},
viewportWidth: 414,
viewportHeight: 896,
})
125 changes: 125 additions & 0 deletions cypress/component/Actionsheet.cy.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
import React from 'react'
import { mount } from 'cypress/react18'
import { ActionSheet } from '../../src/packages/actionsheet/actionsheet'

const menulist = [
{
name: '选项一',
description: '选项一的描述信息',
danger: true,
},
{
name: '选项二',
disabled: true,
},
{
name: '必填',
name1: '选项三',
},
]

it('props test options ', () => {
mount(
<ActionSheet
visible
title="弹层标题"
description="弹层描述信息"
cancelText="关闭弹层"
options={menulist}
/>
)
cy.get('.nut-actionsheet-list .nut-actionsheet-item').should('have.length', 3)
})

it('props test cancelText ', async () => {
mount(
<ActionSheet
visible
title="弹层标题"
description="弹层描述信息"
cancelText="关闭弹层"
options={menulist}
/>
)
cy.get('.nut-actionsheet-cancel').then(($el) => {
const el = cy.wrap($el)
el.should('have.text', '关闭弹层')
})
})

it('props test has value ', async () => {
mount(
<ActionSheet
visible
title="弹层标题"
description="弹层描述信息"
cancelText="关闭弹层"
options={menulist}
/>
)
cy.get('.nut-actionsheet-list .nut-actionsheet-item')
.eq(0)
.then(($el) => {
const el = cy.wrap($el)
el.should('have.text', '选项一选项一的描述信息')
el.should('have.class', 'danger')
})
})

// it('props test choose item and show value', async () => {
// const choose = vi.fn()
// mount(
// <ActionSheet
// visible
// title="弹层标题"
// description="弹层描述信息"
// cancelText="关闭弹层"
// options={menulist}
// onSelect={choose}
// />
// )
// const chooseTagEle = container.querySelectorAll(
// '.nut-actionsheet-list .nut-actionsheet-item'
// )[0]
// fireEvent.click(chooseTagEle)
// await waitFor(() => expect(choose.mock.calls[0][0].name).toEqual('选项一'))
// })

// it('props test disabled item has disabled classes', async () => {
// const choose = vi.fn()
// mount(
// <ActionSheet
// visible
// title="弹层标题"
// description="弹层描述信息"
// cancelText="关闭弹层"
// options={menulist}
// onSelect={choose}
// />
// )
// const options = container.querySelectorAll(
// '.nut-actionsheet-list .nut-actionsheet-item'
// )
// const disableItem = options[1]
// expect(disableItem).toHaveClass('nut-actionsheet-item disabled')
// })

// it('props test click disabled item and not call fn', async () => {
// const choose = vi.fn()
// mount(
// <ActionSheet
// visible
// title="弹层标题"
// description="弹层描述信息"
// cancelText="关闭弹层"
// options={menulist}
// onSelect={choose}
// />
// )
// const options = container.querySelectorAll(
// '.nut-actionsheet-list .nut-actionsheet-item'
// )
// const disableItem = options[1]
// fireEvent.click(disableItem)
// await waitFor(() => expect(choose).not.toBeCalled())
// })
6 changes: 6 additions & 0 deletions cypress/component/Button.cy.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import React from 'react'
import { Button } from '../../src/packages/button/button'

it('playground', () => {
cy.mount(<Button type="primary">123</Button>)
})
38 changes: 38 additions & 0 deletions cypress/component/Cell.cy.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import React from 'react'
import { Cell } from '../../src/packages/cell/cell.taro'
import { Switch } from '../../src/packages/switch/switch.taro'

it('prop title extra description test', () => {
cy.mount(
<Cell
data-testid="prop"
title="我是标题"
description="我是描述"
extra="描述文字"
/>
)
cy.get('.nut-cell-title').should('contain.text', '我是标题')
cy.get('.nut-cell-description').should('contain.text', '我是描述')
cy.get('.nut-cell-extra').should('contain.text', '描述文字')
})
it('prop ', () => {
cy.mount(<Cell title="URL 跳转" extra="https://m.jd.com/" />)
cy.get('.nut-cell-extra').should('be.visible')
})

it('emit click event', () => {
const testClick = () => {}
cy.mount(<Cell data-testid="emit-click" onClick={() => testClick()} />)
cy.get('[data-testid="emit-click"]').click().trigger('testClick')
})

it('slot default test', () => {
cy.mount(<Cell title={<div>自定义内容</div>} extra="描述文字" />)
cy.root().should('contain.html', '<div>自定义内容</div>')
})

it('slot extra', () => {
cy.mount(<Cell title="Switch" extra={<Switch defaultChecked />} />)
cy.get('.nut-switch').should('be.visible')
// expect(container.querySelector('.nut-switch')).toBeInTheDocument()
})
8 changes: 8 additions & 0 deletions cypress/e2e/index.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import './taro/base.cy'
import './taro/layout.cy'
import './taro/nav.cy'
import './taro/dentry.cy'

Cypress.on('uncaught:exception', (err, runnable) => {
return false
})
116 changes: 116 additions & 0 deletions cypress/e2e/taro/base.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
const getPath = (component) => `base/pages/${component}/index`

describe('base components test', () => {
it('button successfully passes', () => {
cy.visit(getPath('button'))
cy.get('.applets-demo-header').contains('Button')
// Click Loading Test and loading icon shows
cy.contains('button', 'Click me').scrollIntoView().click()
cy.contains('button', 'Click me')
.parent()
.find('i.nut-icon-Loading')
.should('exist')
cy.wait(400)
})

it('cell successfully passes', () => {
cy.visit(getPath('cell'))
cy.get('.applets-demo-header').contains('Cell')
// Click Switch
cy.contains('自定义右侧区域').scrollIntoView()
cy.get('.nut-switch-button').click()
cy.get('.nut-switch-button')
.parent()
.should('have.class', 'nut-switch-close')
cy.get('.nut-switch-button').click()
cy.get('.nut-switch-button')
.parent()
.should('have.class', 'nut-switch-open')
// Jump URL
cy.contains('链接 | 分组用法').scrollIntoView()
cy.contains('/pages/index/index').click()
cy.wait(500)
cy.window().then((location) => {
expect(location.location.pathname).to.equal('/')
})
cy.wait(400)
})

it('ConfigProvider successfully passes', () => {
cy.visit(getPath('configprovider'))
cy.get('.applets-demo-header').contains('ConfigProvider')
// Expected Rate
cy.get('.nut-rate')
.first()
.find('.nut-rate-item')
.eq(-2)
.find('.nut-rate-item-icon')
.click()
cy.get('.nut-rate')
.first()
.find('.nut-rate-item .nut-rate-item-icon')
.filter('.nut-rate-item-icon-disabled')
.should('have.length', 1)
cy.get('.nut-rate')
.first()
.find('.nut-rate-item')
.first()
.find('.nut-rate-item-icon')
.click()
cy.get('.nut-rate')
.first()
.find('.nut-rate-item .nut-rate-item-icon')
.filter('.nut-rate-item-icon-disabled')
.should('have.length', 4)
cy.wait(400)
})

it('Icon successfully passes', () => {
cy.visit(getPath('icon'))
cy.get('.applets-demo-header').contains('Icon')
// V12 Icon Click Test
cy.contains('V12 Icon').scrollIntoView()
cy.get('i.nut-icon-thumbs-up').click()
cy.contains('<ThumbsUp />')
cy.get(
'i.nut-icon-heart-fill.nut-icon-am-breathe.nut-icon-am-infinite'
).click()
cy.contains(
`<HeartFill className='nut-icon-am-breathe nut-icon-am-infinite' />`
)
cy.wait(400)
})
it('Image successfully passes', () => {
cy.visit(getPath('image'))
cy.get('.applets-demo-header').contains('Image')
cy.wait(500)
// Lazy Load Scroll
cy.contains('图片懒加载').scrollIntoView()
cy.get('.taro-scroll-view__scroll-y .taro-img__mode-scaletofill')
.filter('[src]')
.should('have.length', 3)
cy.get('.taro-scroll-view__scroll-y').scrollTo('bottom', { duration: 1000 })
cy.get('.taro-scroll-view__scroll-y .taro-img__mode-scaletofill')
.filter('[src]')
.should('have.length.greaterThan', 3)
cy.wait(400)
})
it('Overlay successfully passes', () => {
cy.visit(getPath('overlay'))
cy.get('.applets-demo-header').contains('Overlay')
// Display Overlay
cy.contains('嵌套内容').scrollIntoView()
cy.get('.nut-button-success').click()
cy.contains('这里是正文')
cy.contains('这里是正文')
.parent()
.parent()
.should('have.class', 'nut-overlay')
.click()
cy.contains('这里是正文').should('not.exist')
cy.get('nut-overlay').should('not.exist')
})
})
Cypress.on('uncaught:exception', (err, runnable) => {
return false
})
45 changes: 45 additions & 0 deletions cypress/e2e/taro/dentry.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const componentTest = (comName, fn) => {
const dentryArr = [
'Address',
'Calendar',
'CalendarCard',
'Cascader',
'Checkbox',
'DatePicker',
'Form',
'Input',
'InputNumber',
]
const getPath = (component) =>
`${dentryArr.includes(component) ? 'dentry' : 'dentry1'}/pages/${component.toLowerCase()}/index`

it(`${comName} successfully passes`, () => {
cy.visit(getPath(comName))
cy.get('.applets-demo-header').contains(comName)
cy.wait(400)
fn()
})
}
describe('layout components test', () => {
componentTest('Address', () => {})
componentTest('Calendar', () => {})
componentTest('CalendarCard', () => {})
componentTest('Cascader', () => {})
componentTest('Checkbox', () => {})
componentTest('DatePicker', () => {})
componentTest('Form', () => {})
componentTest('Input', () => {})
componentTest('InputNumber', () => {})
componentTest('Menu', () => {})
componentTest('NumberKeyboard', () => {})
componentTest('Picker', () => {})
componentTest('Radio', () => {})
componentTest('Range', () => {})
componentTest('Rate', () => {})
componentTest('SearchBar', () => {})
componentTest('ShortPassword', () => {})
componentTest('Signature', () => {})
componentTest('Switch', () => {})
componentTest('TextArea', () => {})
componentTest('Uploader', () => {})
})
Loading