@popsure/dirty-swan 0.54.1 → 0.54.2

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.
Files changed (61) hide show
  1. package/dist/cjs/index.js +21 -21
  2. package/dist/cjs/index.js.map +1 -1
  3. package/dist/cjs/lib/components/table/Table.d.ts +3 -4
  4. package/dist/cjs/lib/components/table/Table.stories.d.ts +5 -4
  5. package/dist/cjs/lib/components/table/components/TableContents/TableContents.d.ts +13 -0
  6. package/dist/cjs/lib/components/table/components/TableSection/TableSection.d.ts +6 -17
  7. package/dist/cjs/lib/components/table/types.d.ts +6 -4
  8. package/dist/esm/{Collapsible-ac67187a.js → Collapsible-a355828b.js} +1 -1
  9. package/dist/esm/Collapsible-a355828b.js.map +1 -0
  10. package/dist/esm/components/table/Table.js +7 -7
  11. package/dist/esm/components/table/Table.js.map +1 -1
  12. package/dist/esm/components/table/Table.stories.js +9 -9
  13. package/dist/esm/components/table/Table.stories.js.map +1 -1
  14. package/dist/esm/components/table/Table.test.js +13 -13
  15. package/dist/esm/components/table/Table.test.js.map +1 -1
  16. package/dist/esm/components/table/components/TableCell/TableCell.js +1 -1
  17. package/dist/esm/components/table/components/{TableSection → TableContents}/Collapsible.js +1 -1
  18. package/dist/esm/components/table/components/TableContents/TableContents.js +56 -0
  19. package/dist/esm/components/table/components/TableContents/TableContents.js.map +1 -0
  20. package/dist/esm/components/table/components/TableContents/TableContents.test.js +82 -0
  21. package/dist/esm/components/table/components/TableContents/TableContents.test.js.map +1 -0
  22. package/dist/esm/components/table/components/TableControls/TableControls.js +1 -1
  23. package/dist/esm/components/table/components/TableSection/TableSection.js +41 -38
  24. package/dist/esm/components/table/components/TableSection/TableSection.js.map +1 -1
  25. package/dist/esm/components/table/components/TableSection/TableSection.test.js +34 -56
  26. package/dist/esm/components/table/components/TableSection/TableSection.test.js.map +1 -1
  27. package/dist/esm/index.js +2 -2
  28. package/dist/esm/lib/components/table/Table.d.ts +3 -4
  29. package/dist/esm/lib/components/table/Table.stories.d.ts +5 -4
  30. package/dist/esm/lib/components/table/components/TableContents/TableContents.d.ts +13 -0
  31. package/dist/esm/lib/components/table/components/TableSection/TableSection.d.ts +6 -17
  32. package/dist/esm/lib/components/table/types.d.ts +6 -4
  33. package/package.json +1 -1
  34. package/src/lib/components/table/Table.stories.tsx +13 -13
  35. package/src/lib/components/table/Table.test.tsx +11 -11
  36. package/src/lib/components/table/Table.tsx +11 -13
  37. package/src/lib/components/table/components/TableCell/TableCell.module.scss +1 -0
  38. package/src/lib/components/table/components/TableContents/TableContents.module.scss +10 -0
  39. package/src/lib/components/table/components/TableContents/TableContents.test.tsx +86 -0
  40. package/src/lib/components/table/components/TableContents/TableContents.tsx +106 -0
  41. package/src/lib/components/table/components/TableControls/TableControls.module.scss +2 -1
  42. package/src/lib/components/table/components/TableSection/TableSection.module.scss +13 -8
  43. package/src/lib/components/table/components/TableSection/TableSection.test.tsx +38 -64
  44. package/src/lib/components/table/components/TableSection/TableSection.tsx +97 -94
  45. package/src/lib/components/table/types.ts +8 -4
  46. package/dist/cjs/lib/components/table/components/TableContent/TableContent.d.ts +0 -13
  47. package/dist/esm/Collapsible-ac67187a.js.map +0 -1
  48. package/dist/esm/components/table/components/TableContent/TableContent.js +0 -59
  49. package/dist/esm/components/table/components/TableContent/TableContent.js.map +0 -1
  50. package/dist/esm/components/table/components/TableContent/TableContent.test.js +0 -60
  51. package/dist/esm/components/table/components/TableContent/TableContent.test.js.map +0 -1
  52. package/dist/esm/lib/components/table/components/TableContent/TableContent.d.ts +0 -13
  53. package/src/lib/components/table/components/TableContent/TableContent.module.scss +0 -15
  54. package/src/lib/components/table/components/TableContent/TableContent.test.tsx +0 -56
  55. package/src/lib/components/table/components/TableContent/TableContent.tsx +0 -121
  56. /package/dist/cjs/lib/components/table/components/{TableSection → TableContents}/Collapsible.d.ts +0 -0
  57. /package/dist/cjs/lib/components/table/components/{TableContent/TableContent.test.d.ts → TableContents/TableContents.test.d.ts} +0 -0
  58. /package/dist/esm/components/table/components/{TableSection → TableContents}/Collapsible.js.map +0 -0
  59. /package/dist/esm/lib/components/table/components/{TableSection → TableContents}/Collapsible.d.ts +0 -0
  60. /package/dist/esm/lib/components/table/components/{TableContent/TableContent.test.d.ts → TableContents/TableContents.test.d.ts} +0 -0
  61. /package/src/lib/components/table/components/{TableSection → TableContents}/Collapsible.tsx +0 -0
