|
|
|
@ -8,7 +8,14 @@ import { MockDataSourceApi } from 'test/mocks/datasource_srv'; |
|
|
|
|
import { getGrafanaContextMock } from 'test/mocks/getGrafanaContextMock'; |
|
|
|
|
|
|
|
|
|
import { DataSourcePluginMeta } from '@grafana/data'; |
|
|
|
|
import { BackendSrv, FetchError, FetchResponse, setDataSourceSrv, BackendSrvRequest } from '@grafana/runtime'; |
|
|
|
|
import { |
|
|
|
|
BackendSrv, |
|
|
|
|
FetchError, |
|
|
|
|
FetchResponse, |
|
|
|
|
setDataSourceSrv, |
|
|
|
|
BackendSrvRequest, |
|
|
|
|
reportInteraction, |
|
|
|
|
} from '@grafana/runtime'; |
|
|
|
|
import { GrafanaContext } from 'app/core/context/GrafanaContext'; |
|
|
|
|
import { contextSrv } from 'app/core/services/context_srv'; |
|
|
|
|
import { configureStore } from 'app/store/configureStore'; |
|
|
|
@ -47,12 +54,6 @@ function createFetchError(overrides?: DeepPartial<FetchError>): FetchError { |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
jest.mock('app/core/services/context_srv'); |
|
|
|
|
|
|
|
|
|
const mocks = { |
|
|
|
|
contextSrv: jest.mocked(contextSrv), |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const renderWithContext = async ( |
|
|
|
|
datasources: ConstructorParameters<typeof MockDataSourceSrv>[0] = {}, |
|
|
|
|
correlations: Correlation[] = [] |
|
|
|
@ -217,6 +218,20 @@ const renderWithContext = async ( |
|
|
|
|
return renderResult; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
jest.mock('app/core/services/context_srv'); |
|
|
|
|
|
|
|
|
|
const mocks = { |
|
|
|
|
contextSrv: jest.mocked(contextSrv), |
|
|
|
|
reportInteraction: jest.fn(), |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
jest.mock('@grafana/runtime', () => ({ |
|
|
|
|
...jest.requireActual('@grafana/runtime'), |
|
|
|
|
reportInteraction: (...args: Parameters<typeof reportInteraction>) => { |
|
|
|
|
mocks.reportInteraction(...args); |
|
|
|
|
}, |
|
|
|
|
})); |
|
|
|
|
|
|
|
|
|
beforeAll(() => { |
|
|
|
|
mocks.contextSrv.hasPermission.mockImplementation(() => true); |
|
|
|
|
}); |
|
|
|
@ -254,6 +269,10 @@ describe('CorrelationsPage', () => { |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
afterEach(() => { |
|
|
|
|
mocks.reportInteraction.mockClear(); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('shows CTA', async () => { |
|
|
|
|
// insert form should not be present
|
|
|
|
|
expect(screen.queryByRole('button', { name: /add$/i })).not.toBeInTheDocument(); |
|
|
|
@ -305,12 +324,18 @@ describe('CorrelationsPage', () => { |
|
|
|
|
// Waits for the form to be removed, meaning the correlation got successfully saved
|
|
|
|
|
await waitForElementToBeRemoved(() => screen.queryByRole('button', { name: /add$/i })); |
|
|
|
|
|
|
|
|
|
expect(mocks.reportInteraction).toHaveBeenLastCalledWith('grafana_correlations_added'); |
|
|
|
|
|
|
|
|
|
// the table showing correlations should have appeared
|
|
|
|
|
expect(screen.getByRole('table')).toBeInTheDocument(); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
describe('With correlations', () => { |
|
|
|
|
afterEach(() => { |
|
|
|
|
mocks.reportInteraction.mockClear(); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
let queryRowsByCellValue: (columnName: Matcher, textValue: Matcher) => HTMLTableRowElement[]; |
|
|
|
|
let getHeaderByName: (columnName: Matcher) => HTMLTableCellElement; |
|
|
|
|
let queryCellsByColumnName: (columnName: Matcher) => HTMLTableCellElement[]; |
|
|
|
@ -430,6 +455,8 @@ describe('CorrelationsPage', () => { |
|
|
|
|
|
|
|
|
|
// the form should get removed after successful submissions
|
|
|
|
|
await waitForElementToBeRemoved(() => screen.queryByRole('button', { name: /add$/i })); |
|
|
|
|
|
|
|
|
|
expect(mocks.reportInteraction).toHaveBeenLastCalledWith('grafana_correlations_added'); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('correctly closes the form when clicking on the close icon', async () => { |
|
|
|
@ -460,6 +487,8 @@ describe('CorrelationsPage', () => { |
|
|
|
|
fireEvent.click(confirmButton); |
|
|
|
|
|
|
|
|
|
await waitForElementToBeRemoved(() => screen.queryByRole('cell', { name: /some label$/i })); |
|
|
|
|
|
|
|
|
|
expect(mocks.reportInteraction).toHaveBeenLastCalledWith('grafana_correlations_deleted'); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('correctly edits correlations', async () => { |
|
|
|
@ -468,6 +497,8 @@ describe('CorrelationsPage', () => { |
|
|
|
|
const rowExpanderButton = within(tableRows[0]).getByRole('button', { name: /toggle row expanded/i }); |
|
|
|
|
fireEvent.click(rowExpanderButton); |
|
|
|
|
|
|
|
|
|
expect(mocks.reportInteraction).toHaveBeenLastCalledWith('grafana_correlations_details_expanded'); |
|
|
|
|
|
|
|
|
|
await waitForElementToBeRemoved(() => screen.queryByText(/loading query editor/i)); |
|
|
|
|
|
|
|
|
|
fireEvent.change(screen.getByRole('textbox', { name: /label/i }), { target: { value: 'edited label' } }); |
|
|
|
@ -482,6 +513,8 @@ describe('CorrelationsPage', () => { |
|
|
|
|
await waitFor(() => { |
|
|
|
|
expect(screen.queryByRole('cell', { name: /edited label$/i })).toBeInTheDocument(); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
expect(mocks.reportInteraction).toHaveBeenLastCalledWith('grafana_correlations_edited'); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
@ -526,6 +559,8 @@ describe('CorrelationsPage', () => { |
|
|
|
|
|
|
|
|
|
fireEvent.click(rowExpanderButton); |
|
|
|
|
|
|
|
|
|
expect(mocks.reportInteraction).toHaveBeenLastCalledWith('grafana_correlations_details_expanded'); |
|
|
|
|
|
|
|
|
|
// wait for the form to be rendered and query editor to be mounted
|
|
|
|
|
await waitForElementToBeRemoved(() => screen.queryByText(/loading query editor/i)); |
|
|
|
|
|
|
|
|
|