123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- import {mountWithTheme} from 'sentry-test/enzyme';
- import {initializeOrg} from 'sentry-test/initializeOrg';
- import {Client} from 'sentry/api';
- import DashboardWidgetQuerySelectorModal from 'sentry/components/modals/dashboardWidgetQuerySelectorModal';
- import {t} from 'sentry/locale';
- import {DisplayType} from 'sentry/views/dashboardsV2/types';
- const stubEl: any = (props: any) => <div>{props.children}</div>;
- const api: Client = new Client();
- function mountModal({initialData, widget}) {
- return mountWithTheme(
- <DashboardWidgetQuerySelectorModal
- Header={stubEl}
- Footer={stubEl}
- Body={stubEl}
- CloseButton={stubEl}
- closeModal={() => {}}
- organization={initialData.organization}
- widget={widget}
- api={api}
- />,
- initialData.routerContext
- );
- }
- describe('Modals -> AddDashboardWidgetModal', function () {
- const initialData = initializeOrg({
- organization: {
- features: ['performance-view', 'discover-query'],
- apdexThreshold: 400,
- },
- router: {},
- project: 1,
- projects: [],
- });
- let mockQuery;
- let mockWidget;
- beforeEach(function () {
- mockQuery = {
- conditions: 'title:/organizations/:orgId/performance/summary/',
- fields: ['count()', 'failure_count()'],
- aggregates: ['count()', 'failure_count()'],
- columns: [],
- id: '1',
- name: 'Query Name',
- orderby: '',
- };
- mockWidget = {
- title: 'Test Widget',
- displayType: DisplayType.AREA,
- interval: '5m',
- queries: [mockQuery],
- };
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/dashboards/widgets/',
- method: 'POST',
- statusCode: 200,
- body: [],
- });
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/events-stats/',
- body: [],
- });
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/eventsv2/',
- body: {data: [{'event.type': 'error'}], meta: {'event.type': 'string'}},
- });
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/events-geo/',
- body: {data: [], meta: {}},
- });
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/recent-searches/',
- body: [],
- });
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/dashboards/',
- body: [{id: '1', title: t('Test Dashboard')}],
- });
- });
- afterEach(() => {
- MockApiClient.clearMockResponses();
- });
- it('renders a single query selection when the widget only has one query', async function () {
- const wrapper = mountModal({initialData, widget: mockWidget});
- await tick();
- expect(wrapper.find('StyledInput').length).toEqual(1);
- expect(wrapper.find('StyledInput').props().value).toEqual(
- 'title:/organizations/:orgId/performance/summary/'
- );
- expect(wrapper.find('OpenInDiscoverButton').length).toEqual(1);
- wrapper.unmount();
- });
- it('renders a multiple query selections when the widget only has multiple queries', async function () {
- mockWidget.queries.push({
- ...mockQuery,
- conditions: 'title:/organizations/:orgId/performance/',
- id: '2',
- });
- mockWidget.queries.push({
- ...mockQuery,
- conditions: 'title:/organizations/:orgId/',
- id: '3',
- });
- const wrapper = mountModal({initialData, widget: mockWidget});
- await tick();
- expect(wrapper.find('StyledInput').length).toEqual(3);
- expect(wrapper.find('StyledInput').at(0).props().value).toEqual(
- 'title:/organizations/:orgId/performance/summary/'
- );
- expect(wrapper.find('StyledInput').at(1).props().value).toEqual(
- 'title:/organizations/:orgId/performance/'
- );
- expect(wrapper.find('StyledInput').at(2).props().value).toEqual(
- 'title:/organizations/:orgId/'
- );
- expect(wrapper.find('OpenInDiscoverButton').length).toEqual(3);
- wrapper.unmount();
- });
- it('links user to the query in discover when a query is selected from the modal', async function () {
- const wrapper = mountModal({initialData, widget: mockWidget});
- await tick();
- expect(wrapper.find('QueryContainer').find('Link').props().to).toEqual(
- '/organizations/org-slug/discover/results/?field=count%28%29&field=failure_count%28%29&name=Test%20Widget&query=title%3A%2Forganizations%2F%3AorgId%2Fperformance%2Fsummary%2F&statsPeriod=14d&yAxis=count%28%29&yAxis=failure_count%28%29'
- );
- wrapper.unmount();
- });
- it('links user to the query in discover with additional field when a world map query is selected from the modal', async function () {
- mockWidget.queries[0].fields = ['count()'];
- mockWidget.queries[0].aggregates = ['count()'];
- mockWidget.displayType = DisplayType.WORLD_MAP;
- const wrapper = mountModal({initialData, widget: mockWidget});
- await tick();
- expect(wrapper.find('QueryContainer').find('Link').props().to).toEqual(
- '/organizations/org-slug/discover/results/?display=worldmap&field=geo.country_code&field=count%28%29&name=Test%20Widget&query=title%3A%2Forganizations%2F%3AorgId%2Fperformance%2Fsummary%2F%20has%3Ageo.country_code&statsPeriod=14d&yAxis=count%28%29'
- );
- wrapper.unmount();
- });
- });
|