2022-05-23 09:45:36 -05:00
|
|
|
import { render, screen, waitFor } from '@testing-library/react';
|
|
|
|
import userEvent from '@testing-library/user-event';
|
2022-04-22 08:33:13 -05:00
|
|
|
|
2018-09-11 07:14:03 -05:00
|
|
|
import { TeamGroup } from '../../types';
|
2022-04-22 08:33:13 -05:00
|
|
|
|
|
|
|
import { Props, TeamGroupSync } from './TeamGroupSync';
|
2018-09-11 07:14:03 -05:00
|
|
|
import { getMockTeamGroups } from './__mocks__/teamMocks';
|
|
|
|
|
|
|
|
const setup = (propOverrides?: object) => {
|
|
|
|
const props: Props = {
|
2022-02-03 10:49:39 -06:00
|
|
|
isReadOnly: false,
|
2018-09-11 07:14:03 -05:00
|
|
|
groups: [] as TeamGroup[],
|
|
|
|
loadTeamGroups: jest.fn(),
|
|
|
|
addTeamGroup: jest.fn(),
|
|
|
|
removeTeamGroup: jest.fn(),
|
|
|
|
};
|
|
|
|
|
|
|
|
Object.assign(props, propOverrides);
|
|
|
|
|
2022-05-23 09:45:36 -05:00
|
|
|
return render(<TeamGroupSync {...props} />);
|
2018-09-11 07:14:03 -05:00
|
|
|
};
|
|
|
|
|
2022-05-23 09:45:36 -05:00
|
|
|
describe('TeamGroupSync', () => {
|
2018-09-11 07:14:03 -05:00
|
|
|
it('should render component', () => {
|
2022-05-23 09:45:36 -05:00
|
|
|
setup();
|
|
|
|
expect(screen.getByRole('heading', { name: /External group sync/i })).toBeInTheDocument();
|
2018-09-11 07:14:03 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should render groups table', () => {
|
2022-05-23 09:45:36 -05:00
|
|
|
setup({ groups: getMockTeamGroups(3) });
|
|
|
|
expect(screen.getAllByRole('row')).toHaveLength(4); // 3 items plus table header
|
2018-09-11 07:14:03 -05:00
|
|
|
});
|
|
|
|
|
2022-05-23 09:45:36 -05:00
|
|
|
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');
|
|
|
|
});
|
2018-09-11 07:14:03 -05:00
|
|
|
});
|
|
|
|
|
2022-05-23 09:45:36 -05:00
|
|
|
it('should call remove group', async () => {
|
|
|
|
const mockRemoveGroup = jest.fn();
|
2018-09-11 07:14:03 -05:00
|
|
|
const mockGroup: TeamGroup = { teamId: 1, groupId: 'some/group' };
|
2022-05-23 09:45:36 -05:00
|
|
|
setup({ removeTeamGroup: mockRemoveGroup, groups: [mockGroup] });
|
|
|
|
await userEvent.click(screen.getByRole('button', { name: 'Remove group some/group' }));
|
|
|
|
await waitFor(() => {
|
|
|
|
expect(mockRemoveGroup).toHaveBeenCalledWith('some/group');
|
|
|
|
});
|
2018-09-11 07:14:03 -05:00
|
|
|
});
|
|
|
|
});
|