Skip to content

Commit 8ebb713

Browse files
test(design-system): add tests for table component [AR-46651] (#131)
[Jira](AR-46651-add-tests-for-components-with-zero-coverage) ### Improvements for Table's stories - Broke down stories into multiple files. There used to be a single 1000 lines file. - Added tests to majority of stories - Isolated storybook related files into stories folder Note: stories itself are not changed.
1 parent ea528b9 commit 8ebb713

19 files changed

Lines changed: 1424 additions & 1023 deletions

packages/design-system/src/components/ds-table/ds-table.stories.tsx

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

packages/design-system/src/components/ds-table/utils/story-data-generator.ts renamed to packages/design-system/src/components/ds-table/stories/common/story-data-generator.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
11
import type { SortingState } from '@tanstack/react-table';
2-
import type { Status } from '../ds-table.stories';
3-
4-
export type Person = {
5-
id: string;
6-
firstName: string;
7-
lastName: string;
8-
age: number;
9-
visits: number;
10-
status: Status;
11-
progress: number;
12-
};
2+
import type { Person, Status } from './story-data';
133

144
export interface GeneratedDataResult {
155
data: Person[];
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
import type { ColumnDef } from '@tanstack/react-table';
2+
3+
export type Status = 'relationship' | 'complicated' | 'single';
4+
5+
export type Person = {
6+
id: string;
7+
firstName: string;
8+
lastName: string;
9+
age: number;
10+
visits: number;
11+
status: Status;
12+
progress: number;
13+
};
14+
15+
export const columns: ColumnDef<Person>[] = [
16+
{
17+
accessorKey: 'firstName',
18+
header: 'First Name',
19+
cell: (info) => info.getValue(),
20+
},
21+
{
22+
accessorKey: 'lastName',
23+
header: 'Last Name',
24+
cell: (info) => info.getValue(),
25+
},
26+
{
27+
accessorKey: 'age',
28+
header: 'Age',
29+
cell: (info) => info.getValue(),
30+
},
31+
{
32+
accessorKey: 'visits',
33+
header: 'Visits',
34+
cell: (info) => info.getValue(),
35+
},
36+
{
37+
accessorKey: 'status',
38+
header: 'Status',
39+
cell: (info) => info.getValue(),
40+
},
41+
{
42+
accessorKey: 'progress',
43+
header: 'Profile Progress',
44+
cell: (info) => `${String(info.getValue())}%`,
45+
},
46+
];
47+
48+
export const defaultData: Person[] = [
49+
{
50+
id: '1',
51+
firstName: 'Tanner',
52+
lastName: 'Linsley',
53+
age: 33,
54+
visits: 100,
55+
status: 'single',
56+
progress: 75,
57+
},
58+
{
59+
id: '2',
60+
firstName: 'Kevin',
61+
lastName: 'Fine',
62+
age: 28,
63+
visits: 200,
64+
status: 'relationship',
65+
progress: 50,
66+
},
67+
{
68+
id: '3',
69+
firstName: 'John',
70+
lastName: 'Doe',
71+
age: 45,
72+
visits: 50,
73+
status: 'complicated',
74+
progress: 90,
75+
},
76+
{
77+
id: '4',
78+
firstName: 'Jane',
79+
lastName: 'Smith',
80+
age: 30,
81+
visits: 150,
82+
status: 'single',
83+
progress: 60,
84+
},
85+
{
86+
id: '5',
87+
firstName: 'Peter',
88+
lastName: 'Jones',
89+
age: 22,
90+
visits: 250,
91+
status: 'relationship',
92+
progress: 30,
93+
},
94+
{
95+
id: '6',
96+
firstName: 'Mary',
97+
lastName: 'Jane',
98+
age: 38,
99+
visits: 80,
100+
status: 'complicated',
101+
progress: 85,
102+
},
103+
{
104+
id: '7',
105+
firstName: 'David',
106+
lastName: 'Williams',
107+
age: 50,
108+
visits: 120,
109+
status: 'single',
110+
progress: 40,
111+
},
112+
{
113+
id: '8',
114+
firstName: 'Sarah',
115+
lastName: 'Brown',
116+
age: 25,
117+
visits: 180,
118+
status: 'relationship',
119+
progress: 70,
120+
},
121+
{
122+
id: '9',
123+
firstName: 'Michael',
124+
lastName: 'Davis',
125+
age: 41,
126+
visits: 95,
127+
status: 'complicated',
128+
progress: 20,
129+
},
130+
{
131+
id: '10',
132+
firstName: 'Emily',
133+
lastName: 'Miller',
134+
age: 36,
135+
visits: 110,
136+
status: 'single',
137+
progress: 55,
138+
},
139+
{
140+
id: '11',
141+
firstName: 'Daniel',
142+
lastName: 'Wilson',
143+
age: 29,
144+
visits: 220,
145+
status: 'relationship',
146+
progress: 80,
147+
},
148+
{
149+
id: '12',
150+
firstName: 'Olivia',
151+
lastName: 'Moore',
152+
age: 48,
153+
visits: 65,
154+
status: 'complicated',
155+
progress: 15,
156+
},
157+
{
158+
id: '13',
159+
firstName: 'James',
160+
lastName: 'Taylor',
161+
age: 31,
162+
visits: 135,
163+
status: 'single',
164+
progress: 95,
165+
},
166+
{
167+
id: '14',
168+
firstName: 'Sophia',
169+
lastName: 'Anderson',
170+
age: 27,
171+
visits: 170,
172+
status: 'relationship',
173+
progress: 25,
174+
},
175+
{
176+
id: '15',
177+
firstName: 'Robert',
178+
lastName: 'Thomas',
179+
age: 43,
180+
visits: 88,
181+
status: 'complicated',
182+
progress: 50,
183+
},
184+
];
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import type { ReactNode } from 'react';
2+
3+
import styles from '../ds-table.stories.module.scss';
4+
5+
export const fullHeightDecorator = (Story: () => ReactNode) => (
6+
<div className={styles.storyPadding}>
7+
<style>
8+
{`
9+
#storybook-root, html, body { height: 100%; }
10+
`}
11+
</style>
12+
<Story />
13+
</div>
14+
);
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import type { StoryContext } from '@storybook/react-vite';
2+
3+
export const getDataRows = (canvas: StoryContext['canvas']) =>
4+
canvas.getAllByRole('row').filter((row: HTMLElement) => !row.querySelector('th'));
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export * from './progress-infographic/progress-infographic';
2+
export * from './status-item/status-item';
3+
export * from './table-empty-state/table-empty-state';
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
.progressInfographic {
2+
width: 100%;
3+
height: 20px;
4+
background-color: var(--neutral-10);
5+
border-radius: 4px;
6+
overflow: hidden;
7+
border: 1px solid var(--neutral-6);
8+
9+
& > .bar {
10+
height: 100%;
11+
display: flex;
12+
align-items: center;
13+
justify-content: center;
14+
color: white;
15+
font-size: 10px;
16+
font-weight: bold;
17+
transition: width 0.3s ease-in-out;
18+
19+
&--low {
20+
background-color: var(--system-status-error);
21+
}
22+
23+
&--medium {
24+
background-color: var(--system-status-info);
25+
}
26+
27+
&--high {
28+
background-color: var(--system-status-ok);
29+
}
30+
}
31+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import classnames from 'classnames';
2+
import styles from './progress-infographic.module.scss';
3+
4+
export const ProgressInfographic = ({ value }: { value: number }) => {
5+
const barClass = classnames(styles.bar, {
6+
[styles['bar--high']]: value > 70,
7+
[styles['bar--medium']]: value > 40 && value <= 70,
8+
[styles['bar--low']]: value <= 40,
9+
});
10+
11+
return (
12+
<div className={styles.progressInfographic}>
13+
<div className={barClass} style={{ width: `${String(value)}%` }}>
14+
{value}%
15+
</div>
16+
</div>
17+
);
18+
};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.emptyStateContainer {
2+
padding: 20px;
3+
text-align: center;
4+
border: 1px dashed #ccc;
5+
height: 100%;
6+
7+
&__text {
8+
margin-top: 10px;
9+
}
10+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import styles from './table-empty-state.module.scss';
2+
import DsIcon from '../../../../ds-icon/ds-icon';
3+
4+
export const TableEmptyState = () => {
5+
return (
6+
<div className={styles.emptyStateContainer}>
7+
<DsIcon icon="info" size="large" />
8+
<p className={styles.emptyStateContainer__text}>No matching records found.</p>
9+
</div>
10+
);
11+
};

0 commit comments

Comments
 (0)