Skip to content

Commit afdb5c3

Browse files
test(shared table + searchmembers): replace snapshots tests by manual tests
1 parent 1ad10ff commit afdb5c3

File tree

16 files changed

+93
-526
lines changed

16 files changed

+93
-526
lines changed

src/pages/Demos/SearchMembers/__tests__/SearchMembers.test.tsx

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { screen } from '@testing-library/react';
22
import { MODES } from 'shared/components/Loader';
33
import { emptyFunction, render } from 'shared/testsUtils';
4-
import SearchMembers, { getDownloadPath, setFileName, DownloadLinkEnhanced } from '../SearchMembers';
4+
import SearchMembers, { DownloadLinkEnhanced, getDownloadPath, setFileName } from '../SearchMembers';
55

66
describe('getDownloadPath', () => {
77
it('Should return "members/0064962455/download-detail" When getDownloadPath with memberId "0064962455"', () => {
@@ -40,18 +40,11 @@ describe('<DownloadLinkEnhanced />', () => {
4040
firstname: 'samuel',
4141
lastname: 'gomez',
4242
};
43-
it('Should call getDownloadPathFn and setFileNameFn with proper params', () => {
44-
const { asFragment } = render(
45-
<DownloadLinkEnhanced {...defaultDownloadProps} getDownloadPathFn={getDownloadPathFnMock} setFileNameFn={setFileNameFnMock} />,
46-
);
47-
expect(asFragment()).toMatchSnapshot();
48-
expect(getDownloadPathFnMock).toBeCalledWith('09878817');
49-
expect(setFileNameFnMock).toBeCalledWith({ memberId: '09878817', name: 'samuel-gomez' });
50-
});
5143

52-
it('Should call getDownloadPathFn and setFileNameFn with proper params 2 ', () => {
53-
const { asFragment } = render(<DownloadLinkEnhanced {...defaultDownloadProps} />);
54-
expect(asFragment()).toMatchSnapshot();
44+
it('Should call getDownloadPathFn and setFileNameFn with proper params', () => {
45+
render(<DownloadLinkEnhanced {...defaultDownloadProps} getDownloadPathFn={getDownloadPathFnMock} setFileNameFn={setFileNameFnMock} />);
46+
expect(getDownloadPathFnMock).toHaveBeenCalledWith('09878817');
47+
expect(setFileNameFnMock).toHaveBeenCalledWith({ memberId: '09878817', name: 'samuel-gomez' });
5548
});
5649
});
5750

src/pages/Demos/SearchMembers/__tests__/__snapshots__/SearchMembers.test.tsx.snap

Lines changed: 0 additions & 59 deletions
This file was deleted.

src/shared/components/Table/Body/Line/Td/__tests__/Td.test.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,21 @@ const defaultProps = {
66
label: 'label',
77
hover: null,
88
};
9-
const container = document.createElement('tr');
9+
const trContainer = document.createElement('tr');
1010

1111
describe('Td', () => {
1212
it('Render <Td/> without hover', () => {
13-
const { asFragment } = renderWithContainer(<Td {...defaultProps}>child th</Td>, container);
14-
expect(asFragment()).toMatchSnapshot();
13+
const { container } = renderWithContainer(<Td {...defaultProps}>child th</Td>, trContainer);
14+
expect(container.firstChild?.firstChild?.textContent).toBe('label');
1515
});
16+
1617
it('Render <Td/> with hover', () => {
17-
const { asFragment } = renderWithContainer(
18+
const { container } = renderWithContainer(
1819
<Td {...defaultProps} classModifier="custom" hover={<p>Hover content</p>}>
1920
child td
2021
</Td>,
21-
container,
22+
trContainer,
2223
);
23-
expect(asFragment()).toMatchSnapshot();
24+
expect(container.firstChild?.firstChild).toHaveClass('af-popover__wrapper');
2425
});
2526
});

src/shared/components/Table/Body/Line/Td/__tests__/__snapshots__/Td.test.tsx.snap

Lines changed: 0 additions & 26 deletions
This file was deleted.
Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { renderWithContainer } from 'shared/testsUtils';
2+
import { within } from 'shared/testsUtils/customRender';
23
import Line from '../Line';
34

4-
const container = document.createElement('tbody');
5+
const tbodyContainer = document.createElement('tbody');
56

67
const columnsMock = [
78
{
@@ -11,25 +12,32 @@ const columnsMock = [
1112
},
1213
];
1314

14-
const itemsType = 'users';
15-
1615
describe('Line', () => {
1716
it.each`
18-
columns | className | modifier | children | lineNumber
19-
${undefined} | ${undefined} | ${undefined} | ${undefined} | ${1}
20-
${[]} | ${undefined} | ${undefined} | ${undefined} | ${2}
21-
${columnsMock} | ${undefined} | ${undefined} | ${undefined} | ${3}
22-
${columnsMock} | ${undefined} | ${'modifier'} | ${undefined} | ${4}
17+
columns | className | modifier | children
18+
${undefined} | ${undefined} | ${undefined} | ${undefined}
19+
${[]} | ${undefined} | ${undefined} | ${undefined}
20+
${columnsMock} | ${undefined} | ${undefined} | ${undefined}
21+
${columnsMock} | ${undefined} | ${'modifier'} | ${undefined}
2322
`(
24-
'Should render <Line/> when columns: $columns, className: $className, modifier: $modifier, children: $children, lineNumber: $lineNumber',
25-
({ columns, className, modifier, children, lineNumber }) => {
26-
const { baseElement } = renderWithContainer(
27-
<Line className={className} itemsType={itemsType} lineNumber={lineNumber} columns={columns} classModifier={modifier}>
23+
'Should render <Line/> when columns: $columns, className: $className, modifier: $modifier, children: $children',
24+
({ columns, className, modifier, children }) => {
25+
const { baseElement, container } = renderWithContainer(
26+
<Line className={className} columns={columns} classModifier={modifier}>
2827
{children}
2928
</Line>,
30-
container,
29+
tbodyContainer,
3130
);
32-
expect(baseElement).toMatchSnapshot();
31+
32+
if (columns && columns.length > 0) {
33+
within(baseElement).getByText('F');
34+
} else {
35+
expect(within(baseElement).queryByText('F')).toBeNull();
36+
}
37+
38+
if (modifier) {
39+
expect(container.firstChild).toHaveClass('af-table__tr--modifier');
40+
}
3341
},
3442
);
3543
});

src/shared/components/Table/Body/Line/__tests__/__snapshots__/Line.test.tsx.snap

Lines changed: 0 additions & 45 deletions
This file was deleted.

src/shared/components/Table/Body/__tests__/Body.test.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { renderWithContainer } from 'shared/testsUtils';
2+
import { screen, within } from 'shared/testsUtils/customRender';
23
import Body from '../Body';
34

45
const container = document.createElement('table');
56

67
describe('Body', () => {
78
it('Render <Body/> with empty items', () => {
8-
const { baseElement } = renderWithContainer(<Body />, container);
9-
expect(baseElement).toMatchSnapshot();
9+
renderWithContainer(<Body />, container);
10+
expect(screen.queryAllByRole('row').length).toBe(0);
1011
});
1112

1213
const items = [
@@ -23,6 +24,10 @@ describe('Body', () => {
2324

2425
it('Render <Body/> with 1 item', () => {
2526
const { baseElement } = renderWithContainer(<Body items={items} />, container);
26-
expect(baseElement).toMatchSnapshot();
27+
expect(screen.getAllByRole('row').length).toBe(1);
28+
within(baseElement).getByText(items[0].cols.firstname.label);
29+
within(baseElement).getByText(items[0].cols.lastname.label);
30+
within(baseElement).getByText(items[0].cols.birthdate.label);
31+
within(baseElement).getByText(items[0].cols.sexe.label);
2732
});
2833
});

src/shared/components/Table/Body/__tests__/__snapshots__/Body.test.tsx.snap

Lines changed: 0 additions & 42 deletions
This file was deleted.

src/shared/components/Table/Header/Th/ThSortable/__tests__/SortingIcon.test.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ describe('orderIcons', () => {
1717

1818
describe('SortingIcon', () => {
1919
it('Should render SortingIcon with order equal NONE', () => {
20-
const { asFragment } = render(<SortingIcon />);
21-
expect(asFragment()).toMatchSnapshot();
20+
const { container } = render(<SortingIcon />);
21+
expect(container.querySelector('span')).toHaveClass('glyphicon-sorting');
2222
});
2323

2424
it('Should render SortingIcon with order equal 1', () => {
25-
const { asFragment } = render(<SortingIcon order={1} />);
26-
expect(asFragment()).toMatchSnapshot();
25+
const { container } = render(<SortingIcon order={1} />);
26+
expect(container.querySelector('span')).toHaveClass('glyphicon-arrow-xs-up');
2727
});
2828
it('Should render SortingIcon with order equal -1', () => {
29-
const { asFragment } = render(<SortingIcon order={-1} />);
30-
expect(asFragment()).toMatchSnapshot();
29+
const { container } = render(<SortingIcon order={-1} />);
30+
expect(container.querySelector('span')).toHaveClass('glyphicon-arrow-xs-down');
3131
});
3232
});
Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { renderWithContainer } from 'shared/testsUtils';
2+
import { within } from 'shared/testsUtils/customRender';
3+
import { orderIcons } from '../SortingIcon';
24
import ThSortable from '../ThSortable';
35

46
const defaultProps = {
57
sort: vi.fn(),
68
};
7-
const container = document.createElement('tr');
9+
const trContainer = document.createElement('tr');
810

911
describe('ThSortable', () => {
1012
it.each`
@@ -17,15 +19,19 @@ describe('ThSortable', () => {
1719
${-1} | ${'child'} | ${'variant'}
1820
`(
1921
'Should render <ThSortable/> when order: $order, children: $children, className: $className, classModifier: $classModifier',
20-
({ children, ...rest }) => {
21-
const { baseElement } = renderWithContainer(
22-
<ThSortable {...defaultProps} {...rest}>
22+
({ order, children, ...rest }) => {
23+
const { baseElement, container } = renderWithContainer(
24+
<ThSortable {...defaultProps} {...rest} order={order}>
2325
{children}
2426
</ThSortable>,
25-
container,
27+
trContainer,
2628
);
2729

28-
expect(baseElement).toMatchSnapshot();
30+
expect(container.querySelector('span')).toHaveClass(`glyphicon-${orderIcons(order)}`);
31+
32+
if (children) {
33+
within(baseElement).getByText(children);
34+
}
2935
},
3036
);
3137
});

0 commit comments

Comments
 (0)