Browse Source

test(dashboards): Replace flaky acceptance test (#81203)

Removes a flaky dashboard test and tests the functionality in jest. We
can validate that the API is called with the correct props and the other
tests handle rendering the dashboard.
Nar Saynorath 3 months ago
parent
commit
7efb91bbb2

+ 67 - 0
static/app/views/dashboards/dashboard.spec.tsx

@@ -2,6 +2,7 @@ import {LocationFixture} from 'sentry-fixture/locationFixture';
 import {OrganizationFixture} from 'sentry-fixture/organization';
 import {RouterFixture} from 'sentry-fixture/routerFixture';
 import {TagsFixture} from 'sentry-fixture/tags';
+import {WidgetFixture} from 'sentry-fixture/widget';
 
 import {initializeOrg} from 'sentry-test/initializeOrg';
 import {render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrary';
@@ -294,6 +295,72 @@ describe('Dashboards > Dashboard', () => {
     });
   });
 
+  it('handles duplicate widget in view mode', async () => {
+    const mockOnUpdate = jest.fn();
+    const mockHandleUpdateWidgetList = jest.fn();
+
+    const dashboardWithOneWidget = {
+      ...mockDashboard,
+      widgets: [
+        WidgetFixture({
+          id: '1',
+          layout: {
+            h: 1,
+            w: 1,
+            x: 0,
+            y: 0,
+            minH: 1,
+          },
+        }),
+      ],
+    };
+
+    render(
+      <OrganizationContext.Provider value={initialData.organization}>
+        <MEPSettingProvider forceTransactions={false}>
+          <Dashboard
+            paramDashboardId="1"
+            dashboard={dashboardWithOneWidget}
+            organization={initialData.organization}
+            isEditingDashboard={false}
+            onUpdate={mockOnUpdate}
+            handleUpdateWidgetList={mockHandleUpdateWidgetList}
+            handleAddCustomWidget={() => undefined}
+            router={initialData.router}
+            location={initialData.router.location}
+            widgetLimitReached={false}
+            onSetNewWidget={() => undefined}
+            widgetLegendState={widgetLegendState}
+          />
+        </MEPSettingProvider>
+      </OrganizationContext.Provider>
+    );
+
+    await userEvent.click(await screen.findByLabelText('Widget actions'));
+    await userEvent.click(await screen.findByText('Duplicate Widget'));
+
+    // The new widget is inserted before the duplicated widget
+    const expectedWidgets = [
+      // New Widget
+      expect.objectContaining(
+        WidgetFixture({
+          id: undefined,
+          layout: expect.objectContaining({h: 1, w: 1, x: 0, y: 0, minH: 1}),
+        })
+      ),
+      // Duplicated Widget
+      expect.objectContaining(
+        WidgetFixture({
+          id: '1',
+          layout: expect.objectContaining({h: 1, w: 1, x: 0, y: 1, minH: 1}),
+        })
+      ),
+    ];
+
+    expect(mockHandleUpdateWidgetList).toHaveBeenCalledWith(expectedWidgets);
+    expect(mockOnUpdate).toHaveBeenCalledWith(expectedWidgets);
+  });
+
   describe('Issue Widgets', () => {
     beforeEach(() => {
       MemberListStore.init();

+ 0 - 37
tests/acceptance/test_organization_dashboards.py

@@ -360,43 +360,6 @@ class OrganizationDashboardsAcceptanceTest(AcceptanceTestCase):
 
             self.page.wait_until_loaded()
 
-    @pytest.mark.skip(reason="Flaky")
-    def test_duplicate_widget_in_view_mode(self):
-        existing_widget = DashboardWidget.objects.create(
-            dashboard=self.dashboard,
-            order=0,
-            title="Big Number Widget",
-            display_type=DashboardWidgetDisplayTypes.BIG_NUMBER,
-            widget_type=DashboardWidgetTypes.DISCOVER,
-            interval="1d",
-        )
-        DashboardWidgetQuery.objects.create(
-            widget=existing_widget,
-            fields=["count_unique(issue)"],
-            columns=[],
-            aggregates=["count_unique(issue)"],
-            order=0,
-        )
-        with self.feature(FEATURE_NAMES + EDIT_FEATURE):
-            self.page.visit_dashboard_detail()
-
-            # Hover over the widget to show widget actions
-            self.browser.move_to('[aria-label="Widget panel"]')
-
-            self.browser.element('[aria-label="Widget actions"]').click()
-            self.browser.element('[data-test-id="duplicate-widget"]').click()
-            self.page.wait_until_loaded()
-
-            self.browser.element('[aria-label="Widget actions"]').click()
-            self.browser.element('[data-test-id="duplicate-widget"]').click()
-            self.page.wait_until_loaded()
-
-            # Should not trigger alert
-            self.page.enter_edit_state()
-            self.page.click_cancel_button()
-            wait = WebDriverWait(self.browser.driver, 5)
-            wait.until_not(EC.alert_is_present())
-
     def test_delete_widget_in_view_mode(self):
         existing_widget = DashboardWidget.objects.create(
             dashboard=self.dashboard,