123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- import { render, unmountComponentAtNode } from 'react-dom';
- import { act } from 'react-dom/test-utils';
- import MilvusGrid from '../../grid/index';
- import { ToolBarConfig } from '../../grid/Types';
- let container: any = null;
- jest.mock('react-i18next', () => {
- return {
- useTranslation: () => ({
- t: () => ({
- grid: {},
- }),
- }),
- };
- });
- jest.mock('../../grid/Table', () => {
- return () => {
- return <div id="table">{}</div>;
- };
- });
- jest.mock('../../grid/ToolBar', () => {
- return () => {
- return <div id="tool-bar"></div>;
- };
- });
- jest.mock('react-router-dom', () => {
- return {
- useHistory: () => {
- return {
- listen: () => () => {},
- location: {
- name: '',
- },
- };
- },
- };
- });
- describe('Test Grid index', () => {
- beforeEach(() => {
- container = document.createElement('div');
- document.body.appendChild(container);
- });
- afterEach(() => {
- unmountComponentAtNode(container);
- container.remove();
- container = null;
- });
- it('Has Table Data', () => {
- act(() => {
- render(
- <MilvusGrid
- primaryKey="id"
- rows={[{}]}
- colDefinitions={[]}
- rowCount={10}
- toolbarConfigs={[]}
- />,
- container
- );
- });
- expect(container.querySelectorAll('#table').length).toEqual(1);
- });
- it('Test title', () => {
- const title = ['collections', 'vectors'];
- act(() => {
- render(
- <MilvusGrid
- primaryKey="id"
- rows={[]}
- colDefinitions={[]}
- rowCount={0}
- toolbarConfigs={[]}
- title={title}
- />,
- container
- );
- });
- const titleNodes = container.querySelectorAll('h6');
- expect(titleNodes.length).toEqual(title.length);
- expect(titleNodes[0].textContent).toEqual(title[0]);
- expect(titleNodes[1].textContent).toEqual(title[1]);
- });
- it('Test SearchForm', () => {
- const SearchForm = () => <div id="search-form"></div>;
- act(() => {
- render(
- <MilvusGrid
- primaryKey="id"
- rows={[]}
- colDefinitions={[]}
- rowCount={0}
- toolbarConfigs={[]}
- searchForm={<SearchForm />}
- />,
- container
- );
- });
- expect(container.querySelectorAll('#search-form').length).toEqual(1);
- });
- it('Test Toolbar ', () => {
- const ToolbarConfig: ToolBarConfig[] = [
- {
- label: 'collection',
- icon: 'search',
- onClick: () => {},
- onSearch: () => {},
- },
- ];
- act(() => {
- render(
- <MilvusGrid
- primaryKey="id"
- rows={[]}
- colDefinitions={[]}
- rowCount={0}
- toolbarConfigs={ToolbarConfig}
- />,
- container
- );
- });
- expect(container.querySelectorAll('#tool-bar').length).toEqual(1);
- });
- });
|