1
|
|
|
import { shallow, ShallowWrapper } from 'enzyme'; |
2
|
|
|
import { Mock } from 'ts-mockery'; |
3
|
|
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; |
4
|
|
|
import { ShortUrlsTable as shortUrlsTableCreator } from '../../src/short-urls/ShortUrlsTable'; |
5
|
|
|
import { SORTABLE_FIELDS } from '../../src/short-urls/reducers/shortUrlsListParams'; |
6
|
|
|
import { ShortUrlsList } from '../../src/short-urls/reducers/shortUrlsList'; |
7
|
|
|
|
8
|
|
|
describe('<ShortUrlsTable />', () => { |
9
|
|
|
let wrapper: ShallowWrapper; |
10
|
|
|
const shortUrlsList = Mock.all<ShortUrlsList>(); |
11
|
|
|
const orderByColumn = jest.fn(); |
12
|
|
|
const ShortUrlsRow = () => null; |
13
|
|
|
|
14
|
|
|
const ShortUrlsTable = shortUrlsTableCreator(ShortUrlsRow); |
15
|
|
|
|
16
|
|
|
beforeEach(() => { |
17
|
|
|
wrapper = shallow( |
18
|
|
|
<ShortUrlsTable shortUrlsList={shortUrlsList} selectedServer={null} orderByColumn={() => orderByColumn} />, |
19
|
|
|
); |
20
|
|
|
}); |
21
|
|
|
|
22
|
|
|
afterEach(jest.resetAllMocks); |
23
|
|
|
afterEach(() => wrapper?.unmount()); |
24
|
|
|
|
25
|
|
|
it('should render inner table by default', () => { |
26
|
|
|
expect(wrapper.find('table')).toHaveLength(1); |
27
|
|
|
}); |
28
|
|
|
|
29
|
|
|
it('should render table header by default', () => { |
30
|
|
|
expect(wrapper.find('table').find('thead')).toHaveLength(1); |
31
|
|
|
}); |
32
|
|
|
|
33
|
|
|
it('should render 6 table header cells by default', () => { |
34
|
|
|
expect(wrapper.find('table').find('thead').find('tr').find('th')).toHaveLength(6); |
35
|
|
|
}); |
36
|
|
|
|
37
|
|
|
it('should render 6 table header cells without order by icon by default', () => { |
38
|
|
|
const thElements = wrapper.find('table').find('thead').find('tr').find('th'); |
39
|
|
|
|
40
|
|
|
thElements.forEach((thElement) => { |
41
|
|
|
expect(thElement.find(FontAwesomeIcon)).toHaveLength(0); |
42
|
|
|
}); |
43
|
|
|
}); |
44
|
|
|
|
45
|
|
|
it('should render 6 table header cells with conditional order by icon', () => { |
46
|
|
|
const getThElementForSortableField = (sortableField: string) => wrapper.find('table') |
47
|
|
|
.find('thead') |
48
|
|
|
.find('tr') |
49
|
|
|
.find('th') |
50
|
|
|
.filterWhere((e) => e.text().includes(SORTABLE_FIELDS[sortableField as keyof typeof SORTABLE_FIELDS])); |
51
|
|
|
const sortableFields = Object.keys(SORTABLE_FIELDS); |
52
|
|
|
|
53
|
|
|
expect.assertions(sortableFields.length); |
54
|
|
|
sortableFields.forEach((sortableField) => { |
55
|
|
|
getThElementForSortableField(sortableField).simulate('click'); |
56
|
|
|
expect(orderByColumn).toHaveBeenCalled(); |
57
|
|
|
}); |
58
|
|
|
}); |
59
|
|
|
}); |
60
|
|
|
|