Browse Source

test(ui): Fix various act warnings in tests (#67203)

Scott Cooper 11 months ago
parent
commit
c00d040076

+ 4 - 4
static/app/components/events/eventEntries.spec.tsx

@@ -4,7 +4,7 @@ import {LocationFixture} from 'sentry-fixture/locationFixture';
 import {OrganizationFixture} from 'sentry-fixture/organization';
 import {ProjectFixture} from 'sentry-fixture/project';
 
-import {render, screen} from 'sentry-test/reactTestingLibrary';
+import {render, screen, waitFor} from 'sentry-test/reactTestingLibrary';
 
 import {EventEntries} from 'sentry/components/events/eventEntries';
 
@@ -49,12 +49,12 @@ describe('EventEntries', function () {
       {organization: OrganizationFixture({features: ['session-replay']})}
     );
 
-    await screen.findByText(/message/i);
+    await waitFor(() => {
+      expect(screen.getAllByTestId(/event-section/)).toHaveLength(5); //  event tags + 3 entries + event grouping
+    });
 
     const sections = screen.getAllByTestId(/event-section/);
 
-    expect(sections).toHaveLength(5); //  event tags + 3 entries + event grouping
-
     // Replay should be after message but before images loaded
     expect(sections[1]).toHaveTextContent(/message/i);
     expect(sections[2]).toHaveTextContent(/replay/i);

+ 1 - 1
static/app/components/events/interfaces/crashContent/exception/actionableItems.tsx

@@ -391,7 +391,7 @@ export function ActionableItems({event, project, isShare}: ActionableItemsProps)
   if (
     isLoading ||
     !defined(data) ||
-    data.errors.length === 0 ||
+    data.errors?.length === 0 ||
     Object.keys(errorMessages).length === 0
   ) {
     return null;

+ 1 - 1
static/app/components/modals/widgetViewerModal.spec.tsx

@@ -805,7 +805,7 @@ describe('Modals -> WidgetViewerModal', function () {
         mockEventsStats();
         mockEvents();
         const {rerender} = await renderModal({initialData, widget: mockWidget});
-        expect(screen.getByText('Test Error 1c')).toBeInTheDocument();
+        expect(await screen.findByText('Test Error 1c')).toBeInTheDocument();
         await userEvent.click(screen.getByRole('button', {name: 'Next'}));
         expect(initialData.router.replace).toHaveBeenCalledWith(
           expect.objectContaining({

+ 2 - 1
static/app/views/issueDetails/actions/index.spec.tsx

@@ -53,7 +53,7 @@ describe('GroupActions', function () {
   });
 
   describe('render()', function () {
-    it('renders correctly', function () {
+    it('renders correctly', async function () {
       render(
         <GroupActions
           group={group}
@@ -62,6 +62,7 @@ describe('GroupActions', function () {
           disabled={false}
         />
       );
+      expect(await screen.findByRole('button', {name: 'Resolve'})).toBeInTheDocument();
     });
   });
 

+ 2 - 2
static/app/views/organizationStats/teamInsights/health.spec.tsx

@@ -195,10 +195,10 @@ describe('TeamStatsHealth', () => {
     });
   }
 
-  it('defaults to first team', () => {
+  it('defaults to first team', async () => {
     createWrapper();
 
-    expect(screen.getByText('#backend')).toBeInTheDocument();
+    expect(await screen.findByText('#backend')).toBeInTheDocument();
     expect(screen.getByText('Key transaction')).toBeInTheDocument();
   });
 

+ 4 - 0
static/app/views/performance/transactionSummary/transactionAnomalies/index.spec.tsx

@@ -32,6 +32,10 @@ describe('AnomaliesTab', function () {
       url: '/organizations/org-slug/events-has-measurements/',
       body: {measurements: false},
     });
+    MockApiClient.addMockResponse({
+      url: '/organizations/org-slug/replay-count/',
+      body: {},
+    });
     anomaliesMock = MockApiClient.addMockResponse({
       url: '/organizations/org-slug/transaction-anomaly-detection/',
       body: {},

+ 18 - 18
static/app/views/performance/transactionSummary/transactionEvents/content.spec.tsx

@@ -5,7 +5,6 @@ import {initializeOrg} from 'sentry-test/initializeOrg';
 import {act, render, screen} from 'sentry-test/reactTestingLibrary';
 import {textWithMarkupMatcher} from 'sentry-test/utils';
 
-import {t} from 'sentry/locale';
 import ProjectsStore from 'sentry/stores/projectsStore';
 import EventView from 'sentry/utils/discover/eventView';
 import {
@@ -176,7 +175,7 @@ describe('Performance Transaction Events Content', function () {
     jest.clearAllMocks();
   });
 
-  it('basic rendering', function () {
+  it('basic rendering', async function () {
     render(
       <OrganizationContext.Provider value={initialData.organization}>
         <EventsPageContent
@@ -196,27 +195,27 @@ describe('Performance Transaction Events Content', function () {
       {context: initialData.routerContext}
     );
 
-    expect(screen.getByTestId('events-table')).toBeInTheDocument();
+    expect(await screen.findByTestId('events-table')).toBeInTheDocument();
     expect(screen.getByText(textWithMarkupMatcher('Percentilep100'))).toBeInTheDocument();
     expect(
-      screen.getByPlaceholderText(t('Search for events, users, tags, and more'))
+      screen.getByPlaceholderText('Search for events, users, tags, and more')
     ).toBeInTheDocument();
     expect(screen.getByRole('button', {name: 'Filter by operation'})).toBeInTheDocument();
 
     const columnTitles = screen
       .getAllByRole('columnheader')
-      .map(elem => elem.textContent);
+      .map(elem => elem.textContent?.trim());
     expect(columnTitles).toEqual([
-      t('event id'),
-      t('user'),
-      t('operation duration'),
-      t('total duration'),
-      t('trace id'),
-      t('timestamp'),
+      'event id',
+      'user',
+      'operation duration',
+      'total duration',
+      'trace id',
+      'timestamp',
     ]);
   });
 
-  it('rendering with webvital selected', function () {
+  it('rendering with webvital selected', async function () {
     render(
       <OrganizationContext.Provider value={initialData.organization}>
         <EventsPageContent
@@ -237,20 +236,20 @@ describe('Performance Transaction Events Content', function () {
       {context: initialData.routerContext}
     );
 
-    expect(screen.getByTestId('events-table')).toBeInTheDocument();
+    expect(await screen.findByTestId('events-table')).toBeInTheDocument();
     expect(screen.getByText(textWithMarkupMatcher('Percentilep100'))).toBeInTheDocument();
     expect(
-      screen.getByPlaceholderText(t('Search for events, users, tags, and more'))
+      screen.getByPlaceholderText('Search for events, users, tags, and more')
     ).toBeInTheDocument();
     expect(screen.getByRole('button', {name: 'Filter by operation'})).toBeInTheDocument();
 
     const columnTitles = screen
       .getAllByRole('columnheader')
-      .map(elem => elem.textContent);
-    expect(columnTitles).toStrictEqual(expect.arrayContaining([t('measurements.lcp')]));
+      .map(elem => elem.textContent?.trim());
+    expect(columnTitles).toStrictEqual(expect.arrayContaining(['measurements.lcp']));
   });
 
-  it('rendering with http.method', function () {
+  it('rendering with http.method', async function () {
     const _eventView = EventView.fromNewQueryWithLocation(
       {
         id: undefined,
@@ -283,9 +282,10 @@ describe('Performance Transaction Events Content', function () {
       {context: initialData.routerContext}
     );
 
+    expect(await screen.findByTestId('events-table')).toBeInTheDocument();
     const columnTitles = screen
       .getAllByRole('columnheader')
       .map(elem => elem.textContent);
-    expect(columnTitles).toStrictEqual(expect.arrayContaining([t('http.method')]));
+    expect(columnTitles).toStrictEqual(expect.arrayContaining(['http.method']));
   });
 });

+ 9 - 10
static/app/views/performance/transactionSummary/transactionTags/index.spec.tsx

@@ -175,7 +175,7 @@ describe('Performance > Transaction Tags', function () {
       },
     });
 
-    expect(screen.getByRole('radio', {name: 'hardwareConcurrency'})).toBeChecked();
+    expect(await screen.findByRole('radio', {name: 'hardwareConcurrency'})).toBeChecked();
   });
 
   it('Default tagKey is set when loading the page without one', async function () {
@@ -200,7 +200,7 @@ describe('Performance > Transaction Tags', function () {
       },
     });
 
-    expect(histogramMock).toHaveBeenCalledTimes(1);
+    await waitFor(() => expect(histogramMock).toHaveBeenCalledTimes(1));
     expect(histogramMock).toHaveBeenNthCalledWith(
       1,
       expect.anything(),
@@ -237,7 +237,7 @@ describe('Performance > Transaction Tags', function () {
       },
     });
 
-    expect(histogramMock).toHaveBeenCalledTimes(1);
+    await waitFor(() => expect(histogramMock).toHaveBeenCalledTimes(1));
     expect(histogramMock).toHaveBeenNthCalledWith(
       1,
       expect.anything(),
@@ -264,7 +264,7 @@ describe('Performance > Transaction Tags', function () {
     });
 
     // Release link is properly setup
-    expect(screen.getByText(TEST_RELEASE_NAME)).toBeInTheDocument();
+    expect(await screen.findByText(TEST_RELEASE_NAME)).toBeInTheDocument();
     expect(screen.getByText(TEST_RELEASE_NAME).parentElement).toHaveAttribute(
       'href',
       `/organizations/${initialData.organization.slug}/releases/${encodeURIComponent(
@@ -297,8 +297,8 @@ describe('Performance > Transaction Tags', function () {
       },
     });
 
-    expect(screen.getByRole('radio', {name: 'hardwareConcurrency'})).toBeChecked();
-    expect(screen.getByRole('button', {name: 'Next'})).toHaveAttribute(
+    expect(await screen.findByRole('radio', {name: 'hardwareConcurrency'})).toBeChecked();
+    expect(await screen.findByRole('button', {name: 'Next'})).toHaveAttribute(
       'aria-disabled',
       'false'
     );
@@ -342,10 +342,11 @@ describe('Performance > Transaction Tags', function () {
     });
 
     await waitFor(() => {
+      // Table is loaded.
       expect(screen.getByRole('table')).toBeInTheDocument();
     });
 
-    expect(histogramMock).toHaveBeenCalledTimes(1);
+    await waitFor(() => expect(histogramMock).toHaveBeenCalledTimes(1));
 
     expect(histogramMock).toHaveBeenNthCalledWith(
       1,
@@ -359,9 +360,7 @@ describe('Performance > Transaction Tags', function () {
 
     await selectEvent.select(screen.getByText('X-Axis'), 'LCP');
 
-    await waitFor(() => {
-      expect(screen.getByRole('table')).toBeInTheDocument();
-    });
+    expect(await screen.findByRole('table')).toBeInTheDocument();
 
     expect(histogramMock).toHaveBeenCalledTimes(2);
 

+ 2 - 2
static/app/views/performance/transactionSummary/transactionVitals/index.spec.tsx

@@ -237,8 +237,8 @@ describe('Performance > Web Vitals', function () {
       );
     });
 
-    it.each(vitals)('Renders %s', function (vital) {
-      expect(screen.getByText(vital.heading)).toBeInTheDocument();
+    it.each(vitals)('Renders %s', async function (vital) {
+      expect(await screen.findByText(vital.heading)).toBeInTheDocument();
       expect(screen.getByText(vital.baseline)).toBeInTheDocument();
     });
   });

+ 8 - 4
static/app/views/performance/vitalDetail/index.spec.tsx

@@ -437,16 +437,17 @@ describe('Performance > VitalDetail', function () {
     expect(screen.getByText('4.50s').closest('td')).toBeInTheDocument();
   });
 
-  it('correctly renders which browsers support LCP', function () {
+  it('correctly renders which browsers support LCP', async function () {
     render(<TestComponent />, {
       context: routerContext,
       organization: org,
     });
 
+    expect(await screen.findAllByText(/Largest Contentful Paint/)).toHaveLength(2);
     testSupportedBrowserRendering(WebVital.LCP);
   });
 
-  it('correctly renders which browsers support CLS', function () {
+  it('correctly renders which browsers support CLS', async function () {
     const newRouter = {
       ...router,
       location: {
@@ -462,10 +463,11 @@ describe('Performance > VitalDetail', function () {
       organization: org,
     });
 
+    expect(await screen.findAllByText(/Cumulative Layout Shift/)).toHaveLength(2);
     testSupportedBrowserRendering(WebVital.CLS);
   });
 
-  it('correctly renders which browsers support FCP', function () {
+  it('correctly renders which browsers support FCP', async function () {
     const newRouter = {
       ...router,
       location: {
@@ -486,10 +488,11 @@ describe('Performance > VitalDetail', function () {
       organization: org,
     });
 
+    expect(await screen.findAllByText(/First Contentful Paint/)).toHaveLength(2);
     testSupportedBrowserRendering(WebVital.FCP);
   });
 
-  it('correctly renders which browsers support FID', function () {
+  it('correctly renders which browsers support FID', async function () {
     const newRouter = {
       ...router,
       location: {
@@ -510,6 +513,7 @@ describe('Performance > VitalDetail', function () {
       organization: org,
     });
 
+    expect(await screen.findAllByText(/First Input Delay/)).toHaveLength(2);
     testSupportedBrowserRendering(WebVital.FID);
   });
 });

Some files were not shown because too many files changed in this diff