broadcasts.spec.tsx 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import {BroadcastFixture} from 'sentry-fixture/broadcast';
  2. import {OrganizationFixture} from 'sentry-fixture/organization';
  3. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  4. import {BROADCAST_CATEGORIES} from 'sentry/components/sidebar/broadcastPanelItem';
  5. import {Broadcasts} from 'sentry/components/sidebar/broadcasts';
  6. import {SidebarPanelKey} from 'sentry/components/sidebar/types';
  7. import type {Broadcast} from 'sentry/types/system';
  8. import {trackAnalytics} from 'sentry/utils/analytics';
  9. jest.mock('sentry/utils/analytics');
  10. function renderMockRequests({
  11. orgSlug,
  12. broadcastsResponse,
  13. }: {
  14. orgSlug: string;
  15. broadcastsResponse?: Broadcast[];
  16. }) {
  17. MockApiClient.addMockResponse({
  18. url: '/broadcasts/',
  19. method: 'PUT',
  20. });
  21. MockApiClient.addMockResponse({
  22. url: `/organizations/${orgSlug}/broadcasts/`,
  23. body: broadcastsResponse ?? [],
  24. });
  25. }
  26. describe('Broadcasts', function () {
  27. const category = 'blog';
  28. it('renders empty state', async function () {
  29. const organization = OrganizationFixture();
  30. renderMockRequests({orgSlug: organization.slug});
  31. render(
  32. <Broadcasts
  33. orientation="left"
  34. collapsed={false}
  35. currentPanel={SidebarPanelKey.BROADCASTS}
  36. onShowPanel={() => jest.fn()}
  37. hidePanel={jest.fn()}
  38. />
  39. );
  40. expect(await screen.findByText(/No recent updates/)).toBeInTheDocument();
  41. });
  42. it('renders a broadcast item with media content correctly', async function () {
  43. const organization = OrganizationFixture();
  44. const broadcast = BroadcastFixture({
  45. mediaUrl:
  46. 'https://images.ctfassets.net/em6l9zw4tzag/2vWdw7ZaApWxygugalbyOC/285525e5b7c9fbfa8fb814a69ab214cd/PerformancePageSketches_hero.jpg?w=2520&h=945&q=50&fm=webp',
  47. category,
  48. });
  49. renderMockRequests({orgSlug: organization.slug, broadcastsResponse: [broadcast]});
  50. render(
  51. <Broadcasts
  52. orientation="left"
  53. collapsed={false}
  54. currentPanel={SidebarPanelKey.BROADCASTS}
  55. onShowPanel={() => jest.fn()}
  56. hidePanel={jest.fn()}
  57. />
  58. );
  59. // Verify that the broadcast content is rendered correctly
  60. expect(await screen.findByText(BROADCAST_CATEGORIES[category])).toBeInTheDocument();
  61. const titleLink = screen.getByRole('link', {name: broadcast.title});
  62. expect(titleLink).toHaveAttribute('href', broadcast.link);
  63. expect(screen.getByText(/Source maps are JSON/)).toBeInTheDocument();
  64. // Simulate click and check if analytics tracking is called
  65. await userEvent.click(titleLink);
  66. expect(trackAnalytics).toHaveBeenCalledWith(
  67. 'whats_new.link_clicked',
  68. expect.objectContaining({
  69. title: broadcast.title,
  70. category,
  71. })
  72. );
  73. });
  74. });