123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882 |
- import {browserHistory} from 'react-router';
- import {createListeners} from 'sentry-test/createListeners';
- import {selectDropdownMenuItem} from 'sentry-test/dropdownMenu';
- import {enforceActOnUseLegacyStoreHook, mountWithTheme} from 'sentry-test/enzyme';
- import {initializeOrg} from 'sentry-test/initializeOrg';
- import {mountGlobalModal} from 'sentry-test/modal';
- import {act} from 'sentry-test/reactTestingLibrary';
- import {triggerPress} from 'sentry-test/utils';
- import * as modals from 'sentry/actionCreators/modal';
- import ProjectsStore from 'sentry/stores/projectsStore';
- import {DashboardState} from 'sentry/views/dashboardsV2/types';
- import * as types from 'sentry/views/dashboardsV2/types';
- import ViewEditDashboard from 'sentry/views/dashboardsV2/view';
- import {OrganizationContext} from 'sentry/views/organizationContext';
- describe('Dashboards > Detail', function () {
- enforceActOnUseLegacyStoreHook();
- const organization = TestStubs.Organization({
- features: ['global-views', 'dashboards-basic', 'dashboards-edit', 'discover-query'],
- });
- const projects = [TestStubs.Project()];
- describe('prebuilt dashboards', function () {
- let wrapper;
- let initialData, mockVisit;
- beforeEach(function () {
- act(() => ProjectsStore.loadInitialData(projects));
- initialData = initializeOrg({organization});
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/tags/',
- body: [],
- });
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/projects/',
- body: [TestStubs.Project()],
- });
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/dashboards/',
- body: [
- TestStubs.Dashboard([], {id: 'default-overview', title: 'Default'}),
- TestStubs.Dashboard([], {id: '1', title: 'Custom Errors'}),
- ],
- });
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/dashboards/default-overview/',
- body: TestStubs.Dashboard([], {id: 'default-overview', title: 'Default'}),
- });
- mockVisit = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/dashboards/1/visit/',
- method: 'POST',
- body: [],
- statusCode: 200,
- });
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/users/',
- method: 'GET',
- body: [],
- });
- });
- afterEach(function () {
- MockApiClient.clearMockResponses();
- if (wrapper) {
- wrapper.unmount();
- }
- });
- it('can delete', async function () {
- const deleteMock = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/dashboards/default-overview/',
- method: 'DELETE',
- });
- wrapper = mountWithTheme(
- <OrganizationContext.Provider value={initialData.organization}>
- <ViewEditDashboard
- organization={initialData.organization}
- params={{orgId: 'org-slug', dashboardId: 'default-overview'}}
- router={initialData.router}
- location={initialData.router.location}
- />
- </OrganizationContext.Provider>,
- initialData.routerContext
- );
- await tick();
- wrapper.update();
- // Enter edit mode.
- wrapper.find('Controls Button[data-test-id="dashboard-edit"]').simulate('click');
- const modal = await mountGlobalModal();
- // Click delete, confirm will show
- wrapper.find('Controls Button[data-test-id="dashboard-delete"]').simulate('click');
- await tick();
- await modal.update();
- // Click confirm
- modal.find('button[aria-label="Confirm"]').simulate('click');
- expect(deleteMock).toHaveBeenCalled();
- });
- it('can rename and save', async function () {
- const fireEvent = createListeners('window');
- const updateMock = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/dashboards/default-overview/',
- method: 'PUT',
- body: TestStubs.Dashboard([], {id: '8', title: 'Updated prebuilt'}),
- });
- wrapper = mountWithTheme(
- <OrganizationContext.Provider value={initialData.organization}>
- <ViewEditDashboard
- organization={initialData.organization}
- params={{orgId: 'org-slug', dashboardId: 'default-overview'}}
- router={initialData.router}
- location={initialData.router.location}
- />
- </OrganizationContext.Provider>,
- initialData.routerContext
- );
- await tick();
- wrapper.update();
- // Enter edit mode.
- wrapper.find('Controls Button[data-test-id="dashboard-edit"]').simulate('click');
- await tick();
- wrapper.update();
- // Rename
- const dashboardTitle = wrapper.find('DashboardTitle Label');
- dashboardTitle.simulate('click');
- wrapper.find('StyledInput').simulate('change', {
- target: {innerText: 'Updated prebuilt', value: 'Updated prebuilt'},
- });
- act(() => {
- // Press enter
- fireEvent.keyDown('Enter');
- });
- wrapper.find('Controls Button[data-test-id="dashboard-commit"]').simulate('click');
- await tick();
- wrapper.update();
- expect(updateMock).toHaveBeenCalledWith(
- '/organizations/org-slug/dashboards/default-overview/',
- expect.objectContaining({
- data: expect.objectContaining({title: 'Updated prebuilt'}),
- })
- );
- // Should redirect to the new dashboard.
- expect(browserHistory.replace).toHaveBeenCalledWith(
- expect.objectContaining({
- pathname: '/organizations/org-slug/dashboard/8/',
- })
- );
- });
- it('disables buttons based on features', async function () {
- initialData = initializeOrg({
- organization: TestStubs.Organization({
- features: ['global-views', 'dashboards-basic', 'discover-query'],
- projects: [TestStubs.Project()],
- }),
- });
- wrapper = mountWithTheme(
- <OrganizationContext.Provider value={initialData.organization}>
- <ViewEditDashboard
- organization={initialData.organization}
- params={{orgId: 'org-slug', dashboardId: 'default-overview'}}
- router={initialData.router}
- location={initialData.router.location}
- />
- </OrganizationContext.Provider>,
- initialData.routerContext
- );
- await tick();
- wrapper.update();
- // Edit should be disabled
- const editProps = wrapper
- .find('Controls Button[data-test-id="dashboard-edit"]')
- .props();
- expect(editProps.disabled).toBe(true);
- expect(mockVisit).not.toHaveBeenCalled();
- });
- });
- describe('custom dashboards', function () {
- let wrapper, initialData, widgets, mockVisit;
- const openEditModal = jest.spyOn(modals, 'openAddDashboardWidgetModal');
- beforeEach(function () {
- initialData = initializeOrg({organization});
- types.MAX_WIDGETS = 30;
- widgets = [
- TestStubs.Widget(
- [
- {
- name: '',
- conditions: 'event.type:error',
- fields: ['count()'],
- aggregates: ['count()'],
- columns: [],
- },
- ],
- {
- title: 'Errors',
- interval: '1d',
- id: '1',
- }
- ),
- TestStubs.Widget(
- [
- {
- name: '',
- conditions: 'event.type:transaction',
- fields: ['count()'],
- aggregates: ['count()'],
- columns: [],
- },
- ],
- {
- title: 'Transactions',
- interval: '1d',
- id: '2',
- }
- ),
- TestStubs.Widget(
- [
- {
- name: '',
- conditions: 'event.type:transaction transaction:/api/cats',
- fields: ['p50()'],
- aggregates: ['p50()'],
- columns: [],
- },
- ],
- {
- title: 'p50 of /api/cats',
- interval: '1d',
- id: '3',
- }
- ),
- ];
- mockVisit = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/dashboards/1/visit/',
- method: 'POST',
- body: [],
- statusCode: 200,
- });
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/tags/',
- body: [],
- });
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/projects/',
- body: [TestStubs.Project()],
- });
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/dashboards/',
- body: [
- TestStubs.Dashboard([], {
- id: 'default-overview',
- title: 'Default',
- widgetDisplay: ['area'],
- }),
- TestStubs.Dashboard([], {
- id: '1',
- title: 'Custom Errors',
- widgetDisplay: ['area'],
- }),
- ],
- });
- MockApiClient.addMockResponse({
- method: 'GET',
- url: '/organizations/org-slug/dashboards/1/',
- body: TestStubs.Dashboard(widgets, {id: '1', title: 'Custom Errors'}),
- });
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/dashboards/1/',
- method: 'PUT',
- body: TestStubs.Dashboard(widgets, {id: '1', title: 'Custom Errors'}),
- });
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/events-stats/',
- body: {data: []},
- });
- MockApiClient.addMockResponse({
- method: 'POST',
- url: '/organizations/org-slug/dashboards/widgets/',
- body: [],
- });
- MockApiClient.addMockResponse({
- method: 'GET',
- url: '/organizations/org-slug/recent-searches/',
- body: [],
- });
- MockApiClient.addMockResponse({
- method: 'GET',
- url: '/organizations/org-slug/issues/',
- body: [],
- });
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/eventsv2/',
- method: 'GET',
- body: [],
- });
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/users/',
- method: 'GET',
- body: [],
- });
- });
- afterEach(function () {
- MockApiClient.clearMockResponses();
- jest.clearAllMocks();
- if (wrapper) {
- wrapper.unmount();
- }
- });
- it('can remove widgets', async function () {
- const updateMock = MockApiClient.addMockResponse({
- url: '/organizations/org-slug/dashboards/1/',
- method: 'PUT',
- body: TestStubs.Dashboard([widgets[0]], {id: '1', title: 'Custom Errors'}),
- });
- wrapper = mountWithTheme(
- <OrganizationContext.Provider value={initialData.organization}>
- <ViewEditDashboard
- organization={initialData.organization}
- params={{orgId: 'org-slug', dashboardId: '1'}}
- router={initialData.router}
- location={initialData.router.location}
- />
- </OrganizationContext.Provider>,
- initialData.routerContext
- );
- await tick();
- wrapper.update();
- expect(mockVisit).toHaveBeenCalledTimes(1);
- // Enter edit mode.
- wrapper.find('Controls Button[data-test-id="dashboard-edit"]').simulate('click');
- const card = wrapper.find('WidgetCard').first();
- card.find('WidgetCardPanel').simulate('mouseOver');
- // Remove the second and third widgets
- wrapper
- .find('WidgetCard')
- .at(1)
- .find('Button[data-test-id="widget-delete"]')
- .simulate('click');
- wrapper
- .find('WidgetCard')
- .at(1)
- .find('Button[data-test-id="widget-delete"]')
- .simulate('click');
- // Save changes
- wrapper.find('Controls Button[data-test-id="dashboard-commit"]').simulate('click');
- await tick();
- expect(updateMock).toHaveBeenCalled();
- expect(updateMock).toHaveBeenCalledWith(
- '/organizations/org-slug/dashboards/1/',
- expect.objectContaining({
- data: expect.objectContaining({
- title: 'Custom Errors',
- widgets: [widgets[0]],
- }),
- })
- );
- // Visit should not be called again on dashboard update
- expect(mockVisit).toHaveBeenCalledTimes(1);
- });
- it('opens edit modal for widgets', async function () {
- wrapper = mountWithTheme(
- <OrganizationContext.Provider value={initialData.organization}>
- <ViewEditDashboard
- organization={initialData.organization}
- params={{orgId: 'org-slug', dashboardId: '1'}}
- router={initialData.router}
- location={initialData.router.location}
- />
- </OrganizationContext.Provider>,
- initialData.routerContext
- );
- await tick();
- wrapper.update();
- // Enter edit mode.
- wrapper.find('Controls Button[data-test-id="dashboard-edit"]').simulate('click');
- wrapper.update();
- const card = wrapper.find('WidgetCard').first();
- card.find('WidgetCardPanel').simulate('mouseOver');
- // Edit the first widget
- wrapper
- .find('WidgetCard')
- .first()
- .find('Button[data-test-id="widget-edit"]')
- .simulate('click');
- expect(openEditModal).toHaveBeenCalledTimes(1);
- expect(openEditModal).toHaveBeenCalledWith(
- expect.objectContaining({
- widget: {
- id: '1',
- interval: '1d',
- queries: [
- {
- conditions: 'event.type:error',
- fields: ['count()'],
- aggregates: ['count()'],
- columns: [],
- name: '',
- },
- ],
- title: 'Errors',
- type: 'line',
- },
- })
- );
- });
- it('does not update if api update fails', async function () {
- const fireEvent = createListeners('window');
- window.confirm = jest.fn(() => true);
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/dashboards/1/',
- method: 'PUT',
- statusCode: 400,
- });
- wrapper = mountWithTheme(
- <OrganizationContext.Provider value={initialData.organization}>
- <ViewEditDashboard
- organization={initialData.organization}
- params={{orgId: 'org-slug', dashboardId: '1'}}
- router={initialData.router}
- location={initialData.router.location}
- />
- </OrganizationContext.Provider>,
- initialData.routerContext
- );
- await tick();
- wrapper.update();
- // Enter edit mode.
- wrapper.find('Controls Button[data-test-id="dashboard-edit"]').simulate('click');
- // Rename
- const dashboardTitle = wrapper.find('DashboardTitle Label');
- dashboardTitle.simulate('click');
- wrapper.find('StyledInput').simulate('change', {
- target: {innerText: 'Updated Name', value: 'Updated Name'},
- });
- act(() => {
- // Press enter
- fireEvent.keyDown('Enter');
- });
- wrapper.find('Controls Button[data-test-id="dashboard-commit"]').simulate('click');
- await tick();
- wrapper.update();
- expect(wrapper.find('DashboardTitle EditableText').props().value).toEqual(
- 'Updated Name'
- );
- wrapper.find('Controls Button[data-test-id="dashboard-cancel"]').simulate('click');
- expect(wrapper.find('DashboardTitle EditableText').props().value).toEqual(
- 'Custom Errors'
- );
- });
- it('shows add widget option', async function () {
- wrapper = mountWithTheme(
- <OrganizationContext.Provider value={initialData.organization}>
- <ViewEditDashboard
- organization={initialData.organization}
- params={{orgId: 'org-slug', dashboardId: '1'}}
- router={initialData.router}
- location={initialData.router.location}
- />
- </OrganizationContext.Provider>,
- initialData.routerContext
- );
- await tick();
- wrapper.update();
- // Enter edit mode.
- wrapper.find('Controls Button[data-test-id="dashboard-edit"]').simulate('click');
- wrapper.update();
- expect(wrapper.find('AddWidget').exists()).toBe(true);
- });
- it('opens custom modal when add widget option is clicked', async function () {
- wrapper = mountWithTheme(
- <OrganizationContext.Provider value={initialData.organization}>
- <ViewEditDashboard
- organization={initialData.organization}
- params={{orgId: 'org-slug', dashboardId: '1'}}
- router={initialData.router}
- location={initialData.router.location}
- />
- </OrganizationContext.Provider>,
- initialData.routerContext
- );
- await tick();
- wrapper.update();
- // Enter edit mode.
- wrapper.find('Controls Button[data-test-id="dashboard-edit"]').simulate('click');
- wrapper.update();
- wrapper.find('AddButton[data-test-id="widget-add"]').simulate('click');
- expect(openEditModal).toHaveBeenCalledTimes(1);
- });
- it('opens widget library when add widget option is clicked', async function () {
- initialData = initializeOrg({
- organization: TestStubs.Organization({
- features: [
- 'global-views',
- 'dashboards-basic',
- 'dashboards-edit',
- 'discover-query',
- ],
- projects: [TestStubs.Project()],
- }),
- });
- wrapper = mountWithTheme(
- <OrganizationContext.Provider value={initialData.organization}>
- <ViewEditDashboard
- organization={initialData.organization}
- params={{orgId: 'org-slug', dashboardId: '1'}}
- router={initialData.router}
- location={initialData.router.location}
- />
- </OrganizationContext.Provider>,
- initialData.routerContext
- );
- await tick();
- wrapper.update();
- // Enter edit mode.
- wrapper.find('Controls Button[data-test-id="dashboard-edit"]').simulate('click');
- wrapper.update();
- wrapper.find('AddButton[data-test-id="widget-add"]').simulate('click');
- expect(openEditModal).toHaveBeenCalledTimes(1);
- expect(openEditModal).toHaveBeenCalledWith(
- expect.objectContaining({
- source: types.DashboardWidgetSource.LIBRARY,
- })
- );
- });
- it('hides add widget option', async function () {
- types.MAX_WIDGETS = 1;
- wrapper = mountWithTheme(
- <OrganizationContext.Provider value={initialData.organization}>
- <ViewEditDashboard
- organization={initialData.organization}
- params={{orgId: 'org-slug', dashboardId: '1'}}
- router={initialData.router}
- location={initialData.router.location}
- />
- </OrganizationContext.Provider>,
- initialData.routerContext
- );
- await tick();
- wrapper.update();
- // Enter edit mode.
- wrapper.find('Controls Button[data-test-id="dashboard-edit"]').simulate('click');
- wrapper.update();
- expect(wrapper.find('AddWidget').exists()).toBe(false);
- });
- it('hides and shows breadcrumbs based on feature', async function () {
- const newOrg = initializeOrg({
- organization: TestStubs.Organization({
- features: ['global-views', 'dashboards-basic', 'discover-query'],
- projects: [TestStubs.Project()],
- }),
- });
- wrapper = mountWithTheme(
- <OrganizationContext.Provider value={initialData.organization}>
- <ViewEditDashboard
- organization={newOrg.organization}
- params={{orgId: 'org-slug', dashboardId: '1'}}
- router={newOrg.router}
- location={newOrg.router.location}
- />
- </OrganizationContext.Provider>,
- newOrg.routerContext
- );
- await tick();
- wrapper.update();
- expect(wrapper.find('Breadcrumbs').exists()).toBe(false);
- wrapper = mountWithTheme(
- <OrganizationContext.Provider value={initialData.organization}>
- <ViewEditDashboard
- organization={initialData.organization}
- params={{orgId: 'org-slug', dashboardId: '1'}}
- router={initialData.router}
- location={initialData.router.location}
- />
- </OrganizationContext.Provider>,
- initialData.routerContext
- );
- await tick();
- wrapper.update();
- const breadcrumbs = wrapper.find('Breadcrumbs');
- expect(breadcrumbs.exists()).toBe(true);
- expect(breadcrumbs.find('BreadcrumbLink').find('a').text()).toEqual('Dashboards');
- expect(breadcrumbs.find('BreadcrumbItem').last().text()).toEqual('Custom Errors');
- });
- it('unsets newWidget after rendering', async function () {
- initialData.router.location = {
- query: {
- displayType: 'line',
- interval: '5m',
- queryConditions: ['title:test', 'event.type:test'],
- queryFields: ['count()', 'failure_count()'],
- queryNames: ['1', '2'],
- queryOrderby: '',
- title: 'Widget Title',
- },
- };
- wrapper = mountWithTheme(
- <OrganizationContext.Provider value={initialData.organization}>
- <ViewEditDashboard
- organization={initialData.organization}
- params={{orgId: 'org-slug', dashboardId: '1'}}
- router={initialData.router}
- location={{...initialData.router.location, pathname: '/mockpath'}}
- />
- </OrganizationContext.Provider>,
- initialData.routerContext
- );
- expect(wrapper.find('DashboardDetail').props().initialState).toEqual(
- DashboardState.EDIT
- );
- expect(wrapper.find('DashboardDetail').props().newWidget).toBeDefined();
- await act(async () => {
- // Wrap await tick in act because componentDidMount in Dashboard triggers
- // state change when parsing widget from location
- await tick();
- });
- wrapper.update();
- // The newWidget state was cleared after adding the widget
- expect(wrapper.find('DashboardDetail').props().newWidget).toBeUndefined();
- await act(async () => {
- await tick();
- });
- });
- it('enters edit mode when given a new widget in location query', async function () {
- initialData.router.location = {
- query: {
- displayType: 'line',
- interval: '5m',
- queryConditions: ['title:test', 'event.type:test'],
- queryFields: ['count()', 'failure_count()'],
- queryNames: ['1', '2'],
- queryOrderby: '',
- title: 'Widget Title',
- },
- };
- wrapper = mountWithTheme(
- <OrganizationContext.Provider value={initialData.organization}>
- <ViewEditDashboard
- organization={initialData.organization}
- params={{orgId: 'org-slug', dashboardId: '1'}}
- router={initialData.router}
- location={{...initialData.router.location, pathname: '/mockpath'}}
- />
- </OrganizationContext.Provider>,
- initialData.routerContext
- );
- expect(wrapper.find('DashboardDetail').props().initialState).toEqual(
- DashboardState.EDIT
- );
- await act(async () => {
- // Wrap await tick in act because componentDidMount in Dashboard triggers
- // state change when parsing widget from location
- await tick();
- });
- });
- it('enters view mode when not given a new widget in location query', async function () {
- wrapper = mountWithTheme(
- <OrganizationContext.Provider value={initialData.organization}>
- <ViewEditDashboard
- organization={initialData.organization}
- params={{orgId: 'org-slug', dashboardId: '1'}}
- router={initialData.router}
- location={initialData.router.location}
- />
- </OrganizationContext.Provider>,
- initialData.routerContext
- );
- await tick();
- wrapper.update();
- expect(wrapper.find('DashboardDetail').props().initialState).toEqual(
- DashboardState.VIEW
- );
- });
- it('opens add widget to custom modal', async function () {
- types.MAX_WIDGETS = 10;
- initialData = initializeOrg({
- organization: TestStubs.Organization({
- features: [
- 'global-views',
- 'dashboards-basic',
- 'dashboards-edit',
- 'discover-query',
- ],
- projects: [TestStubs.Project()],
- }),
- });
- wrapper = mountWithTheme(
- <OrganizationContext.Provider value={initialData.organization}>
- <ViewEditDashboard
- organization={initialData.organization}
- params={{orgId: 'org-slug', dashboardId: '1'}}
- router={initialData.router}
- location={initialData.router.location}
- />
- </OrganizationContext.Provider>,
- initialData.routerContext
- );
- await tick();
- wrapper.update();
- expect(wrapper.find('Controls Tooltip').prop('disabled')).toBe(true);
- // Enter Add Widget mode
- wrapper
- .find('Controls Button[data-test-id="add-widget-library"]')
- .simulate('click');
- expect(openEditModal).toHaveBeenCalledTimes(1);
- expect(openEditModal).toHaveBeenCalledWith(
- expect.objectContaining({
- source: types.DashboardWidgetSource.LIBRARY,
- })
- );
- });
- it('disables add library widgets when max widgets reached', async function () {
- types.MAX_WIDGETS = 3;
- initialData = initializeOrg({
- organization: TestStubs.Organization({
- features: [
- 'global-views',
- 'dashboards-basic',
- 'dashboards-edit',
- 'discover-query',
- ],
- projects: [TestStubs.Project()],
- }),
- });
- wrapper = mountWithTheme(
- <OrganizationContext.Provider value={initialData.organization}>
- <ViewEditDashboard
- organization={initialData.organization}
- params={{orgId: 'org-slug', dashboardId: '1'}}
- router={initialData.router}
- location={initialData.router.location}
- />
- </OrganizationContext.Provider>,
- initialData.routerContext
- );
- await tick();
- wrapper.update();
- expect(wrapper.find('WidgetCard')).toHaveLength(3);
- expect(
- wrapper.find('Controls Button[data-test-id="add-widget-library"]').props()
- .disabled
- ).toEqual(true);
- expect(wrapper.find('Controls Tooltip').prop('disabled')).toBe(false);
- await act(async () => {
- triggerPress(wrapper.first().find('MenuControlWrap Button').first());
- await tick();
- wrapper.update();
- });
- expect(
- wrapper.find(`MenuItemWrap[data-test-id="duplicate-widget"]`).props()[
- 'aria-disabled'
- ]
- ).toEqual(true);
- });
- it('opens edit modal when editing widget from context menu', async function () {
- wrapper = mountWithTheme(
- <OrganizationContext.Provider value={initialData.organization}>
- <ViewEditDashboard
- organization={initialData.organization}
- params={{orgId: 'org-slug', dashboardId: '1'}}
- router={initialData.router}
- location={initialData.router.location}
- />
- </OrganizationContext.Provider>,
- initialData.routerContext
- );
- await tick();
- wrapper.update();
- expect(wrapper.find('WidgetCard')).toHaveLength(3);
- await selectDropdownMenuItem({
- wrapper,
- specifiers: {prefix: 'WidgetCard', first: true},
- itemKey: 'edit-widget',
- });
- expect(openEditModal).toHaveBeenCalledTimes(1);
- expect(openEditModal).toHaveBeenCalledWith(
- expect.objectContaining({
- widget: {
- id: '1',
- interval: '1d',
- queries: [
- {
- conditions: 'event.type:error',
- fields: ['count()'],
- aggregates: ['count()'],
- columns: [],
- name: '',
- },
- ],
- title: 'Errors',
- type: 'line',
- },
- })
- );
- });
- });
- });
|