1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- import {Organization} from 'fixtures/js-stubs/organization';
- import {Project} from 'fixtures/js-stubs/project';
- import {routerContext} from 'fixtures/js-stubs/routerContext';
- import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
- import {Client} from 'sentry/api';
- import {ErrorRobot} from 'sentry/components/errorRobot';
- describe('ErrorRobot', function () {
- let getIssues;
- let routerContext;
- beforeEach(function () {
- routerContext = routerContext();
- getIssues = Client.addMockResponse({
- url: '/projects/org-slug/project-slug/issues/',
- method: 'GET',
- body: [],
- });
- });
- afterEach(() => {
- jest.clearAllMocks();
- Client.clearMockResponses();
- });
- describe('with a project', function () {
- function createWrapper() {
- return render(
- <ErrorRobot api={new MockApiClient()} org={Organization()} project={Project()} />,
- {context: routerContext}
- );
- }
- it('Renders a button for creating an event', function () {
- createWrapper();
- const button = screen.getByRole('button', {name: 'Create a sample event'});
- expect(button).toBeEnabled();
- expect(getIssues).toHaveBeenCalled();
- });
- it('Renders installation instructions', function () {
- createWrapper();
- userEvent.click(screen.getByText('Installation Instructions'));
- expect(routerContext.context.router.push).toHaveBeenCalledWith(
- '/org-slug/project-slug/getting-started/'
- );
- });
- });
- describe('without a project', function () {
- function createWrapper() {
- return render(<ErrorRobot api={new MockApiClient()} org={Organization()} />, {
- context: routerContext,
- });
- }
- it('Renders a disabled create event button', function () {
- createWrapper();
- const button = screen.getByRole('button', {name: 'Create a sample event'});
- expect(button).toBeDisabled();
- expect(getIssues).toHaveBeenCalledTimes(0);
- });
- it('does not display install instructions', function () {
- createWrapper();
- expect(screen.queryByText('Installation Instructions')).not.toBeInTheDocument();
- });
- });
- });
|