2019-01-23 01:46:04 +00:00
|
|
|
import { mount } from '@vue/test-utils';
|
2021-09-25 08:51:32 +00:00
|
|
|
import dayjs from 'dayjs';
|
|
|
|
import { asyncExpect } from '../../../tests/utils';
|
2019-01-23 01:46:04 +00:00
|
|
|
import Comment from '..';
|
|
|
|
import List from '../../list';
|
|
|
|
import Form from '../../form';
|
|
|
|
import Button from '../../button';
|
|
|
|
import Input from '../../input';
|
2020-03-07 11:45:13 +00:00
|
|
|
import mountTest from '../../../tests/shared/mountTest';
|
2021-09-25 08:51:32 +00:00
|
|
|
import relativeTime from 'dayjs/plugin/relativeTime';
|
|
|
|
dayjs.extend(relativeTime);
|
2019-01-23 01:46:04 +00:00
|
|
|
|
|
|
|
const CommentTest = {
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
comments: [],
|
|
|
|
submitting: false,
|
|
|
|
value: '',
|
2021-09-25 08:51:32 +00:00
|
|
|
dayjs,
|
2019-01-23 01:46:04 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
handleSubmit() {
|
|
|
|
if (!this.value) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.submitting = true;
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
this.submitting = false;
|
|
|
|
this.comments = [
|
|
|
|
{
|
|
|
|
author: 'Han Solo',
|
|
|
|
avatar: 'https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png',
|
|
|
|
content: this.value,
|
2021-09-25 08:51:32 +00:00
|
|
|
datetime: dayjs().fromNow(),
|
2019-01-23 01:46:04 +00:00
|
|
|
},
|
|
|
|
...this.comments,
|
|
|
|
];
|
|
|
|
this.value = '';
|
|
|
|
}, 1000);
|
|
|
|
},
|
|
|
|
handleChange(e) {
|
|
|
|
this.value = e.target.value;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
{this.comments.length ? (
|
|
|
|
<List
|
|
|
|
dataSource={this.comments}
|
|
|
|
header={`${this.comments.length} ${this.comments.length > 1 ? 'replies' : 'reply'}`}
|
|
|
|
itemLayout="horizontal"
|
2020-07-28 09:10:59 +00:00
|
|
|
renderItem={({ item }) => {
|
2019-01-23 01:46:04 +00:00
|
|
|
return (
|
|
|
|
<List.Item>
|
|
|
|
<Comment
|
|
|
|
author={item.author}
|
|
|
|
avatar={item.avatar}
|
|
|
|
content={item.content}
|
|
|
|
datetime={item.datetime}
|
|
|
|
/>
|
|
|
|
</List.Item>
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
) : null}
|
2020-07-28 09:10:59 +00:00
|
|
|
<Comment
|
|
|
|
vSlots={{
|
|
|
|
content: () => (
|
|
|
|
<div>
|
|
|
|
<Form.Item>
|
|
|
|
<Input.TextArea rows={4} onChange={this.handleChange} value={this.value} />
|
|
|
|
</Form.Item>
|
|
|
|
<Form.Item>
|
|
|
|
<Button
|
|
|
|
htmlType="submit"
|
|
|
|
loading={this.submitting}
|
|
|
|
onClick={this.handleSubmit}
|
|
|
|
type="primary"
|
|
|
|
>
|
|
|
|
Add Comment
|
|
|
|
</Button>
|
|
|
|
</Form.Item>
|
|
|
|
</div>
|
|
|
|
),
|
|
|
|
}}
|
|
|
|
></Comment>
|
2019-01-23 01:46:04 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('Comment', () => {
|
2020-03-07 11:45:13 +00:00
|
|
|
mountTest(Comment);
|
2019-01-23 01:46:04 +00:00
|
|
|
it('Comment can be used as editor, user can customize the editor component.', async () => {
|
|
|
|
const wrapper = mount(CommentTest, {
|
|
|
|
sync: false,
|
|
|
|
});
|
|
|
|
await asyncExpect(() => {
|
|
|
|
wrapper.find('textarea').element.value = '222';
|
|
|
|
wrapper.find('textarea').trigger('input');
|
|
|
|
});
|
|
|
|
await asyncExpect(() => {
|
2020-07-28 09:10:59 +00:00
|
|
|
wrapper.find('.ant-btn').trigger('click');
|
2019-01-23 01:46:04 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
await asyncExpect(() => {
|
2020-07-28 09:10:59 +00:00
|
|
|
expect(wrapper.findAll('.ant-list-header')[0].element.innerHTML).toBe('1 reply');
|
2019-01-23 01:46:04 +00:00
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
|
|
}, 2000);
|
|
|
|
});
|
|
|
|
});
|