nameAndDescFields.spec.tsx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {RouterFixture} from 'sentry-fixture/routerFixture';
  3. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  4. import {useNavigate} from 'sentry/utils/useNavigate';
  5. import WidgetBuilderNameAndDescription from 'sentry/views/dashboards/widgetBuilder/components/nameAndDescFields';
  6. import {WidgetBuilderProvider} from 'sentry/views/dashboards/widgetBuilder/contexts/widgetBuilderContext';
  7. jest.mock('sentry/utils/useNavigate', () => ({
  8. useNavigate: jest.fn(),
  9. }));
  10. const mockUseNavigate = jest.mocked(useNavigate);
  11. describe('WidgetBuilder', () => {
  12. let router;
  13. let organization;
  14. beforeEach(function () {
  15. router = RouterFixture({
  16. location: {
  17. pathname: '/organizations/org-slug/dashboard/1/',
  18. query: {project: '-1'},
  19. },
  20. params: {},
  21. });
  22. organization = OrganizationFixture({});
  23. });
  24. it('edits name and description', async function () {
  25. const mockNavigate = jest.fn();
  26. mockUseNavigate.mockReturnValue(mockNavigate);
  27. render(
  28. <WidgetBuilderProvider>
  29. <WidgetBuilderNameAndDescription />
  30. </WidgetBuilderProvider>,
  31. {
  32. router,
  33. organization,
  34. }
  35. );
  36. await userEvent.type(await screen.findByPlaceholderText('Name'), 'some name');
  37. expect(mockNavigate).toHaveBeenLastCalledWith(
  38. expect.objectContaining({
  39. ...router.location,
  40. query: expect.objectContaining({title: 'some name'}),
  41. })
  42. );
  43. await userEvent.click(await screen.findByTestId('add-description'));
  44. await userEvent.type(
  45. await screen.findByPlaceholderText('Description'),
  46. 'some description'
  47. );
  48. expect(mockNavigate).toHaveBeenLastCalledWith(
  49. expect.objectContaining({
  50. ...router.location,
  51. query: expect.objectContaining({description: 'some description'}),
  52. })
  53. );
  54. });
  55. });