From c2cd08ee84e11494d567c870ca8cd3229835730d Mon Sep 17 00:00:00 2001 From: Karl Persson Date: Fri, 22 Nov 2024 17:11:27 +0100 Subject: [PATCH] AdminUserTable: Add some basic render tests (#96927) * Add some basic render tests --- .../features/admin/Users/UsersTable.test.tsx | 69 +++++++++++++++++++ .../app/features/admin/Users/UsersTable.tsx | 2 +- 2 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 public/app/features/admin/Users/UsersTable.test.tsx diff --git a/public/app/features/admin/Users/UsersTable.test.tsx b/public/app/features/admin/Users/UsersTable.test.tsx new file mode 100644 index 00000000000..667aca52b89 --- /dev/null +++ b/public/app/features/admin/Users/UsersTable.test.tsx @@ -0,0 +1,69 @@ +import { render } from '@testing-library/react'; +import { MemoryRouter } from 'react-router-dom-v5-compat'; + +import { UserDTO } from '../../../types'; + +import { UsersTable, UsersTableProps } from './UsersTable'; + +const setup = (propOverrides?: object) => { + const props: UsersTableProps = { + users: [] as UserDTO[], + showPaging: true, + totalPages: 1, + onChangePage: jest.fn(), + currentPage: 1, + fetchData: jest.fn(), + }; + + Object.assign(props, propOverrides); + + render( + + + + ); +}; + +describe('Render', () => { + it('should render component', () => { + expect(() => setup()).not.toThrow(); + }); + + it('should render when user has licensed role None', () => { + expect(() => + setup({ + users: [ + { + id: 1, + uid: '1', + login: '1', + email: '1', + name: '1', + isGrafanaAdmin: false, + isDisabled: false, + licensedRole: 'None', + }, + ], + }) + ).not.toThrow(); + }); + + it('should render when user belongs to org', () => { + expect(() => + setup({ + users: [ + { + id: 1, + uid: '1', + login: '1', + email: '1', + name: '1', + isGrafanaAdmin: false, + isDisabled: false, + orgs: [{ name: 'test', url: 'test' }], + }, + ], + }) + ).not.toThrow(); + }); +}); diff --git a/public/app/features/admin/Users/UsersTable.tsx b/public/app/features/admin/Users/UsersTable.tsx index 07ac760e087..c397dccf6b7 100644 --- a/public/app/features/admin/Users/UsersTable.tsx +++ b/public/app/features/admin/Users/UsersTable.tsx @@ -23,7 +23,7 @@ import { OrgUnits } from './OrgUnits'; type Cell = CellProps; -interface UsersTableProps { +export interface UsersTableProps { users: UserDTO[]; showPaging?: boolean; totalPages: number;