noDataMessage.spec.tsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. import {PageFiltersFixture} from 'sentry-fixture/pageFilters';
  2. import {ProjectFixture} from 'sentry-fixture/project';
  3. import {ProjectSdkUpdatesFixture} 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([
  17. ProjectFixture({
  18. name: 'Awesome API',
  19. slug: 'awesome-api',
  20. features: ['span-metrics-extraction'],
  21. }),
  22. ]);
  23. usePageFilters.mockImplementation(() => ({
  24. selection: PageFiltersFixture({projects: [2]}),
  25. isReady: true,
  26. shouldPersist: true,
  27. pinnedFilters: new Set(),
  28. desyncedFilters: new Set(),
  29. }));
  30. });
  31. afterEach(() => {
  32. ProjectsStore.reset();
  33. });
  34. it('does not show anything if there is recent data', function () {
  35. MockApiClient.addMockResponse({
  36. url: '/organizations/org-slug/sdk-updates/',
  37. body: [],
  38. });
  39. render(<NoDataMessage isDataAvailable />);
  40. expect(
  41. screen.queryByText(textWithMarkupMatcher('No queries found.'))
  42. ).not.toBeInTheDocument();
  43. });
  44. it('shows a no data message if there is no recent data', async function () {
  45. const sdkMock = MockApiClient.addMockResponse({
  46. url: '/organizations/org-slug/sdk-updates/',
  47. body: [],
  48. });
  49. render(<NoDataMessage isDataAvailable={false} />);
  50. await waitFor(() => expect(sdkMock).toHaveBeenCalled());
  51. await tick(); // There is no visual indicator, this awaits the promise resolve
  52. expect(
  53. screen.queryByText(textWithMarkupMatcher('No queries found.'))
  54. ).toBeInTheDocument();
  55. expect(
  56. screen.queryByText(
  57. textWithMarkupMatcher('You may be missing data due to outdated SDKs')
  58. )
  59. ).not.toBeInTheDocument();
  60. });
  61. it('shows a list of outdated SDKs if there is no data available and SDKs are outdated', async function () {
  62. const sdkMock = MockApiClient.addMockResponse({
  63. url: '/organizations/org-slug/sdk-updates/',
  64. body: [ProjectSdkUpdatesFixture({projectId: '2'})],
  65. });
  66. render(<NoDataMessage isDataAvailable={false} />);
  67. await waitFor(() => expect(sdkMock).toHaveBeenCalled());
  68. await tick(); // There is no visual indicator, this awaits the promise resolve
  69. expect(
  70. screen.queryByText(textWithMarkupMatcher('No queries found.'))
  71. ).toBeInTheDocument();
  72. expect(
  73. screen.getByText(
  74. textWithMarkupMatcher('You may be missing data due to outdated SDKs')
  75. )
  76. ).toBeInTheDocument();
  77. expect(screen.getAllByRole('link')[1]).toHaveAttribute(
  78. 'href',
  79. '/organizations/org-slug/projects/awesome-api/'
  80. );
  81. });
  82. it('shows a list of denylisted projects if any are are set even if data is available', async function () {
  83. ProjectsStore.loadInitialData([
  84. ProjectFixture({
  85. name: 'Awful API',
  86. slug: 'awful-api',
  87. features: [],
  88. }),
  89. ]);
  90. render(<NoDataMessage isDataAvailable />);
  91. await tick(); // There is no visual indicator, this awaits the promise resolve
  92. expect(
  93. screen.getByText(
  94. textWithMarkupMatcher(
  95. 'Some of your projects have been omitted from query performance analysis'
  96. )
  97. )
  98. ).toBeInTheDocument();
  99. expect(screen.getAllByRole('link')[0]).toHaveAttribute(
  100. 'href',
  101. '/organizations/org-slug/projects/awful-api/'
  102. );
  103. });
  104. });