Skip to content

Commit

Permalink
added test case for new SortedDataTable
Browse files Browse the repository at this point in the history
Signed-off-by: c-r-dev <[email protected]>
  • Loading branch information
c-r-dev committed Jan 16, 2025
1 parent 86bf8d8 commit 431ad9f
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions web/vtadmin/src/components/dataTable/SortedDataTable.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* Copyright 2025 The Vitess Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { describe, expect, it } from 'vitest';
import { JSX } from 'react/jsx-runtime';
import { SortedDataTable } from './SortedDataTable';
import { fireEvent, render, screen } from '@testing-library/react';
import { MemoryRouter } from 'react-router-dom';

describe('SortedDataTable', () => {
it('SortedDataTable renders successfully', () => {
const columnProps = [
{ display: 'col1', accessor: 'col1' },
{ display: <div>col2</div>, accessor: 'a_col2' },
];
const testData = [
{ col1: 'dcol1', a_col2: '20' },
{ col1: 'dcol11', a_col2: '10' },
];

render(
<MemoryRouter initialEntries={[{ pathname: '/schemas', totalPages: 10, pageQueryKey: 'page' }]}>
<SortedDataTable
columns={columnProps}
data={testData}
renderRows={function (rows: any[]): JSX.Element[] {
return rows.map((item, idx) => {
return (
<tr key={idx}>
<td> {item.col1} </td> <td> {item.col2} </td>
</tr>
);
});
}}
/>
</MemoryRouter>
);
expect(screen.getAllByRole('table').length).toBe(1);
expect(screen.getAllByRole('row').length).toBe(3);
expect(screen.getAllByRole('columnheader').length).toBe(2);

// Check onClick on column
const column1 = screen.getByText('col1');
fireEvent.click(column1);
// dependency on vite-jest to check useState sortColumn if col1 gets set.
});
});

0 comments on commit 431ad9f

Please sign in to comment.