Skip to content

Commit

Permalink
feat(vadcDataDictionaryTable): fixed test issues and eslint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
jarvisraymond-uchicago committed Jan 17, 2024
1 parent 7c6b871 commit 0937d7c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 32 deletions.
24 changes: 7 additions & 17 deletions src/Analysis/DataDictionary/ColumnHeaders/ColumnHeaders.test.tsx
Original file line number Diff line number Diff line change
@@ -1,41 +1,31 @@
import React from 'react';
import { render, fireEvent, screen } from '@testing-library/react';
import { ISortConfig } from '../Interfaces/Interfaces';
import '@testing-library/jest-dom/extend-expect';
import ColumnHeaders from './ColumnHeaders';
import Header from './Header'; // Assuming you've exported the Header component for testing

interface ISortConfig {
sortKey: string;
sortDirection: 'asc' | 'desc';
}

const sortConfig: ISortConfig = { sortKey: '', direction: 'ascending' };
describe('ColumnHeaders', () => {
it('renders ColumnHeaders ', () => {
const handleSort = jest.fn();
const sortConfig: ISortConfig = {};

render(
<table>
<ColumnHeaders handleSort={handleSort} sortConfig={sortConfig} />
</table>
</table>,
);

expect(screen.getByTestId('column-headers')).toBeInTheDocument();
});
it('calls handleSort when a column is clicked', () => {
const handleSort = jest.fn();
const sortConfig: ISortConfig = {};

const { getByRole } = render(
render(
<table>
<ColumnHeaders handleSort={handleSort} sortConfig={sortConfig} />
</table>
</table>,
);

fireEvent.click(
screen.getAllByRole('presentation', { name: 'caret-up' })[0]
screen.getAllByRole('presentation', { name: 'caret-up' })[0],
);

expect(handleSort).toHaveBeenCalledWith('vocabularyID'); // or 'desc' depending on the initial sorting state
expect(handleSort).toHaveBeenCalledTimes(1);
});
});
30 changes: 15 additions & 15 deletions src/Analysis/DataDictionary/ColumnHeaders/Header.test.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import React from 'react';
import { ISortConfig, IHeaderProps } from './Interfaces/Interfaces'; // adjust the import path if necessary
import {
render, fireEvent, screen, cleanup,
} from '@testing-library/react';
import { ISortConfig } from '../Interfaces/Interfaces';
import Header from './Header'; // adjust the import path if necessary
import { render, fireEvent, screen } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';
import { cleanup } from '@testing-library/react';

describe('Header component', () => {
afterEach(cleanup);
const defaultProps: IHeaderProps = {
const defaultProps: any = {
handleSort: jest.fn(),
headerJSX: <div data-testid='header'>Test Header Text</div>, // adjust the JSX for your headerJSX
headerKey: 'key1',
Expand All @@ -23,26 +24,26 @@ describe('Header component', () => {
<Header {...defaultProps} />
</tr>
</thead>
</table>
</table>,
);
expect(screen.getAllByText('Test Header Text').length).toBeGreaterThan(0);
});

it(`renders the Header component correctly when sortable is true and
there is a sort config with ascending direction`, () => {
const sortConfig: ISortConfig = {
const sortConfig: any = {
key: 'key1',
sortKey: 'key1',
direction: 'ascending',
}; // adjust for your use case
const { getByTestId } = render(
};
render(
<table>
<thead>
<tr>
<Header {...defaultProps} sortConfig={sortConfig} />
</tr>
</thead>
</table>
</table>,
);
expect(screen.getAllByText('Test Header Text').length).toBeGreaterThan(0);
const caretUpArrows = screen.getAllByRole('presentation', {
Expand All @@ -51,7 +52,7 @@ describe('Header component', () => {

let activeCaretUp = false;
caretUpArrows.forEach((caretUpArrow) => {
if (caretUpArrow['className'].includes('active')) activeCaretUp = true;
if (caretUpArrow.className.includes('active')) activeCaretUp = true;
});
expect(activeCaretUp).toBe(true);
});
Expand All @@ -63,14 +64,14 @@ describe('Header component', () => {
sortKey: 'key1',
direction: 'descending',
}; // adjust for your use case
const { getByTestId } = render(
render(
<table>
<thead>
<tr>
<Header {...defaultProps} sortConfig={sortConfig} />
</tr>
</thead>
</table>
</table>,
);
expect(screen.getAllByText('Test Header Text').length).toBeGreaterThan(0);
const caretDownArrows = screen.getAllByRole('presentation', {
Expand All @@ -79,8 +80,7 @@ describe('Header component', () => {

let activeCaretDown = false;
caretDownArrows.forEach((caretDownArrow) => {
if (caretDownArrow['className'].includes('active'))
activeCaretDown = true;
if (caretDownArrow.className.includes('active')) activeCaretDown = true;
});
expect(activeCaretDown).toBe(true);
});
Expand All @@ -94,7 +94,7 @@ describe('Header component', () => {
<Header {...defaultProps} handleSort={handleSort} />
</tr>
</thead>
</table>
</table>,
);
fireEvent.click(screen.getAllByText('Test Header Text')[0]);
expect(handleSort).toHaveBeenCalledTimes(1);
Expand Down

0 comments on commit 0937d7c

Please sign in to comment.