@dhis2-ui/table 10.16.2 → 10.16.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +5 -4
- package/src/data-table/__tests__/data-table-cell.test.js +168 -0
- package/src/data-table/__tests__/data-table-column-header/filter-handle.test.js +43 -0
- package/src/data-table/__tests__/data-table-column-header/sorter.test.js +41 -0
- package/src/data-table/__tests__/data-table-column-header.test.js +227 -0
- package/src/data-table/__tests__/data-table-row/expand-handle-cell.js +32 -0
- package/src/data-table/__tests__/data-table-row/expanded-row.test.js +57 -0
- package/src/data-table/__tests__/data-table-row.test.js +162 -0
- package/src/data-table/__tests__/data-table.test.js +85 -0
- package/src/data-table/data-table-body.js +3 -0
- package/src/data-table/data-table-cell.js +111 -0
- package/src/data-table/data-table-column-header/data-table-column-header.js +130 -0
- package/src/data-table/data-table-column-header/data-table-column-header.styles.js +30 -0
- package/src/data-table/data-table-column-header/filter-handle.js +30 -0
- package/src/data-table/data-table-column-header/sorter.js +67 -0
- package/src/data-table/data-table-foot.js +3 -0
- package/src/data-table/data-table-head.js +3 -0
- package/src/data-table/data-table-row/data-table-row.js +103 -0
- package/src/data-table/data-table-row/data-table-row.styles.js +20 -0
- package/src/data-table/data-table-row/drag-handle-cell.js +9 -0
- package/src/data-table/data-table-row/expand-handle-cell.js +28 -0
- package/src/data-table/data-table-row/expanded-row.js +51 -0
- package/src/data-table/data-table-toolbar.js +3 -0
- package/src/data-table/data-table.e2e.stories.js +192 -0
- package/src/data-table/data-table.js +75 -0
- package/src/data-table/data-table.prod.stories.js +1342 -0
- package/src/data-table/features/can_scroll/index.js +48 -0
- package/src/data-table/features/can_scroll.feature +31 -0
- package/src/data-table/index.js +8 -0
- package/src/data-table/table-elements/__tests__/table-body.test.js +40 -0
- package/src/data-table/table-elements/__tests__/table-data-cell.test.js +123 -0
- package/src/data-table/table-elements/__tests__/table-foot.test.js +40 -0
- package/src/data-table/table-elements/__tests__/table-head.test.js +40 -0
- package/src/data-table/table-elements/__tests__/table-header-cell-action.test.js +46 -0
- package/src/data-table/table-elements/__tests__/table-header-cell.test.js +130 -0
- package/src/data-table/table-elements/__tests__/table-row.test.js +52 -0
- package/src/data-table/table-elements/__tests__/table-scroll-box.test.js +40 -0
- package/src/data-table/table-elements/__tests__/table-toolbar.test.js +44 -0
- package/src/data-table/table-elements/__tests__/table.test.js +53 -0
- package/src/data-table/table-elements/features/can_scroll/index.js +42 -0
- package/src/data-table/table-elements/features/can_scroll.feature +31 -0
- package/src/data-table/table-elements/index.js +10 -0
- package/src/data-table/table-elements/table-body.js +75 -0
- package/src/data-table/table-elements/table-data-cell/table-data-cell.js +126 -0
- package/src/data-table/table-elements/table-data-cell/table-data-cell.styles.js +42 -0
- package/src/data-table/table-elements/table-foot.js +35 -0
- package/src/data-table/table-elements/table-head.js +26 -0
- package/src/data-table/table-elements/table-header-cell/table-header-cell.js +121 -0
- package/src/data-table/table-elements/table-header-cell/table-header-cell.styles.js +71 -0
- package/src/data-table/table-elements/table-header-cell-action.js +62 -0
- package/src/data-table/table-elements/table-row.js +52 -0
- package/src/data-table/table-elements/table-scroll-box.js +41 -0
- package/src/data-table/table-elements/table-toolbar.js +50 -0
- package/src/data-table/table-elements/table.e2e.stories.js +190 -0
- package/src/data-table/table-elements/table.js +70 -0
- package/src/data-table/table-elements/table.stories.internal.js +1144 -0
- package/src/index.js +32 -0
- package/src/locales/ar/translations.json +4 -0
- package/src/locales/cs/translations.json +4 -0
- package/src/locales/en/translations.json +4 -0
- package/src/locales/es/translations.json +4 -0
- package/src/locales/es_419/translations.json +4 -0
- package/src/locales/fr/translations.json +4 -0
- package/src/locales/index.js +44 -0
- package/src/locales/km/translations.json +4 -0
- package/src/locales/lo/translations.json +4 -0
- package/src/locales/nb/translations.json +4 -0
- package/src/locales/nl/translations.json +4 -0
- package/src/locales/pt/translations.json +4 -0
- package/src/locales/ru/translations.json +4 -0
- package/src/locales/uk/translations.json +4 -0
- package/src/locales/uz_UZ_Cyrl/translations.json +4 -0
- package/src/locales/zh/translations.json +4 -0
- package/src/stacked-table/add-col-num-to-children.js +16 -0
- package/src/stacked-table/content-with-title.js +40 -0
- package/src/stacked-table/extract-header-labels.js +99 -0
- package/src/stacked-table/index.js +8 -0
- package/src/stacked-table/stacked-table-body.js +23 -0
- package/src/stacked-table/stacked-table-cell-head.js +39 -0
- package/src/stacked-table/stacked-table-cell.js +60 -0
- package/src/stacked-table/stacked-table-foot.js +24 -0
- package/src/stacked-table/stacked-table-head.js +23 -0
- package/src/stacked-table/stacked-table-row-head.js +19 -0
- package/src/stacked-table/stacked-table-row.js +50 -0
- package/src/stacked-table/stacked-table.js +33 -0
- package/src/stacked-table/stacked-table.prod.stories.js +463 -0
- package/src/stacked-table/stacked-table.test.js +127 -0
- package/src/stacked-table/supply-header-labels-to-children.js +7 -0
- package/src/stacked-table/table-context.js +4 -0
- package/src/stacked-table/table.js +28 -0
- package/src/table/index.js +8 -0
- package/src/table/table-body.js +21 -0
- package/src/table/table-cell-head.js +56 -0
- package/src/table/table-cell.js +56 -0
- package/src/table/table-context.js +7 -0
- package/src/table/table-foot.js +21 -0
- package/src/table/table-head.js +21 -0
- package/src/table/table-row-head.js +30 -0
- package/src/table/table-row.js +51 -0
- package/src/table/table.js +41 -0
- package/src/table/table.prod.stories.js +724 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dhis2-ui/table",
|
|
3
|
-
"version": "10.16.
|
|
3
|
+
"version": "10.16.3",
|
|
4
4
|
"description": "UI Table",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -34,14 +34,15 @@
|
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@dhis2/prop-types": "^3.1.2",
|
|
37
|
-
"@dhis2/ui-constants": "10.16.
|
|
38
|
-
"@dhis2/ui-icons": "10.16.
|
|
37
|
+
"@dhis2/ui-constants": "10.16.3",
|
|
38
|
+
"@dhis2/ui-icons": "10.16.3",
|
|
39
39
|
"classnames": "^2.3.1",
|
|
40
40
|
"prop-types": "^15.7.2"
|
|
41
41
|
},
|
|
42
42
|
"files": [
|
|
43
43
|
"build",
|
|
44
|
-
"types"
|
|
44
|
+
"types",
|
|
45
|
+
"src"
|
|
45
46
|
],
|
|
46
47
|
"devDependencies": {
|
|
47
48
|
"@dhis2/d2-i18n": "^1.1.0",
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { shallow, mount } from 'enzyme'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
import { DataTableCell } from '../data-table-cell.js'
|
|
4
|
+
import { TableDataCell, TableHeaderCell } from '../table-elements/index.js'
|
|
5
|
+
|
|
6
|
+
describe('<DataTableCell>', () => {
|
|
7
|
+
it('renders children', () => {
|
|
8
|
+
const children = 'children'
|
|
9
|
+
const wrapper = shallow(<DataTableCell>{children}</DataTableCell>)
|
|
10
|
+
|
|
11
|
+
expect(wrapper.containsMatchingElement(children)).toBe(true)
|
|
12
|
+
})
|
|
13
|
+
it('accepts a ref', () => {
|
|
14
|
+
const ref = React.createRef()
|
|
15
|
+
const wrapper = mount(
|
|
16
|
+
<table>
|
|
17
|
+
<tbody>
|
|
18
|
+
<tr>
|
|
19
|
+
<DataTableCell ref={ref} />
|
|
20
|
+
</tr>
|
|
21
|
+
</tbody>
|
|
22
|
+
</table>
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
expect(wrapper.find('td').getDOMNode()).toBe(ref.current)
|
|
26
|
+
})
|
|
27
|
+
it('accepts an active prop', () => {
|
|
28
|
+
const wrapper = shallow(<DataTableCell active />)
|
|
29
|
+
|
|
30
|
+
expect(wrapper.find(TableDataCell).prop('active')).toBe(true)
|
|
31
|
+
})
|
|
32
|
+
it('accepts an align prop', () => {
|
|
33
|
+
const right = 'right'
|
|
34
|
+
const wrapper = shallow(<DataTableCell align={right} />)
|
|
35
|
+
|
|
36
|
+
expect(wrapper.find(TableDataCell).prop('align')).toBe(right)
|
|
37
|
+
})
|
|
38
|
+
it('accepts a bordered prop', () => {
|
|
39
|
+
const wrapper = shallow(<DataTableCell bordered />)
|
|
40
|
+
|
|
41
|
+
expect(wrapper.find(TableDataCell).prop('bordered')).toBe(true)
|
|
42
|
+
})
|
|
43
|
+
it('accepts a className prop', () => {
|
|
44
|
+
const className = 'test'
|
|
45
|
+
const wrapper = shallow(<DataTableCell className={className} />)
|
|
46
|
+
|
|
47
|
+
expect(wrapper.find(TableDataCell).prop('className')).toBe(className)
|
|
48
|
+
})
|
|
49
|
+
it('accepts a colSpan prop', () => {
|
|
50
|
+
const colSpan = '3'
|
|
51
|
+
const wrapper = shallow(<DataTableCell colSpan={colSpan} />)
|
|
52
|
+
|
|
53
|
+
expect(wrapper.find(TableDataCell).prop('colSpan')).toBe(colSpan)
|
|
54
|
+
})
|
|
55
|
+
it('accepts a dataTest prop', () => {
|
|
56
|
+
const dataTest = 'test'
|
|
57
|
+
const wrapper = shallow(<DataTableCell dataTest={dataTest} />)
|
|
58
|
+
|
|
59
|
+
expect(wrapper.find(TableDataCell).prop('dataTest')).toBe(dataTest)
|
|
60
|
+
})
|
|
61
|
+
it('accepts an error prop', () => {
|
|
62
|
+
const wrapper = shallow(<DataTableCell error />)
|
|
63
|
+
|
|
64
|
+
expect(wrapper.find(TableDataCell).prop('error')).toBe(true)
|
|
65
|
+
})
|
|
66
|
+
it('accepts a fixed prop', () => {
|
|
67
|
+
const wrapper = shallow(<DataTableCell fixed />)
|
|
68
|
+
|
|
69
|
+
expect(wrapper.find(TableDataCell)).toHaveLength(0)
|
|
70
|
+
expect(wrapper.find(TableHeaderCell)).toHaveLength(1)
|
|
71
|
+
expect(wrapper.find(TableHeaderCell).dive().type()).toBe('th')
|
|
72
|
+
expect(wrapper.find(TableHeaderCell).prop('fixed')).toBe(true)
|
|
73
|
+
})
|
|
74
|
+
it('accepts a large prop', () => {
|
|
75
|
+
const wrapper = shallow(<DataTableCell large />)
|
|
76
|
+
|
|
77
|
+
expect(wrapper.find(TableDataCell).prop('large')).toBe(true)
|
|
78
|
+
})
|
|
79
|
+
it('accepts a left prop', () => {
|
|
80
|
+
const left = '200px'
|
|
81
|
+
const wrapper = shallow(<DataTableCell left={left} />)
|
|
82
|
+
|
|
83
|
+
expect(wrapper.find(TableDataCell).prop('left')).toBe(left)
|
|
84
|
+
})
|
|
85
|
+
it('accepts a muted prop', () => {
|
|
86
|
+
const wrapper = shallow(<DataTableCell muted />)
|
|
87
|
+
|
|
88
|
+
expect(wrapper.find(TableDataCell).prop('muted')).toBe(true)
|
|
89
|
+
})
|
|
90
|
+
it('accepts a role prop', () => {
|
|
91
|
+
const role = 'test'
|
|
92
|
+
const wrapper = shallow(<DataTableCell role={role} />)
|
|
93
|
+
|
|
94
|
+
expect(wrapper.find(TableDataCell).prop('role')).toBe(role)
|
|
95
|
+
})
|
|
96
|
+
it('accepts a rowSpan prop', () => {
|
|
97
|
+
const rowSpan = '3'
|
|
98
|
+
const wrapper = shallow(<DataTableCell rowSpan={rowSpan} />)
|
|
99
|
+
|
|
100
|
+
expect(wrapper.find(TableDataCell).prop('rowSpan')).toBe(rowSpan)
|
|
101
|
+
})
|
|
102
|
+
it('accepts a scope prop', () => {
|
|
103
|
+
const scope = 'row'
|
|
104
|
+
const wrapper = shallow(<DataTableCell scope={scope} />)
|
|
105
|
+
|
|
106
|
+
expect(wrapper.find(TableDataCell).prop('scope')).toBe(scope)
|
|
107
|
+
})
|
|
108
|
+
it('accepts a staticStyle prop', () => {
|
|
109
|
+
const wrapper = shallow(<DataTableCell staticStyle />)
|
|
110
|
+
|
|
111
|
+
expect(wrapper.find(TableDataCell).prop('staticStyle')).toBe(true)
|
|
112
|
+
})
|
|
113
|
+
it('can render either a td or th tag depending on the fixed and tag prop', () => {
|
|
114
|
+
// default
|
|
115
|
+
expect(
|
|
116
|
+
shallow(<DataTableCell />)
|
|
117
|
+
.dive()
|
|
118
|
+
.type()
|
|
119
|
+
).toBe('td')
|
|
120
|
+
// using the tag prop
|
|
121
|
+
expect(
|
|
122
|
+
shallow(<DataTableCell tag="td" />)
|
|
123
|
+
.dive()
|
|
124
|
+
.type()
|
|
125
|
+
).toBe('td')
|
|
126
|
+
expect(
|
|
127
|
+
shallow(<DataTableCell tag="th" />)
|
|
128
|
+
.dive()
|
|
129
|
+
.type()
|
|
130
|
+
).toBe('th')
|
|
131
|
+
// with fixed prop
|
|
132
|
+
expect(
|
|
133
|
+
shallow(<DataTableCell fixed />)
|
|
134
|
+
.dive()
|
|
135
|
+
.type()
|
|
136
|
+
).toBe('th')
|
|
137
|
+
// tag prop should take presedence over fixed prop
|
|
138
|
+
expect(
|
|
139
|
+
shallow(<DataTableCell fixed tag="td" />)
|
|
140
|
+
.dive()
|
|
141
|
+
.type()
|
|
142
|
+
).toBe('td')
|
|
143
|
+
expect(
|
|
144
|
+
shallow(<DataTableCell fixed tag="th" />)
|
|
145
|
+
.dive()
|
|
146
|
+
.type()
|
|
147
|
+
).toBe('th')
|
|
148
|
+
})
|
|
149
|
+
it('accepts a valid prop', () => {
|
|
150
|
+
const wrapper = shallow(<DataTableCell valid />)
|
|
151
|
+
|
|
152
|
+
expect(wrapper.find(TableDataCell).prop('valid')).toBe(true)
|
|
153
|
+
})
|
|
154
|
+
it('accepts a width prop', () => {
|
|
155
|
+
const width = '200px'
|
|
156
|
+
const wrapper = shallow(<DataTableCell width={width} />)
|
|
157
|
+
|
|
158
|
+
expect(wrapper.find(TableDataCell).prop('width')).toBe(width)
|
|
159
|
+
})
|
|
160
|
+
it('accepts an onClick prop', () => {
|
|
161
|
+
const onClick = jest.fn()
|
|
162
|
+
const wrapper = shallow(<DataTableCell onClick={onClick} />)
|
|
163
|
+
|
|
164
|
+
wrapper.simulate('click')
|
|
165
|
+
|
|
166
|
+
expect(onClick).toHaveBeenCalledTimes(1)
|
|
167
|
+
})
|
|
168
|
+
})
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { colors } from '@dhis2/ui-constants'
|
|
2
|
+
import { IconSearch16 } from '@dhis2/ui-icons'
|
|
3
|
+
import { shallow } from 'enzyme'
|
|
4
|
+
import React from 'react'
|
|
5
|
+
import { FilterHandle } from '../../data-table-column-header/filter-handle.js'
|
|
6
|
+
import { TableHeaderCellAction } from '../../table-elements/index.js'
|
|
7
|
+
|
|
8
|
+
describe('<FilterHandle>', () => {
|
|
9
|
+
it('accepts an active prop', () => {
|
|
10
|
+
const wrapper = shallow(<FilterHandle />)
|
|
11
|
+
const wrapperActive = shallow(<FilterHandle active />)
|
|
12
|
+
|
|
13
|
+
expect(wrapper.find(IconSearch16).prop('color')).toBe(colors.grey600)
|
|
14
|
+
expect(wrapperActive.find(IconSearch16).prop('color')).toBe(
|
|
15
|
+
colors.blue700
|
|
16
|
+
)
|
|
17
|
+
})
|
|
18
|
+
it('accepts a name and onClick prop', () => {
|
|
19
|
+
const name = 'test'
|
|
20
|
+
const fakeEvent = {
|
|
21
|
+
target: 'test',
|
|
22
|
+
value: 'test',
|
|
23
|
+
}
|
|
24
|
+
const onClick = jest.fn()
|
|
25
|
+
const wrapper = shallow(<FilterHandle onClick={onClick} name={name} />)
|
|
26
|
+
|
|
27
|
+
wrapper
|
|
28
|
+
.find(TableHeaderCellAction)
|
|
29
|
+
.dive()
|
|
30
|
+
.find('button')
|
|
31
|
+
.simulate('click', fakeEvent)
|
|
32
|
+
|
|
33
|
+
expect(onClick).toHaveBeenCalledTimes(1)
|
|
34
|
+
expect(onClick).toHaveBeenCalledWith(
|
|
35
|
+
{
|
|
36
|
+
name,
|
|
37
|
+
// toggled
|
|
38
|
+
show: true,
|
|
39
|
+
},
|
|
40
|
+
fakeEvent
|
|
41
|
+
)
|
|
42
|
+
})
|
|
43
|
+
})
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { shallow } from 'enzyme'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
import { Sorter, ASC, DESC } from '../../data-table-column-header/sorter.js'
|
|
4
|
+
import { TableHeaderCellAction } from '../../table-elements/index.js'
|
|
5
|
+
|
|
6
|
+
describe('<Sorter>', () => {
|
|
7
|
+
it('accepts a sortDirection prop', () => {
|
|
8
|
+
const wrapper = shallow(<Sorter sortDirection={ASC} />)
|
|
9
|
+
|
|
10
|
+
expect(
|
|
11
|
+
wrapper.find(TableHeaderCellAction).dive().find('svg').hasClass(ASC)
|
|
12
|
+
).toBe(true)
|
|
13
|
+
})
|
|
14
|
+
it('accepts a name and onClick prop', () => {
|
|
15
|
+
const name = 'test'
|
|
16
|
+
const fakeEvent = {
|
|
17
|
+
target: 'test',
|
|
18
|
+
value: 'test',
|
|
19
|
+
}
|
|
20
|
+
const onClick = jest.fn()
|
|
21
|
+
const wrapper = shallow(
|
|
22
|
+
<Sorter sortDirection={ASC} onClick={onClick} name={name} />
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
wrapper
|
|
26
|
+
.find(TableHeaderCellAction)
|
|
27
|
+
.dive()
|
|
28
|
+
.find('button')
|
|
29
|
+
.simulate('click', fakeEvent)
|
|
30
|
+
|
|
31
|
+
expect(onClick).toHaveBeenCalledTimes(1)
|
|
32
|
+
expect(onClick).toHaveBeenCalledWith(
|
|
33
|
+
{
|
|
34
|
+
name,
|
|
35
|
+
// next sort direction
|
|
36
|
+
direction: DESC,
|
|
37
|
+
},
|
|
38
|
+
fakeEvent
|
|
39
|
+
)
|
|
40
|
+
})
|
|
41
|
+
})
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import { shallow, mount } from 'enzyme'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
import { DataTableColumnHeader } from '../data-table-column-header/data-table-column-header.js'
|
|
4
|
+
import { FilterHandle } from '../data-table-column-header/filter-handle.js'
|
|
5
|
+
import { Sorter } from '../data-table-column-header/sorter.js'
|
|
6
|
+
import {
|
|
7
|
+
TableHeaderCell,
|
|
8
|
+
TableHeaderCellAction,
|
|
9
|
+
} from '../table-elements/index.js'
|
|
10
|
+
|
|
11
|
+
describe('<DataTableColumnHeader>', () => {
|
|
12
|
+
it('renders children', () => {
|
|
13
|
+
const children = 'children'
|
|
14
|
+
const wrapper = shallow(
|
|
15
|
+
<DataTableColumnHeader>{children}</DataTableColumnHeader>
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
expect(wrapper.containsMatchingElement(children)).toBe(true)
|
|
19
|
+
})
|
|
20
|
+
it('accepts a ref', () => {
|
|
21
|
+
const ref = React.createRef()
|
|
22
|
+
const wrapper = mount(
|
|
23
|
+
<table>
|
|
24
|
+
<thead>
|
|
25
|
+
<tr>
|
|
26
|
+
<DataTableColumnHeader ref={ref} />
|
|
27
|
+
</tr>
|
|
28
|
+
</thead>
|
|
29
|
+
</table>
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
expect(wrapper.find('th').getDOMNode()).toBe(ref.current)
|
|
33
|
+
})
|
|
34
|
+
it('accepts an align prop', () => {
|
|
35
|
+
const right = 'right'
|
|
36
|
+
const wrapper = shallow(<DataTableColumnHeader align={right} />)
|
|
37
|
+
|
|
38
|
+
expect(wrapper.find(TableHeaderCell).prop('align')).toBe(right)
|
|
39
|
+
})
|
|
40
|
+
it('accepts a className prop', () => {
|
|
41
|
+
const wrapper = shallow(<DataTableColumnHeader className="test" />)
|
|
42
|
+
|
|
43
|
+
expect(wrapper.find(TableHeaderCell).prop('className')).toBe(
|
|
44
|
+
'test DataTableColumnHeader'
|
|
45
|
+
)
|
|
46
|
+
})
|
|
47
|
+
it('accepts a colSpan prop', () => {
|
|
48
|
+
const colSpan = '3'
|
|
49
|
+
const wrapper = shallow(<DataTableColumnHeader colSpan={colSpan} />)
|
|
50
|
+
|
|
51
|
+
expect(wrapper.find(TableHeaderCell).prop('colSpan')).toBe(colSpan)
|
|
52
|
+
})
|
|
53
|
+
it('accepts a dataTest prop', () => {
|
|
54
|
+
const dataTest = 'test'
|
|
55
|
+
const wrapper = shallow(<DataTableColumnHeader dataTest={dataTest} />)
|
|
56
|
+
|
|
57
|
+
expect(wrapper.find(TableHeaderCell).prop('dataTest')).toBe(dataTest)
|
|
58
|
+
})
|
|
59
|
+
it('accepts filter, name, showFilter and onFilterIconClick props', () => {
|
|
60
|
+
//
|
|
61
|
+
const name = 'test'
|
|
62
|
+
const fakeEvent = {
|
|
63
|
+
target: 'test',
|
|
64
|
+
value: 'test',
|
|
65
|
+
}
|
|
66
|
+
const onClickOpen = jest.fn()
|
|
67
|
+
const onClickClosed = jest.fn()
|
|
68
|
+
const wrapperOpen = shallow(
|
|
69
|
+
<DataTableColumnHeader
|
|
70
|
+
name={name}
|
|
71
|
+
onFilterIconClick={onClickOpen}
|
|
72
|
+
filter={<input />}
|
|
73
|
+
showFilter={true}
|
|
74
|
+
/>
|
|
75
|
+
)
|
|
76
|
+
const wrapperClosed = shallow(
|
|
77
|
+
<DataTableColumnHeader
|
|
78
|
+
name={name}
|
|
79
|
+
onFilterIconClick={onClickClosed}
|
|
80
|
+
filter={<input />}
|
|
81
|
+
showFilter={false}
|
|
82
|
+
/>
|
|
83
|
+
)
|
|
84
|
+
// Showing/hiding the filter
|
|
85
|
+
expect(wrapperOpen.find('input')).toHaveLength(1)
|
|
86
|
+
expect(wrapperClosed.find('input')).toHaveLength(0)
|
|
87
|
+
|
|
88
|
+
// Clicking the filter icon on
|
|
89
|
+
wrapperOpen
|
|
90
|
+
.find(FilterHandle)
|
|
91
|
+
.dive()
|
|
92
|
+
.find(TableHeaderCellAction)
|
|
93
|
+
.dive()
|
|
94
|
+
.find('button')
|
|
95
|
+
.simulate('click', fakeEvent)
|
|
96
|
+
|
|
97
|
+
expect(onClickOpen).toHaveBeenCalledTimes(1)
|
|
98
|
+
expect(onClickOpen).toHaveBeenCalledWith(
|
|
99
|
+
{
|
|
100
|
+
name,
|
|
101
|
+
// toggled
|
|
102
|
+
show: false,
|
|
103
|
+
},
|
|
104
|
+
fakeEvent
|
|
105
|
+
)
|
|
106
|
+
wrapperClosed
|
|
107
|
+
.find(FilterHandle)
|
|
108
|
+
.dive()
|
|
109
|
+
.find(TableHeaderCellAction)
|
|
110
|
+
.dive()
|
|
111
|
+
.find('button')
|
|
112
|
+
.simulate('click', fakeEvent)
|
|
113
|
+
|
|
114
|
+
expect(onClickClosed).toHaveBeenCalledTimes(1)
|
|
115
|
+
expect(onClickClosed).toHaveBeenCalledWith(
|
|
116
|
+
{
|
|
117
|
+
name,
|
|
118
|
+
// toggled
|
|
119
|
+
show: true,
|
|
120
|
+
},
|
|
121
|
+
fakeEvent
|
|
122
|
+
)
|
|
123
|
+
})
|
|
124
|
+
it('accepts a fixed prop', () => {
|
|
125
|
+
const wrapper = shallow(<DataTableColumnHeader fixed left="200px" />)
|
|
126
|
+
|
|
127
|
+
expect(wrapper.find(TableHeaderCell).prop('fixed')).toBe(true)
|
|
128
|
+
})
|
|
129
|
+
it('accepts a large prop', () => {
|
|
130
|
+
const wrapper = shallow(<DataTableColumnHeader large />)
|
|
131
|
+
|
|
132
|
+
expect(wrapper.find(TableHeaderCell).prop('large')).toBe(true)
|
|
133
|
+
})
|
|
134
|
+
it('accepts a left prop', () => {
|
|
135
|
+
const left = '200px'
|
|
136
|
+
const wrapper = shallow(<DataTableColumnHeader left={left} />)
|
|
137
|
+
|
|
138
|
+
expect(wrapper.find(TableHeaderCell).prop('left')).toBe(left)
|
|
139
|
+
})
|
|
140
|
+
it('accepts a role prop', () => {
|
|
141
|
+
const role = 'test'
|
|
142
|
+
const wrapper = shallow(<DataTableColumnHeader role={role} />)
|
|
143
|
+
|
|
144
|
+
expect(wrapper.find(TableHeaderCell).prop('role')).toBe(role)
|
|
145
|
+
})
|
|
146
|
+
it('accepts a rowSpan prop', () => {
|
|
147
|
+
const rowSpan = '3'
|
|
148
|
+
const wrapper = shallow(<DataTableColumnHeader rowSpan={rowSpan} />)
|
|
149
|
+
|
|
150
|
+
expect(wrapper.find(TableHeaderCell).prop('rowSpan')).toBe(rowSpan)
|
|
151
|
+
})
|
|
152
|
+
it('accepts a scope prop', () => {
|
|
153
|
+
const scope = 'row'
|
|
154
|
+
const wrapper = shallow(<DataTableColumnHeader scope={scope} />)
|
|
155
|
+
|
|
156
|
+
expect(wrapper.find(TableHeaderCell).prop('scope')).toBe(scope)
|
|
157
|
+
})
|
|
158
|
+
describe('column header sorting', () => {
|
|
159
|
+
it('accepts sortDirection, sortIconTitle, and onSortIconClick props', () => {
|
|
160
|
+
const name = 'test'
|
|
161
|
+
const title = 'Custom title'
|
|
162
|
+
const fakeEvent = {
|
|
163
|
+
target: 'test',
|
|
164
|
+
value: 'test',
|
|
165
|
+
}
|
|
166
|
+
const onClick = jest.fn()
|
|
167
|
+
const wrapper = shallow(
|
|
168
|
+
<DataTableColumnHeader
|
|
169
|
+
name={name}
|
|
170
|
+
onSortIconClick={onClick}
|
|
171
|
+
sortDirection={'asc'}
|
|
172
|
+
sortIconTitle={title}
|
|
173
|
+
/>
|
|
174
|
+
)
|
|
175
|
+
|
|
176
|
+
const button = wrapper
|
|
177
|
+
.find(Sorter)
|
|
178
|
+
.dive()
|
|
179
|
+
.find(TableHeaderCellAction)
|
|
180
|
+
.dive()
|
|
181
|
+
.find('button')
|
|
182
|
+
|
|
183
|
+
button.simulate('click', fakeEvent)
|
|
184
|
+
|
|
185
|
+
expect(onClick).toHaveBeenCalledTimes(1)
|
|
186
|
+
expect(onClick).toHaveBeenCalledWith(
|
|
187
|
+
{
|
|
188
|
+
name,
|
|
189
|
+
// next sort direction
|
|
190
|
+
direction: 'desc',
|
|
191
|
+
},
|
|
192
|
+
fakeEvent
|
|
193
|
+
)
|
|
194
|
+
expect(button.prop('title')).toBe(title)
|
|
195
|
+
})
|
|
196
|
+
it('has a default sort icon title', () => {
|
|
197
|
+
const wrapper = shallow(
|
|
198
|
+
<DataTableColumnHeader
|
|
199
|
+
name={'test'}
|
|
200
|
+
onSortIconClick={() => {}}
|
|
201
|
+
sortDirection={'asc'}
|
|
202
|
+
/>
|
|
203
|
+
)
|
|
204
|
+
|
|
205
|
+
const button = wrapper
|
|
206
|
+
.find(Sorter)
|
|
207
|
+
.dive()
|
|
208
|
+
.find(TableHeaderCellAction)
|
|
209
|
+
.dive()
|
|
210
|
+
.find('button')
|
|
211
|
+
|
|
212
|
+
expect(button.prop('title')).toBe('Sort items')
|
|
213
|
+
})
|
|
214
|
+
})
|
|
215
|
+
it('accepts a top prop', () => {
|
|
216
|
+
const top = '200px'
|
|
217
|
+
const wrapper = shallow(<DataTableColumnHeader top={top} />)
|
|
218
|
+
|
|
219
|
+
expect(wrapper.find(TableHeaderCell).prop('top')).toBe(top)
|
|
220
|
+
})
|
|
221
|
+
it('accepts a width prop', () => {
|
|
222
|
+
const width = '200px'
|
|
223
|
+
const wrapper = shallow(<DataTableColumnHeader width={width} />)
|
|
224
|
+
|
|
225
|
+
expect(wrapper.find(TableHeaderCell).prop('width')).toBe(width)
|
|
226
|
+
})
|
|
227
|
+
})
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { IconChevronDown24, IconChevronUp24 } from '@dhis2/ui-icons'
|
|
2
|
+
import { shallow } from 'enzyme'
|
|
3
|
+
import React from 'react'
|
|
4
|
+
import { ExpandHandleCell } from '../../data-table-row/expand-handle-cell.js'
|
|
5
|
+
|
|
6
|
+
describe('<ExpandHandleCell>', () => {
|
|
7
|
+
it('renders an <IconChevronUp24> when expanded is true', () => {
|
|
8
|
+
const wrapper = shallow(<ExpandHandleCell expanded />)
|
|
9
|
+
|
|
10
|
+
expect(wrapper.find(IconChevronUp24)).toHaveLength(1)
|
|
11
|
+
expect(wrapper.find(IconChevronDown24)).toHaveLength(0)
|
|
12
|
+
})
|
|
13
|
+
it('renders an <IconChevronDown24> when expanded is falsy', () => {
|
|
14
|
+
const wrapper = shallow(<ExpandHandleCell />)
|
|
15
|
+
|
|
16
|
+
expect(wrapper.find(IconChevronUp24)).toHaveLength(0)
|
|
17
|
+
expect(wrapper.find(IconChevronDown24)).toHaveLength(1)
|
|
18
|
+
})
|
|
19
|
+
it('responds to clicks', () => {
|
|
20
|
+
const onClick = jest.fn()
|
|
21
|
+
const wrapper = shallow(
|
|
22
|
+
<ExpandHandleCell expanded={false} onClick={onClick} />
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
wrapper.simulate('click')
|
|
26
|
+
|
|
27
|
+
expect(onClick).toHaveBeenCalledTimes(1)
|
|
28
|
+
expect(onClick).toHaveBeenCalledWith({
|
|
29
|
+
expanded: true,
|
|
30
|
+
})
|
|
31
|
+
})
|
|
32
|
+
})
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { shallow } from 'enzyme'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
import { ExpandedRow } from '../../data-table-row/expanded-row.js'
|
|
4
|
+
import { TableRow, TableDataCell } from '../../table-elements/index.js'
|
|
5
|
+
|
|
6
|
+
describe('<ExpandedRow>', () => {
|
|
7
|
+
it('renders children', () => {
|
|
8
|
+
const children = 'children'
|
|
9
|
+
const wrapper = shallow(<ExpandedRow>{children}</ExpandedRow>)
|
|
10
|
+
|
|
11
|
+
expect(wrapper.containsMatchingElement(children)).toBe(true)
|
|
12
|
+
})
|
|
13
|
+
it('accepts a colSpan prop', () => {
|
|
14
|
+
const colSpan = '4'
|
|
15
|
+
const wrapper = shallow(<ExpandedRow colSpan={colSpan} />)
|
|
16
|
+
|
|
17
|
+
expect(wrapper.find(TableDataCell).prop('colSpan')).toBe(colSpan)
|
|
18
|
+
})
|
|
19
|
+
it('accepts a className prop', () => {
|
|
20
|
+
const className = 'test'
|
|
21
|
+
const wrapper = shallow(<ExpandedRow className={className} />)
|
|
22
|
+
|
|
23
|
+
expect(wrapper.find(TableRow).prop('className')).toBe(
|
|
24
|
+
`${className}-expandedrow`
|
|
25
|
+
)
|
|
26
|
+
})
|
|
27
|
+
it('accepts a dataTest prop', () => {
|
|
28
|
+
const dataTest = 'test'
|
|
29
|
+
const wrapper = shallow(<ExpandedRow dataTest={dataTest} />)
|
|
30
|
+
|
|
31
|
+
expect(wrapper.find(TableRow).prop('dataTest')).toBe(
|
|
32
|
+
`${dataTest}-expandedrow`
|
|
33
|
+
)
|
|
34
|
+
})
|
|
35
|
+
it('accepts a selected prop', () => {
|
|
36
|
+
const wrapper = shallow(<ExpandedRow selected />)
|
|
37
|
+
|
|
38
|
+
expect(wrapper.find(TableRow).prop('selected')).toBe(true)
|
|
39
|
+
})
|
|
40
|
+
it('accepts a setIsHoveringExpandedContent prop', () => {
|
|
41
|
+
const cb = jest.fn()
|
|
42
|
+
const wrapper = shallow(
|
|
43
|
+
<ExpandedRow setIsHoveringExpandedContent={cb} />
|
|
44
|
+
)
|
|
45
|
+
const tr = wrapper.find(TableRow).dive().find('tr')
|
|
46
|
+
|
|
47
|
+
tr.simulate('mouseover')
|
|
48
|
+
|
|
49
|
+
expect(cb).toHaveBeenCalledTimes(1)
|
|
50
|
+
expect(cb).toHaveBeenLastCalledWith(true)
|
|
51
|
+
|
|
52
|
+
tr.simulate('mouseout')
|
|
53
|
+
|
|
54
|
+
expect(cb).toHaveBeenCalledTimes(2)
|
|
55
|
+
expect(cb).toHaveBeenLastCalledWith(false)
|
|
56
|
+
})
|
|
57
|
+
})
|