Skip to content

Commit 9954d87

Browse files
committed
add unit tests for new modifiers, update example
1 parent 4316b40 commit 9954d87

File tree

2 files changed

+41
-5
lines changed

2 files changed

+41
-5
lines changed

packages/react-table/src/components/Table/__tests__/Table.test.tsx

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,3 +186,39 @@ test(`Does not render with class ${styles.modifiers.noPlainOnGlass} when isNoPla
186186

187187
expect(screen.getByRole('grid', { name: 'Test table' })).not.toHaveClass(styles.modifiers.noPlainOnGlass);
188188
});
189+
190+
test(`Renders with class ${styles.modifiers.stickyHeaderBase} when isStickyHeaderBase is true`, () => {
191+
render(<Table isStickyHeaderBase aria-label="Test table" />);
192+
193+
expect(screen.getByRole('grid', { name: 'Test table' })).toHaveClass(styles.modifiers.stickyHeaderBase);
194+
});
195+
196+
test(`Does not render with class ${styles.modifiers.stickyHeaderBase} when isStickyHeaderBase is false`, () => {
197+
render(<Table isStickyHeaderBase={false} aria-label="Test table" />);
198+
199+
expect(screen.getByRole('grid', { name: 'Test table' })).not.toHaveClass(styles.modifiers.stickyHeaderBase);
200+
});
201+
202+
test(`Does not render with class ${styles.modifiers.stickyHeaderBase} when isStickyHeaderBase is undefined`, () => {
203+
render(<Table aria-label="Test table" />);
204+
205+
expect(screen.getByRole('grid', { name: 'Test table' })).not.toHaveClass(styles.modifiers.stickyHeaderBase);
206+
});
207+
208+
test(`Renders with class ${styles.modifiers.stickyHeaderStuck} when isStickyHeaderStuck is true`, () => {
209+
render(<Table isStickyHeaderStuck aria-label="Test table" />);
210+
211+
expect(screen.getByRole('grid', { name: 'Test table' })).toHaveClass(styles.modifiers.stickyHeaderStuck);
212+
});
213+
214+
test(`Does not render with class ${styles.modifiers.stickyHeaderStuck} when isStickyHeaderStuck is false`, () => {
215+
render(<Table isStickyHeaderStuck={false} aria-label="Test table" />);
216+
217+
expect(screen.getByRole('grid', { name: 'Test table' })).not.toHaveClass(styles.modifiers.stickyHeaderStuck);
218+
});
219+
220+
test(`Does not render with class ${styles.modifiers.stickyHeaderStuck} when isStickyHeaderStuck is undefined`, () => {
221+
render(<Table aria-label="Test table" />);
222+
223+
expect(screen.getByRole('grid', { name: 'Test table' })).not.toHaveClass(styles.modifiers.stickyHeaderStuck);
224+
});

packages/react-table/src/components/Table/examples/TableStickyHeaderDynamic.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export const TableStickyHeaderDynamic: React.FunctionComponent = () => {
8181
<div style={{ height: '400px' }}>
8282
<InnerScrollContainer ref={scrollContainerRef}>
8383
<Table
84-
aria-label="Sticky columns and header table"
84+
aria-label="Dynamic sticky header table"
8585
gridBreakPoint=""
8686
isStickyHeaderBase
8787
isStickyHeaderStuck={isStuck}
@@ -102,13 +102,13 @@ export const TableStickyHeaderDynamic: React.FunctionComponent = () => {
102102
<Tbody>
103103
{facts.map((fact) => (
104104
<Tr key={fact.name}>
105-
<Th modifier="nowrap" dataLabel={columnNames.name}>
105+
<Td modifier="nowrap" dataLabel={columnNames.name}>
106106
{fact.name}
107-
</Th>
108-
<Th modifier="nowrap" dataLabel={columnNames.state}>
107+
</Td>
108+
<Td modifier="nowrap" dataLabel={columnNames.state}>
109109
<BlueprintIcon />
110110
{` ${fact.state}`}
111-
</Th>
111+
</Td>
112112
<Td modifier="nowrap" dataLabel={columnNames.header3}>
113113
{fact.detail1}
114114
</Td>

0 commit comments

Comments
 (0)