The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/public/app/features/teams/TeamGroupSync.test.tsx

57 lines
2.0 KiB

import { render, screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { TeamGroup } from '../../types';
import { Props, TeamGroupSync } from './TeamGroupSync';
import { getMockTeamGroups } from './__mocks__/teamMocks';
const setup = (propOverrides?: object) => {
const props: Props = {
isReadOnly: false,
groups: [] as TeamGroup[],
loadTeamGroups: jest.fn(),
addTeamGroup: jest.fn(),
removeTeamGroup: jest.fn(),
};
Object.assign(props, propOverrides);
return render(<TeamGroupSync {...props} />);
};
describe('TeamGroupSync', () => {
it('should render component', () => {
setup();
expect(screen.getByRole('heading', { name: /External group sync/i })).toBeInTheDocument();
});
it('should render groups table', () => {
setup({ groups: getMockTeamGroups(3) });
expect(screen.getAllByRole('row')).toHaveLength(4); // 3 items plus table header
});
it('should call add group', async () => {
const mockAddGroup = jest.fn();
setup({ addTeamGroup: mockAddGroup });
// Empty List CTA "Add group" button is second in the DOM order
await userEvent.click(screen.getAllByRole('button', { name: /add group/i })[1]);
expect(screen.getByRole('textbox', { name: /add external group/i })).toBeVisible();
await userEvent.type(screen.getByRole('textbox', { name: /add external group/i }), 'test/group');
await userEvent.click(screen.getAllByRole('button', { name: /add group/i })[0]);
await waitFor(() => {
expect(mockAddGroup).toHaveBeenCalledWith('test/group');
});
});
it('should call remove group', async () => {
const mockRemoveGroup = jest.fn();
const mockGroup: TeamGroup = { teamId: 1, groupId: 'some/group' };
setup({ removeTeamGroup: mockRemoveGroup, groups: [mockGroup] });
await userEvent.click(screen.getByRole('button', { name: 'Remove group some/group' }));
await waitFor(() => {
expect(mockRemoveGroup).toHaveBeenCalledWith('some/group');
});
});
});