|
@@ -594,5 +594,65 @@ describe('Dashboards > Detail', function () {
|
|
|
|
|
|
expect(window.confirm).not.toHaveBeenCalled();
|
|
|
});
|
|
|
+
|
|
|
+ it('opens the widget viewer modal using the widget id specified in the url', () => {
|
|
|
+ const openWidgetViewerModal = jest.spyOn(modals, 'openWidgetViewerModal');
|
|
|
+ const widget = TestStubs.Widget(
|
|
|
+ [{name: '', conditions: 'event.type:error', fields: ['count()']}],
|
|
|
+ {
|
|
|
+ title: 'First Widget',
|
|
|
+ interval: '1d',
|
|
|
+ id: '1',
|
|
|
+ layout: null,
|
|
|
+ }
|
|
|
+ );
|
|
|
+ MockApiClient.addMockResponse({
|
|
|
+ url: '/organizations/org-slug/dashboards/1/',
|
|
|
+ body: TestStubs.Dashboard([widget], {id: '1', title: 'Custom Errors'}),
|
|
|
+ });
|
|
|
+
|
|
|
+ rtlMountWithTheme(
|
|
|
+ <ViewEditDashboard
|
|
|
+ organization={initialData.organization}
|
|
|
+ params={{orgId: 'org-slug', dashboardId: '1', widgetId: '1'}}
|
|
|
+ router={initialData.router}
|
|
|
+ location={{...initialData.router.location, pathname: '/widget/123/'}}
|
|
|
+ />,
|
|
|
+ {context: initialData.routerContext}
|
|
|
+ );
|
|
|
+
|
|
|
+ expect(openWidgetViewerModal).toHaveBeenCalledWith(
|
|
|
+ expect.objectContaining({
|
|
|
+ organization: initialData.organization,
|
|
|
+ widget,
|
|
|
+ onClose: expect.anything(),
|
|
|
+ })
|
|
|
+ );
|
|
|
+ });
|
|
|
+
|
|
|
+ it('redirects user to dashboard url if widget is not found', () => {
|
|
|
+ const openWidgetViewerModal = jest.spyOn(modals, 'openWidgetViewerModal');
|
|
|
+ MockApiClient.addMockResponse({
|
|
|
+ url: '/organizations/org-slug/dashboards/1/',
|
|
|
+ body: TestStubs.Dashboard([], {id: '1', title: 'Custom Errors'}),
|
|
|
+ });
|
|
|
+ rtlMountWithTheme(
|
|
|
+ <ViewEditDashboard
|
|
|
+ organization={initialData.organization}
|
|
|
+ params={{orgId: 'org-slug', dashboardId: '1', widgetId: '123'}}
|
|
|
+ router={initialData.router}
|
|
|
+ location={{...initialData.router.location, pathname: '/widget/123/'}}
|
|
|
+ />,
|
|
|
+ {context: initialData.routerContext}
|
|
|
+ );
|
|
|
+
|
|
|
+ expect(openWidgetViewerModal).not.toHaveBeenCalled();
|
|
|
+ expect(initialData.router.replace).toHaveBeenCalledWith(
|
|
|
+ expect.objectContaining({
|
|
|
+ pathname: '/organizations/org-slug/dashboard/1/',
|
|
|
+ query: {},
|
|
|
+ })
|
|
|
+ );
|
|
|
+ });
|
|
|
});
|
|
|
});
|