Skip to content

Commit

Permalink
test(dashboards): Replace flaky acceptance test (#81203)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
narsaynorath authored Nov 22, 2024
1 parent 9d8bebb commit 7efb91b
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 37 deletions.
67 changes: 67 additions & 0 deletions static/app/views/dashboards/dashboard.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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();
Expand Down
37 changes: 0 additions & 37 deletions tests/acceptance/test_organization_dashboards.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,43 +360,6 @@ def test_default_layout_when_widgets_do_not_have_layout_set(self):

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,
Expand Down

0 comments on commit 7efb91b

Please sign in to comment.