forked from alibaba-fusion/next
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index-spec.js
149 lines (130 loc) · 5.37 KB
/
index-spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import React from 'react';
import Enzyme, { mount } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import assert from 'power-assert';
import Button from '../../src/button';
import Card from '../../src/card/index';
import '../../src/card/style.js';
Enzyme.configure({ adapter: new Adapter() });
/* eslint-disable */
describe('Card', () => {
const commonProps = {
style: { width: 300 },
title: 'Title',
subTitle: 'sub title',
extra: 'Link',
};
describe('render', () => {
let wrapper;
afterEach(() => {
wrapper = null;
});
it('should render card', () => {
wrapper = mount(<Card {...commonProps}>Card content</Card>);
assert(wrapper.find('.next-card').length === 1);
assert(wrapper.find('.next-card-head-show-bullet').length === 1);
assert(wrapper.find('.next-card-head-show-underline').length === 0);
});
it('should render without title bullet', () => {
wrapper = mount(
<Card {...commonProps} showTitleBullet={false}>
Card Content
</Card>
);
assert(wrapper.find('.next-card-head-show-bullet').length === 0);
});
it('should render without head underline', () => {
wrapper = mount(
<Card {...commonProps} showHeadDivider={false}>
Card Content
</Card>
);
assert(wrapper.find('.next-card-head-show-underline').length === 0);
});
it('should render without head', () => {
wrapper = mount(
<Card {...commonProps} title={null}>
Card Content
</Card>
);
assert(wrapper.find('.next-card-head').length === 0);
});
it('should render media & actions', () => {
wrapper = mount(
<Card
{...commonProps}
media={<img src="https://img.alicdn.com/tfs/TB1FNIOSFXXXXaWXXXXXXXXXXXX-260-188.png" />}
actions={<Button text type="primary">Button</Button>}
>
Card Content
</Card>
);
assert(wrapper.find('.next-card-media').length > 0);
assert(wrapper.find('.next-card-actions').length > 0);
});
it('should render when contentHeight is auto', () => {
wrapper = mount(
<Card {...commonProps} title="Card Title" contentHeight="300">
Card Content <br/>Card Content <br/>Card Content <br/>Card Content <br/>
Card Content <br/>Card Content <br/>Card Content <br/>Card Content <br/>
Card Content <br/>Card Content <br/>Card Content <br/>Card Content <br/>
Card Content <br/>Card Content <br/>Card Content <br/>Card Content <br/>
Card Content <br/>Card Content <br/>Card Content <br/>Card Content <br/>
Card Content <br/>Card Content <br/>Card Content <br/>Card Content <br/>
Card Content <br/>Card Content <br/>Card Content <br/>Card Content <br/>
</Card>
);
assert(wrapper.find('.next-card-content').instance().style.height === '300px');
wrapper.setProps({ contentHeight: 'auto' });
assert(wrapper.find('.next-card-content').instance().style.height === 'auto');
});
it('should render free', () => {
wrapper = mount(
<Card
style= {{ width: 300 }}
free
>
<Card.Media>
<img src="https://img.alicdn.com/tfs/TB1FNIOSFXXXXaWXXXXXXXXXXXX-260-188.png" />
</Card.Media>
<Card.Header title="Title" subTitle="Sub Title" extra={<Button type="primary" text>Link</Button>} />
<Card.Divider />
<Card.Content>
Card Content
</Card.Content>
<Card.Actions>
<Button type="primary" key="action1" text>Action 1</Button>
<Button type="primary" key="action2" text>Action 2</Button>
</Card.Actions>
</Card>
);
assert(wrapper.find('.next-card-free').length > 0);
// assert(wrapper.find('.next-card-actions').length > 0);
});
});
describe('action', () => {
let wrapper, parent;
beforeEach(() => {
parent = document.createElement('div');
parent.setAttribute('id', 'react-app');
document.body.appendChild(parent);
});
afterEach(() => {
document.body.removeChild(parent);
parent = null;
wrapper = null;
});
it('should expand card', done => {
wrapper = mount(
<Card {...commonProps}>
<div style={{ height: 600 }} />
</Card>,
{ attachTo: parent }
);
assert(wrapper.find('.next-icon-arrow-down.expand').length === 0);
wrapper.find(Button).simulate('click');
assert(wrapper.find('.next-icon-arrow-down.expand').length === 1);
done();
});
});
});