@@ -1,9 +1,10 @@
1
- import { Table, TableData, TableProps } from './Table';
1
+ import { Table, TableProps } from './Table';
2
2
  import { DentalPlusIcon, PlaneIcon } from '../icon';
3
+ import { TableData } from './types';
3
4
 
4
5
  const initialData: TableData = [
5
6
  {
6
- items: [
7
+ rows: [
7
8
  [
8
9
  { content: 'Our plans' },
9
10
  { content: 'Surgery', modalContent: 'More info on surgery' },
@@ -41,7 +42,7 @@ const initialData: TableData = [
41
42
  icon: <DentalPlusIcon size={24} noMargin />,
42
43
  title: 'Dental',
43
44
  },
44
- items: [
45
+ rows: [
45
46
  [
46
47
  { content: 'Regular vet visits & medication' },
47
48
  { content: 'No' },
@@ -67,7 +68,7 @@ const initialData: TableData = [
67
68
  title: 'Travel',
68
69
  icon: <PlaneIcon size={24} noMargin />,
69
70
  },
70
- items: [
71
+ rows: [
71
72
  [
72
73
  { content: 'Regular vet visits & medication' },
73
74
  { content: 'No', checkmarkValue: false },
@@ -136,7 +137,7 @@ const story = {
136
137
  },
137
138
  },
138
139
  args: {
139
- data: initialData,
140
+ tableData: initialData,
140
141
  collapsibleSections: false,
141
142
  hideDetails: false,
142
143
  stickyHeaderTopOffset: 0,
@@ -151,7 +152,7 @@ const story = {
151
152
 
152
153
  export const TableStory = ({
153
154
  collapsibleSections,
154
- data,
155
+ tableData,
155
156
  hideDetails,
156
157
  stickyHeaderTopOffset,
157
158
  textOverrides,
@@ -159,7 +160,7 @@ export const TableStory = ({
159
160
  }: TableProps) => (
160
161
  <Table
161
162
  collapsibleSections={collapsibleSections}
162
- data={data}
163
+ tableData={tableData}
163
164
  hideDetails={hideDetails}
164
165
  stickyHeaderTopOffset={stickyHeaderTopOffset}
165
166
  textOverrides={textOverrides}
@@ -176,17 +177,16 @@ type TableData = {
176
177
  title?: string;
177
178
  icon?: ReactNode;
178
179
  };
179
- items: {
180
+ rows: {
180
181
  align?: 'center' | 'left' | 'right';
181
- boolean?: boolean;
182
- cellProps?: HTMLProps<HTMLTableCellElement>;
183
- description?: ReactNode;
184
- info?: ReactNode;
182
+ checkmarkValue?: boolean;
183
+ content?: ReactNode;
184
+ modalContent?: ReactNode;
185
+ subContent?: ReactNode;
185
186
  rating?: {
186
187
  value: number;
187
188
  type: 'zap' | 'star';
188
189
  }
189
- text?: ReactNode;
190
190
  openModal?: (modalContent: ReactNode) => void;
191
191
  }[][];
192
192
  }[];
@@ -2,20 +2,20 @@ import { render, screen } from '../../util/testUtils';
2
2
  import { Table } from './Table';
3
3
  import { TableSectionData } from './types';
4
4
 
5
- const data: TableSectionData[] = [
5
+ const tableData: TableSectionData[] = [
6
6
  {
7
7
  section: {
8
8
  title: 'Section 1',
9
9
  icon: <span>Icon 1</span>,
10
10
  },
11
- items: [[{ content: 'Item 1' }, { content: 'Item 2' }]],
11
+ rows: [[{ content: 'Item 1' }, { content: 'Item 2' }]],
12
12
  },
13
13
  {
14
14
  section: {
15
15
  title: 'Section 2',
16
16
  icon: <span>Icon 2</span>,
17
17
  },
18
- items: [
18
+ rows: [
19
19
  [
20
20
  { content: 'Item 3' },
21
21
  { content: 'Item 4', modalContent: 'Additional item' },
@@ -26,7 +26,7 @@ const data: TableSectionData[] = [
26
26
 
27
27
  describe('Table', () => {
28
28
  it('renders the table with sections and items', () => {
29
- render(<Table data={data} title="Test Table" />);
29
+ render(<Table tableData={tableData} title="Test Table" />);
30
30
 
31
31
  expect(screen.getByText('Section 1')).toBeInTheDocument();
32
32
  expect(screen.getByText('Section 2')).toBeInTheDocument();
@@ -38,28 +38,28 @@ describe('Table', () => {
38
38
  });
39
39
 
40
40
  it('renders the table without sections', () => {
41
- const dataWithoutSections = [{ items: data[0].items }];
41
+ const dataWithoutSections = [{ rows: tableData[0].rows }];
42
42
 
43
- render(<Table data={dataWithoutSections} title="Test Table" />);
43
+ render(<Table tableData={dataWithoutSections} title="Test Table" />);
44
44
 
45
45
  expect(screen.getAllByText('Item 1')[0]).toBeVisible();
46
46
  expect(screen.getAllByText('Item 2')[0]).toBeVisible();
47
47
  });
48
48
 
49
49
  it('hides the show/hide details button if hideDetails is false', () => {
50
- render(<Table data={data} hideDetails title="Test Table" />);
50
+ render(<Table tableData={tableData} hideDetails title="Test Table" />);
51
51
 
52
52
  expect(screen.queryByTestId('show-hide-details')).toBeInTheDocument();
53
53
  });
54
54
 
55
55
  it('shows the show/hide details button if hideDetails is true', () => {
56
- render(<Table data={data} hideDetails title="Test Table" />);
56
+ render(<Table tableData={tableData} hideDetails title="Test Table" />);
57
57
 
58
58
  expect(screen.getByTestId('show-hide-details')).toBeInTheDocument();
59
59
  });
60
60
 
61
61
  it('hides the sections if hideDetails is true', () => {
62
- render(<Table data={data} hideDetails title="Test Table" />);
62
+ render(<Table tableData={tableData} hideDetails title="Test Table" />);
63
63
 
64
64
  expect(screen.queryByText('Section 2')).not.toBeInTheDocument();
65
65
  expect(screen.getByTestId('show-hide-details')).toBeInTheDocument();
@@ -67,7 +67,7 @@ describe('Table', () => {
67
67
 
68
68
  it('hides the sections if hideDetails is true and shows if clicking on button', async () => {
69
69
  const { user } = render(
70
- <Table data={data} hideDetails title="Test Table" />
70
+ <Table tableData={tableData} hideDetails title="Test Table" />
71
71
  );
72
72
 
73
73
  expect(screen.getByText('Show details')).toBeVisible();
@@ -79,7 +79,7 @@ describe('Table', () => {
79
79
  });
80
80
 
81
81
  it('shows a modal when clicking on info icon', async () => {
82
- const { user } = render(<Table data={data} title="Test Table" />);
82
+ const { user } = render(<Table tableData={tableData} title="Test Table" />);
83
83
 
84
84
  await user.click(screen.getByText('View more info'));
85
85
 
@@ -6,25 +6,23 @@ import { Card } from '../cards/card';
6
6
 
7
7
  import styles from './Table.module.scss';
8
8
  import { useMediaQuery } from '../../hooks/useMediaQuery';
9
- import { TableSection } from './components/TableSection/TableSection';
9
+ import { TableContents } from './components/TableContents/TableContents';
10
10
  import classNames from 'classnames';
11
11
  import { useTableNavigation } from './utils/useTableNavigation/useTableNavigation';
12
12
  import { TableControls } from './components/TableControls/TableControls';
13
- import { TableContent } from './components/TableContent/TableContent';
13
+ import { TableSection } from './components/TableSection/TableSection';
14
14
  import { useScrollSync } from './utils/useScrollSync/useScrollSync';
15
- import { ModalData, ModalFunction, TableSectionData } from './types';
15
+ import { ModalData, ModalFunction, TableData } from './types';
16
16
 
17
17
  type TextOverrides = {
18
18
  showDetails?: string;
19
19
  hideDetails?: string;
20
20
  };
21
21
 
22
- export type TableData = TableSectionData[];
23
-
24
22
  export interface TableProps {
25
23
  className?: string;
26
24
  collapsibleSections?: boolean;
27
- data: TableData;
25
+ tableData: TableData;
28
26
  hideDetails?: boolean;
29
27
  onModalOpen?: ModalFunction;
30
28
  onSelectionChanged?: (index: number) => void;
@@ -41,7 +39,7 @@ const defaultTextOverrides = {
41
39
  const Table = ({
42
40
  className,
43
41
  collapsibleSections,
44
- data,
42
+ tableData,
45
43
  hideDetails,
46
44
  onModalOpen,
47
45
  onSelectionChanged,
@@ -55,7 +53,7 @@ const Table = ({
55
53
  const [shouldHideDetails, setShouldHideDetails] = useState(true);
56
54
  const containerRef = useRef<HTMLDivElement | null>(null);
57
55
  const headerRef = useRef<HTMLDivElement | null>(null);
58
- const columnsLength = data[0].items[0].length;
56
+ const columnsLength = tableData[0].rows[0].length;
59
57
 
60
58
  useScrollSync(headerRef, containerRef, !isMobile);
61
59
 
@@ -66,7 +64,7 @@ const Table = ({
66
64
  onSelectionChanged,
67
65
  });
68
66
 
69
- const currentActiveSection = data?.[0]?.items?.[0]?.[activeSection];
67
+ const currentActiveSection = tableData?.[0]?.rows?.[0]?.[activeSection];
70
68
 
71
69
  const handleOpenModal: ModalFunction = ({ body, title }) => {
72
70
  onModalOpen?.({ body, title });
@@ -100,8 +98,8 @@ const Table = ({
100
98
  style={{ top: `${stickyHeaderTopOffset}px` }}
101
99
  >
102
100
  <div className={styles.container} ref={headerRef}>
103
- <TableContent
104
- data={[data?.[0]?.items?.[0]]}
101
+ <TableSection
102
+ tableCellRows={[tableData?.[0]?.rows?.[0]]}
105
103
  title={title}
106
104
  className={className}
107
105
  openModal={handleOpenModal}
@@ -111,8 +109,8 @@ const Table = ({
111
109
  )}
112
110
 
113
111
  <div ref={containerRef} className={classNames(styles.container, 'pb8')}>
114
- <TableSection
115
- data={data}
112
+ <TableContents
113
+ tableData={tableData}
116
114
  title={title}
117
115
  className={className}
118
116
  collapsibleSections={collapsibleSections}
@@ -5,6 +5,7 @@
5
5
  min-height: initial;
6
6
  height: initial;
7
7
  width: initial;
8
+ padding: 0;
8
9
  }
9
10
 
10
11
  .icon {
@@ -0,0 +1,10 @@
1
+ .cardWrapper {
2
+ height: 88px;
3
+ }
4
+
5
+ .card {
6
+ position: absolute;
7
+ left: 0;
8
+ right: 0;
9
+ z-index: 3;
10
+ }
@@ -0,0 +1,86 @@
1
+ import { render, screen } from '../../../../util/testUtils';
2
+ import { TableContents, TableSectionProps } from './TableContents';
3
+
4
+ const mockData: TableSectionProps['tableData'] = [
5
+ {
6
+ rows: [
7
+ [{ content: 'Item 1.1.1' }, { content: 'Item 1.1.2' }],
8
+ [{ content: 'Item 1.2.1' }, { content: 'Item 1.2.2' }],
9
+ ],
10
+ },
11
+ {
12
+ section: {
13
+ title: 'Section 2',
14
+ },
15
+ rows: [
16
+ [{ content: 'Item 2.1.1' }, { content: 'Item 2.1.2' }],
17
+ [{ content: 'Item 2.2.1' }, { content: 'Item 2.2.2' }],
18
+ ],
19
+ },
20
+ ];
21
+
22
+ describe('TableContents', () => {
23
+ it('renders the table sections with sections', () => {
24
+ render(
25
+ <TableContents collapsibleSections tableData={mockData} title="Table" />
26
+ );
27
+
28
+ expect(screen.getByText('Section 2')).toBeInTheDocument();
29
+ });
30
+
31
+ it('renders the table sections with sections data', () => {
32
+ render(
33
+ <TableContents collapsibleSections tableData={mockData} title="Table" />
34
+ );
35
+
36
+ expect(screen.getByText('Item 1.2.1')).toBeInTheDocument();
37
+ expect(screen.getByText('Item 1.2.2')).toBeInTheDocument();
38
+ expect(screen.getByText('Item 2.1.2')).toBeInTheDocument();
39
+ expect(screen.getByText('Item 2.2.1')).toBeInTheDocument();
40
+ });
41
+
42
+ it('hides the table sections when hideDetails and shouldHideDetails is true', () => {
43
+ render(
44
+ <TableContents
45
+ hideDetails
46
+ shouldHideDetails
47
+ tableData={mockData}
48
+ title="Table"
49
+ />
50
+ );
51
+
52
+ expect(screen.queryByText('Section 2')).not.toBeInTheDocument();
53
+ expect(screen.queryByText('Item 2.1.1')).not.toBeInTheDocument();
54
+ });
55
+
56
+ it('hides the table sections details when collapsibleSections is true', () => {
57
+ render(
58
+ <TableContents
59
+ collapsibleSections
60
+ isMobile
61
+ tableData={mockData}
62
+ title="Table"
63
+ />
64
+ );
65
+
66
+ expect(screen.getByText('Section 2')).toBeVisible();
67
+ expect(screen.queryByText('Item 2.1.1')).not.toBeVisible();
68
+ });
69
+
70
+ it('shows the table sections when hideDetails is collapsibleSections true has expanded ', async () => {
71
+ const { user } = render(
72
+ <TableContents
73
+ collapsibleSections
74
+ isMobile
75
+ tableData={mockData}
76
+ title="Table"
77
+ />
78
+ );
79
+
80
+ expect(screen.queryByText('Item 2.1.1')).not.toBeVisible();
81
+
82
+ await user.click(screen.getByText('Section 2'));
83
+
84
+ expect(screen.getByText('Item 2.1.1')).toBeVisible();
85
+ });
86
+ });
@@ -0,0 +1,106 @@
1
+ import { useState } from 'react';
2
+ import { TableSection } from '../TableSection/TableSection';
3
+ import { ChevronDownIcon, ChevronUpIcon } from '../../../icon';
4
+ import { Card } from '../../../cards/card';
5
+
6
+ import styles from './TableContents.module.scss';
7
+ import classNames from 'classnames';
8
+ import { Collapsible } from './Collapsible';
9
+ import { ModalFunction, TableData } from '../../types';
10
+
11
+ export interface TableContentsProps {
12
+ className?: string;
13
+ collapsibleSections?: boolean;
14
+ tableData: TableData;
15
+ hideDetails?: boolean;
16
+ isMobile?: boolean;
17
+ openModal?: ModalFunction;
18
+ shouldHideDetails?: boolean;
19
+ title: string;
20
+ }
21
+
22
+ const TableContents = ({
23
+ className,
24
+ collapsibleSections,
25
+ tableData,
26
+ hideDetails,
27
+ isMobile,
28
+ openModal,
29
+ shouldHideDetails,
30
+ title,
31
+ }: TableContentsProps) => {
32
+ const [isSectionOpen, setOpenSection] = useState<number | null>(null);
33
+ const firstHeadRow = tableData?.[0]?.rows?.[0];
34
+ const tableWidth = isMobile ? `${firstHeadRow?.length * 50}%` : '';
35
+ const handleToggleSection = (index: number) => {
36
+ setOpenSection((currentSection) =>
37
+ currentSection === index ? null : index
38
+ );
39
+ };
40
+
41
+ return (
42
+ <div style={{ width: tableWidth }}>
43
+ {tableData.map(({ rows, section = {} }, index) => {
44
+ const isFirstSection = index === 0;
45
+ const isExpanded = !collapsibleSections
46
+ ? true
47
+ : isSectionOpen === index || isFirstSection;
48
+ const isVisible = hideDetails ? !shouldHideDetails : true;
49
+
50
+ return (
51
+ (isFirstSection || isVisible) && (
52
+ <div key={index}>
53
+ {section?.title && (
54
+ <div className={styles.cardWrapper}>
55
+ <div className={classNames(styles.card, 'p8')}>
56
+ <Card
57
+ actionIcon={
58
+ isExpanded ? (
59
+ <ChevronUpIcon size={24} />
60
+ ) : (
61
+ <ChevronDownIcon size={24} />
62
+ )
63
+ }
64
+ aria-expanded={isExpanded ? 'true' : 'false'}
65
+ aria-hidden
66
+ classNames={{
67
+ wrapper: 'bg-grey-200',
68
+ icon: 'tc-grey-900',
69
+ }}
70
+ dropShadow={false}
71
+ icon={section?.icon}
72
+ title={section.title}
73
+ titleVariant="medium"
74
+ {...(collapsibleSections
75
+ ? {
76
+ onClick: () => handleToggleSection(index),
77
+ }
78
+ : {})}
79
+ />
80
+ </div>
81
+ </div>
82
+ )}
83
+
84
+ <Collapsible isExpanded={isExpanded} isMobile={isMobile}>
85
+ <TableSection
86
+ className={classNames(className, 'mb24')}
87
+ tableCellRows={
88
+ isFirstSection ? rows : [firstHeadRow, ...rows]
89
+ }
90
+ hideHeader
91
+ openModal={openModal}
92
+ title={`${title}${
93
+ section?.title ? ` - ${section.title}` : ''
94
+ }`}
95
+ width={tableWidth}
96
+ />
97
+ </Collapsible>
98
+ </div>
99
+ )
100
+ );
101
+ })}
102
+ </div>
103
+ );
104
+ };
105
+
106
+ export { TableContents };
@@ -5,11 +5,12 @@
5
5
  left: 0;
6
6
  right: 0;
7
7
  min-height: 72px;
8
- z-index: 3;
8
+ z-index: 9;
9
9
  }
10
10
 
11
11
  .controlButton {
12
12
  border-radius: 50%!important;
13
13
  width: 32px;
14
14
  height: 32px;
15
+ padding: 0;
15
16
  }
@@ -1,10 +1,15 @@
1
- .cardWrapper {
2
- height: 88px;
1
+ @use '../../../../scss/public/colors' as *;
2
+ @use '../../../../scss/public/grid' as *;
3
+
4
+ .table {
5
+ border-collapse: collapse;
6
+ table-layout: fixed;
7
+
8
+ @include p-size-tablet {
9
+ min-width: 845px;
10
+ }
3
11
  }
4
12
 
5
- .card {
6
- position: absolute;
7
- left: 0;
8
- right: 0;
9
- z-index: 3;
10
- }
13
+ .tr {
14
+ min-height: 72px;
15
+ }
@@ -1,82 +1,56 @@
1
1
  import { render, screen } from '../../../../util/testUtils';
2
- import { TableSection, TableSectionProps } from './TableSection';
2
+ import { TableSection, TableContentProps } from './TableSection';
3
3
 
4
- const mockData: TableSectionProps['data'] = [
5
- {
6
- items: [
7
- [{ content: 'Item 1.1.1' }, { content: 'Item 1.1.2' }],
8
- [{ content: 'Item 1.2.1' }, { content: 'Item 1.2.2' }],
9
- ],
10
- },
11
- {
12
- section: {
13
- title: 'Section 2',
14
- },
15
- items: [
16
- [{ content: 'Item 2.1.1' }, { content: 'Item 2.1.2' }],
17
- [{ content: 'Item 2.2.1' }, { content: 'Item 2.2.2' }],
18
- ],
19
- },
4
+ const tableCellRows: TableContentProps['tableCellRows'] = [
5
+ [{ content: 'Cell 1.1' }, { content: 'Cell 1.2' }, { content: 'Cell 1.3' }],
6
+ [{ content: 'Cell 2.1' }, { content: 'Cell 2.2' }, { content: 'Cell 2.3' }],
20
7
  ];
21
8
 
22
- describe('TableSection', () => {
23
- it('renders the table sections with sections', () => {
24
- render(<TableSection collapsibleSections data={mockData} title="Table" />);
25
-
26
- expect(screen.getByText('Section 2')).toBeInTheDocument();
27
- });
9
+ const mockTitle = 'Test Table';
28
10
 
29
- it('renders the table sections with sections data', () => {
30
- render(<TableSection collapsibleSections data={mockData} title="Table" />);
11
+ const mockOpenModal = jest.fn();
31
12
 
32
- expect(screen.getByText('Item 1.2.1')).toBeInTheDocument();
33
- expect(screen.getByText('Item 1.2.2')).toBeInTheDocument();
34
- expect(screen.getByText('Item 2.1.2')).toBeInTheDocument();
35
- expect(screen.getByText('Item 2.2.1')).toBeInTheDocument();
36
- });
13
+ const defaultProps: TableContentProps = {
14
+ tableCellRows,
15
+ title: mockTitle,
16
+ openModal: mockOpenModal,
17
+ };
37
18
 
38
- it('hides the table sections when hideDetails and shouldHideDetails is true', () => {
39
- render(
40
- <TableSection
41
- hideDetails
42
- shouldHideDetails
43
- data={mockData}
44
- title="Table"
45
- />
46
- );
19
+ describe('TableSection', () => {
20
+ it('renders the table caption', () => {
21
+ render(<TableSection {...defaultProps} />);
47
22
 
48
- expect(screen.queryByText('Section 2')).not.toBeInTheDocument();
49
- expect(screen.queryByText('Item 2.1.1')).not.toBeInTheDocument();
23
+ expect(screen.getByText(mockTitle)).toBeInTheDocument();
50
24
  });
51
25
 
52
- it('hides the table sections details when collapsibleSections is true', () => {
53
- render(
54
- <TableSection
55
- collapsibleSections
56
- isMobile
57
- data={mockData}
58
- title="Table"
59
- />
60
- );
26
+ it('renders the table with correct data', () => {
27
+ render(<TableSection {...defaultProps} />);
28
+
29
+ expect(screen.getByText('Cell 1.1')).toBeInTheDocument();
30
+ expect(screen.getByText('Cell 1.2')).toBeInTheDocument();
31
+ expect(screen.getByText('Cell 1.3')).toBeInTheDocument();
61
32
 
62
- expect(screen.getByText('Section 2')).toBeVisible();
63
- expect(screen.queryByText('Item 2.1.1')).not.toBeVisible();
33
+ expect(screen.getByText('Cell 2.1')).toBeInTheDocument();
34
+ expect(screen.getByText('Cell 2.2')).toBeInTheDocument();
35
+ expect(screen.getByText('Cell 2.3')).toBeInTheDocument();
64
36
  });
65
37
 
66
- it('shows the table sections when hideDetails is collapsibleSections true has expanded ', async () => {
67
- const { user } = render(
68
- <TableSection
69
- collapsibleSections
70
- isMobile
71
- data={mockData}
72
- title="Table"
73
- />
74
- );
38
+ it('should render table headers', () => {
39
+ const { container } = render(<TableSection {...defaultProps} />);
75
40
 
76
- expect(screen.queryByText('Item 2.1.1')).not.toBeVisible();
41
+ const thElements = container.querySelectorAll('th');
42
+
43
+ expect(thElements.length).toBe(4);
44
+ expect(thElements[0]).toHaveTextContent('Cell 1.1');
45
+ expect(thElements[3]).toHaveTextContent('Cell 2.1');
46
+ });
77
47
 
78
- await user.click(screen.getByText('Section 2'));
48
+ it('should render table data cells', () => {
49
+ const { container } = render(<TableSection {...defaultProps} />);
79
50
 
80
- expect(screen.getByText('Item 2.1.1')).toBeVisible();
51
+ const tdElements = container.querySelectorAll('td');
52
+ expect(tdElements.length).toBe(2);
53
+ expect(tdElements[0]).toHaveTextContent('Cell 2.2');
54
+ expect(tdElements[1]).toHaveTextContent('Cell 2.3');
81
55
  });
82
56
  });