noDataMessage.spec.tsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import {PageFilters} from 'sentry-fixture/pageFilters';
  2. import {Project} from 'sentry-fixture/project';
  3. import {ProjectSdkUpdates} from 'sentry-fixture/projectSdkUpdates';
  4. import {render, screen, waitFor} from 'sentry-test/reactTestingLibrary';
  5. import {textWithMarkupMatcher} from 'sentry-test/utils';
  6. import ProjectsStore from 'sentry/stores/projectsStore';
  7. import importedUsePageFilters from 'sentry/utils/usePageFilters';
  8. jest.mock('sentry/utils/usePageFilters');
  9. const usePageFilters = jest.mocked(importedUsePageFilters);
  10. import {NoDataMessage} from 'sentry/views/performance/database/noDataMessage';
  11. describe('NoDataMessage', () => {
  12. beforeEach(() => {
  13. jest.clearAllMocks();
  14. MockApiClient.clearMockResponses();
  15. usePageFilters.mockClear();
  16. ProjectsStore.loadInitialData([Project({name: 'Awesome API', slug: 'awesome-api'})]);
  17. usePageFilters.mockImplementation(() => ({
  18. selection: PageFilters({projects: [2]}),
  19. isReady: true,
  20. shouldPersist: true,
  21. pinnedFilters: new Set(),
  22. desyncedFilters: new Set(),
  23. }));
  24. });
  25. it('does not show anything if there is recent data', async function () {
  26. MockApiClient.addMockResponse({
  27. url: '/organizations/org-slug/sdk-updates/',
  28. body: [],
  29. });
  30. const eventsMock = MockApiClient.addMockResponse({
  31. url: '/organizations/org-slug/events/',
  32. body: {
  33. data: [{'project.id': 2, 'count()': 1}],
  34. },
  35. });
  36. render(<NoDataMessage />);
  37. await waitFor(() => expect(eventsMock).toHaveBeenCalled());
  38. await tick(); // There is no visual indicator, this awaits the promise resolve
  39. expect(
  40. screen.queryByText(textWithMarkupMatcher('No queries found.'))
  41. ).not.toBeInTheDocument();
  42. });
  43. it('shows a no data message if there is no recent data', async function () {
  44. MockApiClient.addMockResponse({
  45. url: '/organizations/org-slug/sdk-updates/',
  46. body: [],
  47. });
  48. const eventsMock = MockApiClient.addMockResponse({
  49. url: '/organizations/org-slug/events/',
  50. body: {
  51. data: [],
  52. },
  53. });
  54. render(<NoDataMessage />);
  55. await waitFor(() => expect(eventsMock).toHaveBeenCalled());
  56. await tick(); // There is no visual indicator, this awaits the promise resolve
  57. expect(
  58. screen.queryByText(textWithMarkupMatcher('No queries found.'))
  59. ).toBeInTheDocument();
  60. expect(
  61. screen.queryByText(
  62. textWithMarkupMatcher('You may also be missing data due to outdated SDKs')
  63. )
  64. ).not.toBeInTheDocument();
  65. });
  66. it('shows a list of outdated SDKs if there is no data available and SDKs are outdated', async function () {
  67. const sdkMock = MockApiClient.addMockResponse({
  68. url: '/organizations/org-slug/sdk-updates/',
  69. body: [ProjectSdkUpdates({projectId: '2'})],
  70. });
  71. const eventsMock = MockApiClient.addMockResponse({
  72. url: '/organizations/org-slug/events/',
  73. body: {
  74. data: [],
  75. },
  76. });
  77. render(<NoDataMessage />);
  78. await waitFor(() => expect(eventsMock).toHaveBeenCalled());
  79. await waitFor(() => expect(sdkMock).toHaveBeenCalled());
  80. await tick(); // There is no visual indicator, this awaits the promise resolve
  81. expect(
  82. screen.queryByText(textWithMarkupMatcher('No queries found.'))
  83. ).toBeInTheDocument();
  84. expect(
  85. screen.getByText(
  86. textWithMarkupMatcher('You may also be missing data due to outdated SDKs')
  87. )
  88. ).toBeInTheDocument();
  89. expect(screen.getAllByRole('link')[1]).toHaveAttribute(
  90. 'href',
  91. '/organizations/org-slug/projects/awesome-api/'
  92. );
  93. });
  94. });