-
Notifications
You must be signed in to change notification settings - Fork 593
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(DatePicker): convert to TypeScript, impove docs and tests, close #4578 #4932
Conversation
f471c4f
to
0c655ad
Compare
this.setState({ | ||
panel, | ||
}); | ||
}; | ||
|
||
onOk = value => { | ||
onOk = (value: undefined) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里用undefined是否合适?若value强行指定为undefined,value || this.state.value 的值是否恒为 this.state.value?
} | ||
|
||
function getFormatValues(values, format) { | ||
function getFormatValues(values: RangePickerProps['value'] | null | undefined, format?: string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RangePickerProps['value']似乎已经包含undefined了
cy.get('@timeInput').type('{ctrl}{downArrow}'); | ||
cy.get('@timeInput').should('have.value', '00:00:00'); | ||
cy.get('@timeInput').type('{downArrow}'); | ||
cy.get('@timeInput').should('have.value', '00:00:01'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
在非单独测试时这个case偶尔会出现无法通过的情况,此处可能是00:00:00
|
||
it('should hide seconds', () => { | ||
cy.mount(<DatePicker defaultVisible showTime={{ format: 'HH:mm' }} />); | ||
// assert(!wrapper.find('.next-time-picker-menu-hour').length); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
待删除
it('should defaultValue as string', () => { | ||
cy.mount(<DatePicker defaultValue="2018-01-23" />); | ||
|
||
// assert(wrapper.find('.next-date-picker-input input').instance().value === '2018-01-23'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
待删除
|
||
it('should set hasClear to false', () => { | ||
cy.mount(<YearPicker defaultValue={startYear} hasClear={false} />); | ||
// assert(!wrapper.find('i.next-input-clear-icon').length); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
待删除
|
||
it('should set hasClear to false', () => { | ||
cy.mount(<MonthPicker defaultValue={startMonth} hasClear={false} />); | ||
// assert(!wrapper.find('i.next-input-clear-icon').length); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
待删除
}); | ||
|
||
it('should input disabled date in picker', () => { | ||
// const onChange = cy.spy(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
待删除
describe('render with props', () => { | ||
it('should render with defaultValue', () => { | ||
cy.mount(<WeekPicker defaultValue={startWeek} />); | ||
cy.get('.next-week-picker-input input').should('have.value', '2018-2nd'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
根据原 case 是否应该补一句:cy.get('i.next-input-clear-icon').should('exist');
|
||
describe('action', () => { | ||
it('should select', () => { | ||
// const onChange = cy.spy(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
待删除
|
||
cy.get('.next-calendar-cell[title="2017-11-09"] .next-calendar-date').click(); | ||
cy.get('.next-calendar-cell[title="2017-12-09"] .next-calendar-date').eq(1).click(); | ||
// assert(ret[1].format('YYYY-MM-DD HH:mm:ss') === '2017-12-09 09:00:00'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
待删除
); | ||
cy.get('.next-calendar-cell[title="2017-11-09"] .next-calendar-date').click(); | ||
cy.get('.next-calendar-cell[title="2017-12-09"] .next-calendar-date').eq(1).click(); | ||
// assert(ret[1].format('YYYY-MM-DD HH:mm:ss') === '2017-12-09 23:59:59'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
待删除
cy.get('@input').type('{ctrl}{downArrow}'); | ||
cy.get('@input').should('have.value', moment().format('YYYY-MM-DD')); | ||
cy.get('@input').type('{downArrow}'); | ||
cy.get('@input').should('have.value', moment().add(1, 'day').format('YYYY-MM-DD')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
此处也出现过case不通过的情况,不过复现频率比前者低很多
super(props); | ||
const { format, timeFormat, dateTimeFormat } = getDateTimeFormat( | ||
props.format, | ||
props.showTime! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
此处似乎没必要加非空断言?
super(props); | ||
const { format, timeFormat, dateTimeFormat } = getDateTimeFormat( | ||
props.format, | ||
props.showTime!, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
此处似乎没必要加非空断言?
@@ -2,55 +2,77 @@ import React from 'react'; | |||
import { DatePicker } from '@alifd/next'; | |||
import { Types } from '@alifd/adaptor-helper'; | |||
import moment from 'moment'; | |||
import type { DatePickerProps } from '../../types'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是否应该从'@alifd/next/types/date-picker'中引?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
只有 demo 要求必须从 @alifd/next/types 引,因为是给用户看的,其他的部分可以引相对路径。
); | ||
cy.get('.next-date-picker-panel-input input').eq(0).type('2017-11-11'); | ||
cy.get('.next-date-picker-panel-input input').eq(0).blur(); | ||
cy.wrap(handleChange).should('be.calledWith', '2017-11-11 00:00:00'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* 日期值(受控)moment 对象 | ||
* @en Date value, moment object, controlled | ||
*/ | ||
value?: string | Moment | null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @en Input box size | ||
* @defaultValue 'medium' | ||
*/ | ||
size?: 'small' | 'medium' | 'large'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个size也多次定义,如果不影响tsdoc生成文档的话,是否能够共用一个type
const timeStamp = 1581938105000; | ||
|
||
// 禁止选择 startValue 之前的所有日期 | ||
const disabledDate = function (date: Moment, view: unknown) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
view 可以准确的定义为 string
); | ||
cy.get('.next-date-picker-panel-input input').click(); | ||
cy.get('.next-date-picker-panel-input input').eq(0).clear(); | ||
cy.get('.next-date-picker-panel-input input').eq(0).blur(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
blur这行代码应该是不需要的,下面的click会触发blur
cy.get('.next-date-picker-panel-input input').eq(1).focus(); | ||
cy.get('.next-time-picker-panel').should('exist'); | ||
cy.get('.next-date-picker-panel-input input').eq(0).focus(); | ||
cy.get('.next-date-picker-panel-input input').eq(0).blur(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这行应该也不需要
cy.mount(<RangePicker />); | ||
cy.get('.next-range-picker-trigger-input input').eq(0).focus(); | ||
cy.get('.next-range-picker-trigger-input input').eq(0).click(); | ||
cy.get('.next-range-picker-panel-input-start-date').should('have.class', 'next-focus'); | ||
}); | ||
|
||
it('should focus the input of end date', () => { | ||
cy.mount(<RangePicker />); | ||
cy.get('.next-range-picker-trigger-input input').eq(1).focus(); | ||
cy.get('.next-range-picker-trigger-input input').eq(1).click(); | ||
cy.get('.next-range-picker-panel-input-end-date').should('have.class', 'next-focus'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里面的两行focus是无效的代码
it('should focus the input to change panel', () => { | ||
cy.mount(<RangePicker showTime defaultValue={[startValue, endValue]} defaultVisible />); | ||
cy.get('.next-range-picker-panel-input-start-time input').focus(); | ||
cy.get('.next-range-picker-panel-input-start-time input').blur(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里面的两行blur是无效的代码
close #4578, #3072