grafana/public/app/features/teams/CreateTeam.test.tsx
Torkel Ödegaard 1e85a6f4fd
TopNav: New page layouts (#51510)
* First stab at new page layouts behind feature toggle

* Simplifying PageHeader

* Progress on a new model that can more easily support new and old page layouts

* Progress

* rename folder

* Progress

* Minor change

* fixes

* Fixing tests

* Make breadcrumbs work

* Add tests for old Page component

* Adding tests for new Page component and behavior

* fixing page header test

* Fixed test

* AppChrome outside route

* Renaming folder

* Minor fix

* Updated

* Fixing StoragePage

* Fix for banners

Co-authored-by: Ashley Harrison <ashley.harrison@grafana.com>
2022-07-06 17:00:56 +02:00

52 lines
1.5 KiB
TypeScript

import { render, screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import React from 'react';
import { BackendSrv, setBackendSrv } from '@grafana/runtime';
import { CreateTeam } from './CreateTeam';
beforeEach(() => {
jest.clearAllMocks();
});
const mockPost = jest.fn(() => {
return Promise.resolve({});
});
setBackendSrv({
post: mockPost,
} as any as BackendSrv);
const setup = () => {
return render(<CreateTeam />);
};
describe('Create team', () => {
it('should render component', () => {
setup();
expect(screen.getByText(/new team/i)).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();
});
});