mirror of
https://github.com/grafana/grafana.git
synced 2025-02-10 23:55:47 -06:00
* update eslint, tsconfig + esbuild to handle new jsx transform * remove thing that breaks the new jsx transform * remove react imports * adjust grafana-icons build * is this the correct syntax? * try this * well this was much easier than expected... * change grafana-plugin-configs webpack config * fixes * fix lockfile * fix 2 more violations * use path.resolve instead of require.resolve * remove react import * fix react imports * more fixes * remove React import * remove import React from docs * remove another react import
71 lines
2.1 KiB
TypeScript
71 lines
2.1 KiB
TypeScript
import { render, screen, waitFor } from '@testing-library/react';
|
|
import userEvent from '@testing-library/user-event';
|
|
import { TestProvider } from 'test/helpers/TestProvider';
|
|
|
|
import { BackendSrv, setBackendSrv } from '@grafana/runtime';
|
|
|
|
import { CreateTeam } from './CreateTeam';
|
|
|
|
beforeEach(() => {
|
|
jest.clearAllMocks();
|
|
});
|
|
|
|
jest.mock('app/core/core', () => ({
|
|
contextSrv: {
|
|
licensedAccessControlEnabled: () => false,
|
|
hasPermission: () => true,
|
|
hasPermissionInMetadata: () => true,
|
|
user: { orgId: 1 },
|
|
},
|
|
}));
|
|
|
|
jest.mock('app/core/components/RolePicker/hooks', () => ({
|
|
useRoleOptions: jest.fn().mockReturnValue([{ roleOptions: [] }, jest.fn()]),
|
|
}));
|
|
|
|
const mockPost = jest.fn(() => {
|
|
return Promise.resolve({});
|
|
});
|
|
|
|
setBackendSrv({
|
|
post: mockPost,
|
|
} as unknown as BackendSrv);
|
|
|
|
const setup = () => {
|
|
return render(
|
|
<TestProvider>
|
|
<CreateTeam />
|
|
</TestProvider>
|
|
);
|
|
};
|
|
|
|
describe('Create team', () => {
|
|
it('should render component', () => {
|
|
setup();
|
|
expect(screen.getByRole('textbox', { name: /name/i })).toBeInTheDocument();
|
|
expect(screen.getByLabelText(/email/i)).toBeInTheDocument();
|
|
expect(screen.getByRole('button')).toBeInTheDocument();
|
|
});
|
|
|
|
it('should send correct data to the server', async () => {
|
|
setup();
|
|
await userEvent.type(screen.getByRole('textbox', { name: /name/i }), 'Test team');
|
|
await userEvent.type(screen.getByLabelText(/email/i), 'team@test.com');
|
|
await userEvent.click(screen.getByRole('button', { name: /create/i }));
|
|
await waitFor(() => {
|
|
expect(mockPost).toHaveBeenCalledWith(expect.anything(), { name: 'Test team', email: 'team@test.com' });
|
|
});
|
|
});
|
|
|
|
it('should validate required fields', async () => {
|
|
setup();
|
|
await userEvent.type(screen.getByLabelText(/email/i), 'team@test.com');
|
|
await userEvent.click(screen.getByRole('button', { name: /create/i }));
|
|
await waitFor(() => {
|
|
expect(mockPost).not.toBeCalled();
|
|
});
|
|
expect(screen.getAllByRole('alert')).toHaveLength(1);
|
|
expect(screen.getByText(/team name is required/i)).toBeInTheDocument();
|
|
});
|
|
});
|