Grid.spec.tsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import { render } from '@testing-library/react';
  2. import AttuGrid from '../../grid/Grid';
  3. import { ToolBarConfig } from '../../grid/Types';
  4. import { vi } from 'vitest';
  5. vi.mock('react-i18next', () => {
  6. return {
  7. useTranslation: () => ({
  8. t: () => ({
  9. grid: {},
  10. }),
  11. }),
  12. };
  13. });
  14. vi.mock('react-router-dom', () => {
  15. return {
  16. useHistory: () => {
  17. return {
  18. listen: () => () => {},
  19. location: {
  20. name: '',
  21. },
  22. };
  23. },
  24. };
  25. });
  26. describe('Test Grid index', () => {
  27. it('Has Table Data', () => {
  28. const res = render(
  29. <AttuGrid
  30. primaryKey="id"
  31. rows={[{}]}
  32. colDefinitions={[]}
  33. rowCount={10}
  34. toolbarConfigs={[]}
  35. />
  36. );
  37. expect(res.getAllByRole('table').length).toEqual(1);
  38. });
  39. it('Test title', () => {
  40. const title = ['collections', 'vectors'];
  41. const res = render(
  42. <AttuGrid
  43. primaryKey="id"
  44. rows={[]}
  45. colDefinitions={[]}
  46. rowCount={0}
  47. toolbarConfigs={[]}
  48. title={title}
  49. />
  50. );
  51. const breadCrum = res.getAllByRole('breadcrumb');
  52. expect(breadCrum.length).toEqual(1);
  53. expect(breadCrum[0].textContent).toEqual(`collections›vectors`);
  54. });
  55. it('Test Toolbar ', () => {
  56. const ToolbarConfig: ToolBarConfig[] = [
  57. {
  58. label: 'collection',
  59. icon: 'search',
  60. onClick: () => {},
  61. onSearch: () => {},
  62. },
  63. ];
  64. const res = render(
  65. <AttuGrid
  66. primaryKey="id"
  67. rows={[]}
  68. colDefinitions={[]}
  69. rowCount={0}
  70. toolbarConfigs={ToolbarConfig}
  71. />
  72. );
  73. expect(res.getAllByRole('toolbar').length).toEqual(1);
  74. });
  75. });