Skip to content
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

Merged
merged 5 commits into from
Sep 23, 2024

Conversation

eternalsky
Copy link
Contributor

@eternalsky eternalsky commented Sep 13, 2024

close #4578, #3072

@eternalsky eternalsky changed the title Refactor/date picker refactor(DatePicker): convert to TypeScript, impove docs and tests, close Sep 13, 2024
@eternalsky eternalsky changed the title refactor(DatePicker): convert to TypeScript, impove docs and tests, close refactor(DatePicker): convert to TypeScript, impove docs and tests, close #4578 Sep 13, 2024
this.setState({
panel,
});
};

onOk = value => {
onOk = (value: undefined) => {
Copy link
Collaborator

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) {
Copy link
Collaborator

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');
Copy link
Collaborator

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);
Copy link
Collaborator

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');
Copy link
Collaborator

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);
Copy link
Collaborator

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);
Copy link
Collaborator

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();
Copy link
Collaborator

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');
Copy link
Collaborator

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();
Copy link
Collaborator

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');
Copy link
Collaborator

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');
Copy link
Collaborator

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'));
Copy link
Collaborator

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!
Copy link
Collaborator

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!,
Copy link
Collaborator

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';
Copy link
Collaborator

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'中引?

Copy link
Contributor Author

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');
Copy link
Collaborator

@caozhong1996 caozhong1996 Sep 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个断言低概率出现不能被调用到的情况,可能cypress本身的问题
image

@Haxwwwww Haxwwwww self-requested a review September 23, 2024 03:03
@eternalsky eternalsky merged commit 44b64b6 into next Sep 23, 2024
4 checks passed
@eternalsky eternalsky deleted the refactor/date-picker branch September 23, 2024 03:07
* 日期值(受控)moment 对象
* @en Date value, moment object, controlled
*/
value?: string | Moment | null;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
这里的value类型定义,应该可以共用一个,不过好像被合并进去了,后续在改吧🥹

* @en Input box size
* @defaultValue 'medium'
*/
size?: 'small' | 'medium' | 'large';
Copy link
Collaborator

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) {
Copy link
Collaborator

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();
Copy link
Collaborator

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();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这行应该也不需要

Comment on lines +1028 to +1038
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');
Copy link
Collaborator

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();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里面的两行blur是无效的代码

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[DatePicker]DatePicker组件优化 【Technical upgrade】DatePicker
3 participants