mirror of
https://github.com/grafana/grafana.git
synced 2024-12-25 08:21:46 -06:00
Dependencies: Jest 27 (#42681)
* Update jest monorepo * Update version of marked so it doesn't throw an error, set testEnvironment * Fix some unit tests * Remove all these tests that aren't actually working... * use spyOn instead of mocking the whole module * Fix linting Co-authored-by: Renovate Bot <bot@renovateapp.com>
This commit is contained in:
parent
cf9aef9168
commit
cc9151d382
@ -5,6 +5,7 @@ process.env.TZ = 'Pacific/Easter';
|
||||
|
||||
module.exports = {
|
||||
verbose: false,
|
||||
testEnvironment: 'jsdom',
|
||||
transform: {
|
||||
'^.+\\.(ts|tsx|js|jsx)$': require.resolve('ts-jest'),
|
||||
},
|
||||
|
@ -146,7 +146,7 @@
|
||||
"angular-mocks": "1.6.6",
|
||||
"autoprefixer": "10.2.6",
|
||||
"axios": "0.21.2",
|
||||
"babel-jest": "26.6.3",
|
||||
"babel-jest": "27.4.2",
|
||||
"babel-loader": "8.2.2",
|
||||
"babel-plugin-angularjs-annotate": "0.10.0",
|
||||
"copy-webpack-plugin": "9.0.1",
|
||||
@ -180,17 +180,18 @@
|
||||
"http-server": "14.0.0",
|
||||
"husky": "^7.0.0",
|
||||
"iconscout-unicons-tarball": "https://github.com/grafana/icons/tarball/63056cd833ba7ee4e94904492b3a8c0cabc38d28",
|
||||
"jest": "26.6.3",
|
||||
"jest": "27.4.2",
|
||||
"jest-canvas-mock": "2.3.0",
|
||||
"jest-date-mock": "1.0.8",
|
||||
"jest-junit": "13.0.0",
|
||||
"jest-matcher-utils": "26.0.0",
|
||||
"jest-matcher-utils": "27.4.2",
|
||||
"lerna": "^4.0.0",
|
||||
"lint-staged": "12.0.2",
|
||||
"mini-css-extract-plugin": "2.4.4",
|
||||
"module-alias": "2.2.2",
|
||||
"mutationobserver-shim": "0.3.3",
|
||||
"ngtemplate-loader": "2.1.0",
|
||||
"node-notifier": "^10.0.0",
|
||||
"nodemon": "2.0.2",
|
||||
"postcss": "8.3.6",
|
||||
"postcss-loader": "6.2.0",
|
||||
@ -214,7 +215,7 @@
|
||||
"stylelint-config-sass-guidelines": "9.0.1",
|
||||
"terser-webpack-plugin": "5.2.5",
|
||||
"testing-library-selector": "^0.1.3",
|
||||
"ts-jest": "26.4.4",
|
||||
"ts-jest": "27.0.7",
|
||||
"ts-loader": "9.2.6",
|
||||
"ts-node": "10.4.0",
|
||||
"tslib": "2.3.1",
|
||||
|
@ -28,7 +28,7 @@
|
||||
"date-fns": "2.21.3",
|
||||
"eventemitter3": "4.0.7",
|
||||
"lodash": "4.17.21",
|
||||
"marked": "4.0.0",
|
||||
"marked": "4.0.5",
|
||||
"moment": "2.29.1",
|
||||
"moment-timezone": "0.5.33",
|
||||
"ol": "6.7.0",
|
||||
@ -61,7 +61,7 @@
|
||||
"@types/testing-library__jest-dom": "5.9.5",
|
||||
"@types/testing-library__react-hooks": "^3.2.0",
|
||||
"@types/tinycolor2": "1.4.2",
|
||||
"pretty-format": "25.1.0",
|
||||
"pretty-format": "27.4.2",
|
||||
"react": "17.0.1",
|
||||
"react-dom": "17.0.1",
|
||||
"react-test-renderer": "17.0.1",
|
||||
|
@ -417,7 +417,7 @@ describe('Reducer Transformer', () => {
|
||||
"CA",
|
||||
"NY",
|
||||
"CA",
|
||||
undefined,
|
||||
,
|
||||
],
|
||||
},
|
||||
Object {
|
||||
@ -425,8 +425,8 @@ describe('Reducer Transformer', () => {
|
||||
"name": "country",
|
||||
"type": "string",
|
||||
"values": Array [
|
||||
undefined,
|
||||
undefined,
|
||||
,
|
||||
,
|
||||
"USA",
|
||||
"USA",
|
||||
],
|
||||
|
@ -79,31 +79,31 @@ describe('date time formats', () => {
|
||||
it('should format as local date', () => {
|
||||
const dateTimeObject = browserTime.toDate();
|
||||
const formattedDateText = getDateTimeAsLocalFormat()(epoch, 0, 0).text;
|
||||
expect(formattedDateText).toContain(dateTimeObject.getFullYear());
|
||||
expect(formattedDateText).toContain(dateTimeObject.getSeconds());
|
||||
expect(formattedDateText).toContain(dateTimeObject.getFullYear().toString());
|
||||
expect(formattedDateText).toContain(dateTimeObject.getSeconds().toString());
|
||||
});
|
||||
|
||||
it('should format as local date and skip date when today', () => {
|
||||
const now = dateTime();
|
||||
const dateTimeObject = now.toDate();
|
||||
const formattedDateText = getDateTimeAsLocalFormatNoDateIfToday()(now.valueOf(), 0, 0).text;
|
||||
expect(formattedDateText).not.toContain(dateTimeObject.getFullYear());
|
||||
expect(formattedDateText).toContain(dateTimeObject.getSeconds());
|
||||
expect(formattedDateText).not.toContain(dateTimeObject.getFullYear().toString());
|
||||
expect(formattedDateText).toContain(dateTimeObject.getSeconds().toString());
|
||||
});
|
||||
|
||||
it('should format as local date (in UTC)', () => {
|
||||
const dateTimeObject = utcTime.toDate();
|
||||
const formattedDateText = getDateTimeAsLocalFormat()(epoch, 0, 0, 'utc').text;
|
||||
expect(formattedDateText).toContain(dateTimeObject.getFullYear());
|
||||
expect(formattedDateText).toContain(dateTimeObject.getSeconds());
|
||||
expect(formattedDateText).toContain(dateTimeObject.getFullYear().toString());
|
||||
expect(formattedDateText).toContain(dateTimeObject.getSeconds().toString());
|
||||
});
|
||||
|
||||
it('should format as local date (in UTC) and skip date when today', () => {
|
||||
const now = toUtc();
|
||||
const dateTimeObject = now.toDate();
|
||||
const formattedDateText = getDateTimeAsLocalFormatNoDateIfToday()(now.valueOf(), 0, 0, 'utc').text;
|
||||
expect(formattedDateText).not.toContain(dateTimeObject.getFullYear());
|
||||
expect(formattedDateText).toContain(dateTimeObject.getSeconds());
|
||||
expect(formattedDateText).not.toContain(dateTimeObject.getFullYear().toString());
|
||||
expect(formattedDateText).toContain(dateTimeObject.getSeconds().toString());
|
||||
});
|
||||
|
||||
it('should format as from now with days', () => {
|
||||
|
@ -49,7 +49,7 @@
|
||||
"@types/rollup-plugin-visualizer": "4.2.1",
|
||||
"@types/systemjs": "^0.20.6",
|
||||
"lodash": "4.17.21",
|
||||
"pretty-format": "25.1.0",
|
||||
"pretty-format": "27.4.2",
|
||||
"rimraf": "3.0.1",
|
||||
"rollup": "2.58.3",
|
||||
"rollup-plugin-sourcemaps": "0.6.3",
|
||||
|
@ -164,7 +164,7 @@
|
||||
"expose-loader": "3.0.0",
|
||||
"mock-raf": "1.0.1",
|
||||
"postcss-loader": "6.1.1",
|
||||
"pretty-format": "25.1.0",
|
||||
"pretty-format": "27.4.2",
|
||||
"raw-loader": "4.0.2",
|
||||
"react-docgen-typescript-loader": "3.7.2",
|
||||
"react-test-renderer": "17.0.1",
|
||||
|
@ -67,8 +67,8 @@ describe('Lookup gazetteer', () => {
|
||||
-80.891064,
|
||||
-100.891064,
|
||||
-111.891064,
|
||||
undefined,
|
||||
undefined,
|
||||
,
|
||||
,
|
||||
],
|
||||
},
|
||||
Object {
|
||||
@ -79,8 +79,8 @@ describe('Lookup gazetteer', () => {
|
||||
12.448457,
|
||||
24.448457,
|
||||
33.448457,
|
||||
undefined,
|
||||
undefined,
|
||||
,
|
||||
,
|
||||
],
|
||||
},
|
||||
Object {
|
||||
|
@ -6,9 +6,6 @@ import { useLocation } from 'react-router-dom';
|
||||
export function useQueryParams(): [UrlQueryMap, (values: UrlQueryMap, replace?: boolean) => void] {
|
||||
const { search } = useLocation();
|
||||
const queryParams = useMemo(() => locationSearchToObject(search || ''), [search]);
|
||||
const update = useCallback(
|
||||
(values: UrlQueryMap, replace?: boolean) => setImmediate(() => locationService.partial(values, replace)),
|
||||
[]
|
||||
);
|
||||
const update = useCallback((values: UrlQueryMap, replace?: boolean) => locationService.partial(values, replace), []);
|
||||
return [queryParams, update];
|
||||
}
|
||||
|
@ -27,12 +27,10 @@ describe('timeSrv', () => {
|
||||
timeSrv = new TimeSrv(new ContextSrvStub() as any);
|
||||
timeSrv.init(_dashboard);
|
||||
|
||||
beforeEach(() => {
|
||||
locationUpdates = [];
|
||||
const history = new HistoryWrapper();
|
||||
history.getHistory().listen((x) => locationUpdates.push(x));
|
||||
setLocationService(history);
|
||||
});
|
||||
locationUpdates = [];
|
||||
const history = new HistoryWrapper();
|
||||
history.getHistory().listen((x) => locationUpdates.push(x));
|
||||
setLocationService(history);
|
||||
});
|
||||
|
||||
describe('timeRange', () => {
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { lastUsedDatasourceKeyForOrgId } from '../../../core/utils/explore';
|
||||
import store from '../../../core/store';
|
||||
|
||||
const dataSourceMock = {
|
||||
get: jest.fn(),
|
||||
@ -7,11 +8,7 @@ jest.mock('app/features/plugins/datasource_srv', () => ({
|
||||
getDatasourceSrv: jest.fn(() => dataSourceMock),
|
||||
}));
|
||||
|
||||
const storeMock = {
|
||||
getObject: jest.fn().mockReturnValue([]),
|
||||
set: jest.fn(),
|
||||
};
|
||||
jest.mock('app/core/store', () => storeMock);
|
||||
jest.spyOn(store, 'set');
|
||||
|
||||
import { loadAndInitDatasource } from './utils';
|
||||
|
||||
@ -33,7 +30,7 @@ describe('loadAndInitDatasource', () => {
|
||||
expect(dataSourceMock.get).toBeCalledWith('Unknown');
|
||||
expect(dataSourceMock.get).toBeCalledWith();
|
||||
expect(instance).toMatchObject(DEFAULT_DATASOURCE);
|
||||
expect(storeMock.set).toBeCalledWith(lastUsedDatasourceKeyForOrgId(1), DEFAULT_DATASOURCE.uid);
|
||||
expect(store.set).toBeCalledWith(lastUsedDatasourceKeyForOrgId(1), DEFAULT_DATASOURCE.uid);
|
||||
});
|
||||
|
||||
it('saves last loaded data source uid', async () => {
|
||||
@ -44,6 +41,6 @@ describe('loadAndInitDatasource', () => {
|
||||
expect(dataSourceMock.get).toBeCalledTimes(1);
|
||||
expect(dataSourceMock.get).toBeCalledWith('Test');
|
||||
expect(instance).toMatchObject(TEST_DATASOURCE);
|
||||
expect(storeMock.set).toBeCalledWith(lastUsedDatasourceKeyForOrgId(1), TEST_DATASOURCE.uid);
|
||||
expect(store.set).toBeCalledWith(lastUsedDatasourceKeyForOrgId(1), TEST_DATASOURCE.uid);
|
||||
});
|
||||
});
|
||||
|
@ -130,7 +130,7 @@ describe('Cloudwatch SQLBuilderEditor', () => {
|
||||
expect(screen.getByText('CPUUtilization')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
describe('ORDER BY', async () => {
|
||||
describe('ORDER BY', () => {
|
||||
it('should display it correctly when its specified', async () => {
|
||||
const query = makeSQLQuery({
|
||||
orderBy: {
|
||||
|
@ -890,161 +890,6 @@ describe('CloudWatchDatasource', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function describeMetricFindQuery(query: any, func: any) {
|
||||
describe('metricFindQuery ' + query, () => {
|
||||
const scenario: any = {};
|
||||
scenario.setup = async (setupCallback: any) => {
|
||||
beforeEach(async () => {
|
||||
await setupCallback();
|
||||
const { ds } = getTestContext({ response: scenario.requestResponse });
|
||||
ds.metricFindQuery(query).then((args: any) => {
|
||||
scenario.result = args;
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
func(scenario);
|
||||
});
|
||||
}
|
||||
|
||||
describeMetricFindQuery('regions()', async (scenario: any) => {
|
||||
await scenario.setup(() => {
|
||||
scenario.requestResponse = {
|
||||
results: {
|
||||
metricFindQuery: {
|
||||
tables: [{ rows: [['us-east-1', 'us-east-1']] }],
|
||||
},
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
it('should call __GetRegions and return result', () => {
|
||||
expect(scenario.result[0].text).toContain('us-east-1');
|
||||
expect(scenario.request.queries[0].type).toBe('metricFindQuery');
|
||||
expect(scenario.request.queries[0].subtype).toBe('regions');
|
||||
});
|
||||
});
|
||||
|
||||
describeMetricFindQuery('namespaces()', async (scenario: any) => {
|
||||
await scenario.setup(() => {
|
||||
scenario.requestResponse = {
|
||||
results: {
|
||||
metricFindQuery: {
|
||||
tables: [{ rows: [['AWS/EC2', 'AWS/EC2']] }],
|
||||
},
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
it('should call __GetNamespaces and return result', () => {
|
||||
expect(scenario.result[0].text).toContain('AWS/EC2');
|
||||
expect(scenario.request.queries[0].type).toBe('metricFindQuery');
|
||||
expect(scenario.request.queries[0].subtype).toBe('namespaces');
|
||||
});
|
||||
});
|
||||
|
||||
describeMetricFindQuery('metrics(AWS/EC2, us-east-2)', async (scenario: any) => {
|
||||
await scenario.setup(() => {
|
||||
scenario.requestResponse = {
|
||||
results: {
|
||||
metricFindQuery: {
|
||||
tables: [{ rows: [['CPUUtilization', 'CPUUtilization']] }],
|
||||
},
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
it('should call __GetMetrics and return result', () => {
|
||||
expect(scenario.result[0].text).toBe('CPUUtilization');
|
||||
expect(scenario.request.queries[0].type).toBe('metricFindQuery');
|
||||
expect(scenario.request.queries[0].subtype).toBe('metrics');
|
||||
});
|
||||
});
|
||||
|
||||
describeMetricFindQuery('dimension_keys(AWS/EC2)', async (scenario: any) => {
|
||||
await scenario.setup(() => {
|
||||
scenario.requestResponse = {
|
||||
results: {
|
||||
metricFindQuery: {
|
||||
tables: [{ rows: [['InstanceId', 'InstanceId']] }],
|
||||
},
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
it('should call __GetDimensions and return result', () => {
|
||||
expect(scenario.result[0].text).toBe('InstanceId');
|
||||
expect(scenario.request.queries[0].type).toBe('metricFindQuery');
|
||||
expect(scenario.request.queries[0].subtype).toBe('dimension_keys');
|
||||
});
|
||||
});
|
||||
|
||||
describeMetricFindQuery('dimension_values(us-east-1,AWS/EC2,CPUUtilization,InstanceId)', async (scenario: any) => {
|
||||
await scenario.setup(() => {
|
||||
scenario.requestResponse = {
|
||||
results: {
|
||||
metricFindQuery: {
|
||||
tables: [{ rows: [['i-12345678', 'i-12345678']] }],
|
||||
},
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
it('should call __ListMetrics and return result', () => {
|
||||
expect(scenario.result[0].text).toContain('i-12345678');
|
||||
expect(scenario.request.queries[0].type).toBe('metricFindQuery');
|
||||
expect(scenario.request.queries[0].subtype).toBe('dimension_values');
|
||||
});
|
||||
});
|
||||
|
||||
describeMetricFindQuery('dimension_values(default,AWS/EC2,CPUUtilization,InstanceId)', async (scenario: any) => {
|
||||
await scenario.setup(() => {
|
||||
scenario.requestResponse = {
|
||||
results: {
|
||||
metricFindQuery: {
|
||||
tables: [{ rows: [['i-12345678', 'i-12345678']] }],
|
||||
},
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
it('should call __ListMetrics and return result', () => {
|
||||
expect(scenario.result[0].text).toContain('i-12345678');
|
||||
expect(scenario.request.queries[0].type).toBe('metricFindQuery');
|
||||
expect(scenario.request.queries[0].subtype).toBe('dimension_values');
|
||||
});
|
||||
});
|
||||
|
||||
describeMetricFindQuery(
|
||||
'resource_arns(default,ec2:instance,{"environment":["production"]})',
|
||||
async (scenario: any) => {
|
||||
await scenario.setup(() => {
|
||||
scenario.requestResponse = {
|
||||
results: {
|
||||
metricFindQuery: {
|
||||
tables: [
|
||||
{
|
||||
rows: [
|
||||
[
|
||||
'arn:aws:ec2:us-east-1:123456789012:instance/i-12345678901234567',
|
||||
'arn:aws:ec2:us-east-1:123456789012:instance/i-76543210987654321',
|
||||
],
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
it('should call __ListMetrics and return result', () => {
|
||||
expect(scenario.result[0].text).toContain('arn:aws:ec2:us-east-1:123456789012:instance/i-12345678901234567');
|
||||
expect(scenario.request.queries[0].type).toBe('metricFindQuery');
|
||||
expect(scenario.request.queries[0].subtype).toBe('resource_arns');
|
||||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
function genMockFrames(numResponses: number): DataFrame[] {
|
||||
|
@ -33,7 +33,7 @@ async function changeTarget(ctx: any, target: string): Promise<void> {
|
||||
await ctx.dispatch(actions.toggleEditorMode());
|
||||
}
|
||||
|
||||
describe('Graphite actions', async () => {
|
||||
describe('Graphite actions', () => {
|
||||
const ctx = {
|
||||
datasource: {
|
||||
metricFindQuery: jest.fn(() => Promise.resolve([])),
|
||||
|
@ -95,8 +95,7 @@ describe('Live Stream Tests', () => {
|
||||
fakeSocket = new Observable(() => {
|
||||
return () => (unsubscribed = true);
|
||||
}) as any;
|
||||
const spy = spyOn(rxJsWebSocket, 'webSocket');
|
||||
spy.and.returnValue(fakeSocket);
|
||||
jest.spyOn(rxJsWebSocket, 'webSocket').mockReturnValue(fakeSocket as rxJsWebSocket.WebSocketSubject<unknown>);
|
||||
|
||||
const liveStreams = new LiveStreams();
|
||||
const stream1 = liveStreams.getStream(makeTarget('url_to_match'));
|
||||
@ -139,6 +138,7 @@ describe('Live Stream Tests', () => {
|
||||
return logStreamAfterError;
|
||||
})
|
||||
) as any;
|
||||
jest.spyOn(rxJsWebSocket, 'webSocket').mockReturnValue(fakeSocket as rxJsWebSocket.WebSocketSubject<unknown>);
|
||||
const liveStreams = new LiveStreams();
|
||||
await expect(liveStreams.getStream(makeTarget('url_to_match'), 100)).toEmitValuesWith((received) => {
|
||||
const data = received[0];
|
||||
|
@ -1,6 +1,5 @@
|
||||
import { GraphCtrl } from '../module';
|
||||
import { dateTime } from '@grafana/data';
|
||||
import TimeSeries from 'app/core/time_series2';
|
||||
|
||||
jest.mock('../graph', () => ({}));
|
||||
|
||||
@ -110,40 +109,4 @@ describe.skip('GraphCtrl', () => {
|
||||
expect(ctx.ctrl.dataWarning.title).toBe('No data');
|
||||
});
|
||||
});
|
||||
|
||||
describe('when data is exported to CSV', () => {
|
||||
const appEventMock = jest.fn();
|
||||
|
||||
beforeEach(() => {
|
||||
appEventMock.mockReset();
|
||||
scope.$root = { appEvent: appEventMock };
|
||||
scope.$new = () => ({});
|
||||
const data = [
|
||||
{
|
||||
target: 'test.normal',
|
||||
datapoints: [
|
||||
[10, 1],
|
||||
[10, 2],
|
||||
],
|
||||
},
|
||||
{
|
||||
target: 'test.nulls',
|
||||
datapoints: [
|
||||
[null, 1],
|
||||
[null, 2],
|
||||
],
|
||||
},
|
||||
{
|
||||
target: 'test.zeros',
|
||||
datapoints: [
|
||||
[0, 1],
|
||||
[0, 2],
|
||||
],
|
||||
},
|
||||
];
|
||||
ctx.ctrl.onDataSnapshotLoad(data);
|
||||
// allIsNull / allIsZero are set by getFlotPairs
|
||||
ctx.ctrl.seriesList.forEach((series: TimeSeries) => series.getFlotPairs(''));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -3,43 +3,20 @@ jest.mock('app/core/core', () => ({}));
|
||||
import $ from 'jquery';
|
||||
import GraphTooltip from '../graph_tooltip';
|
||||
|
||||
const scope = {
|
||||
const scope: any = {
|
||||
appEvent: jest.fn(),
|
||||
onAppEvent: jest.fn(),
|
||||
ctrl: {},
|
||||
ctrl: {
|
||||
panel: {
|
||||
tooltip: {},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const elem = $('<div></div>');
|
||||
const dashboard = {};
|
||||
const getSeriesFn = () => {};
|
||||
|
||||
function describeSharedTooltip(desc: string, fn: any) {
|
||||
const ctx: any = {};
|
||||
ctx.ctrl = scope.ctrl;
|
||||
ctx.ctrl.panel = {
|
||||
tooltip: {
|
||||
shared: true,
|
||||
},
|
||||
legend: {},
|
||||
stack: false,
|
||||
};
|
||||
|
||||
ctx.setup = (setupFn: any) => {
|
||||
ctx.setupFn = setupFn;
|
||||
};
|
||||
|
||||
describe(desc, () => {
|
||||
beforeEach(() => {
|
||||
ctx.setupFn();
|
||||
// @ts-ignore
|
||||
const tooltip = new GraphTooltip(elem, dashboard, scope, getSeriesFn);
|
||||
ctx.results = tooltip.getMultiSeriesPlotHoverInfo(ctx.data, ctx.pos);
|
||||
});
|
||||
|
||||
fn(ctx);
|
||||
});
|
||||
}
|
||||
|
||||
describe('findHoverIndexFromData', () => {
|
||||
// @ts-ignore
|
||||
const tooltip = new GraphTooltip(elem, dashboard, scope, getSeriesFn);
|
||||
@ -77,9 +54,19 @@ describe('findHoverIndexFromData', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describeSharedTooltip('steppedLine false, stack false', (ctx: any) => {
|
||||
ctx.setup(() => {
|
||||
ctx.data = [
|
||||
describe('with a shared tooltip', () => {
|
||||
beforeEach(() => {
|
||||
scope.ctrl.panel = {
|
||||
tooltip: {
|
||||
shared: true,
|
||||
},
|
||||
legend: {},
|
||||
stack: false,
|
||||
};
|
||||
});
|
||||
|
||||
describe('steppedLine false, stack false', () => {
|
||||
const data = [
|
||||
{
|
||||
data: [
|
||||
[10, 15],
|
||||
@ -97,42 +84,34 @@ describeSharedTooltip('steppedLine false, stack false', (ctx: any) => {
|
||||
hideTooltip: false,
|
||||
},
|
||||
];
|
||||
ctx.pos = { x: 11 };
|
||||
const pos = { x: 11 };
|
||||
|
||||
it('should return 2 series', () => {
|
||||
// @ts-ignore
|
||||
const tooltip = new GraphTooltip(elem, dashboard, scope, getSeriesFn);
|
||||
const results = tooltip.getMultiSeriesPlotHoverInfo(data, pos);
|
||||
expect(results.length).toBe(2);
|
||||
});
|
||||
|
||||
it('should add time to results array', () => {
|
||||
// @ts-ignore
|
||||
const tooltip = new GraphTooltip(elem, dashboard, scope, getSeriesFn);
|
||||
const results = tooltip.getMultiSeriesPlotHoverInfo(data, pos);
|
||||
expect(results.time).toBe(10);
|
||||
});
|
||||
|
||||
it('should set value and hoverIndex', () => {
|
||||
// @ts-ignore
|
||||
const tooltip = new GraphTooltip(elem, dashboard, scope, getSeriesFn);
|
||||
const results = tooltip.getMultiSeriesPlotHoverInfo(data, pos);
|
||||
expect(results[0].value).toBe(15);
|
||||
expect(results[1].value).toBe(2);
|
||||
expect(results[0].hoverIndex).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
it('should return 2 series', () => {
|
||||
expect(ctx.results.length).toBe(2);
|
||||
});
|
||||
|
||||
it('should add time to results array', () => {
|
||||
expect(ctx.results.time).toBe(10);
|
||||
});
|
||||
|
||||
it('should set value and hoverIndex', () => {
|
||||
expect(ctx.results[0].value).toBe(15);
|
||||
expect(ctx.results[1].value).toBe(2);
|
||||
expect(ctx.results[0].hoverIndex).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
describeSharedTooltip('one series is hidden', (ctx: any) => {
|
||||
ctx.setup(() => {
|
||||
ctx.data = [
|
||||
{
|
||||
data: [
|
||||
[10, 15],
|
||||
[12, 20],
|
||||
],
|
||||
},
|
||||
{ data: [] },
|
||||
];
|
||||
ctx.pos = { x: 11 };
|
||||
});
|
||||
});
|
||||
|
||||
describeSharedTooltip('steppedLine false, stack true, individual false', (ctx: any) => {
|
||||
ctx.setup(() => {
|
||||
ctx.data = [
|
||||
describe('steppedLine false, stack true, individual false', () => {
|
||||
const data = [
|
||||
{
|
||||
data: [
|
||||
[10, 15],
|
||||
@ -166,18 +145,19 @@ describeSharedTooltip('steppedLine false, stack true, individual false', (ctx: a
|
||||
hideTooltip: false,
|
||||
},
|
||||
];
|
||||
ctx.ctrl.panel.stack = true;
|
||||
ctx.pos = { x: 11 };
|
||||
scope.ctrl.panel.stack = true;
|
||||
const pos = { x: 11 };
|
||||
|
||||
it('should show stacked value', () => {
|
||||
// @ts-ignore
|
||||
const tooltip = new GraphTooltip(elem, dashboard, scope, getSeriesFn);
|
||||
const results = tooltip.getMultiSeriesPlotHoverInfo(data, pos);
|
||||
expect(results[1].value).toBe(17);
|
||||
});
|
||||
});
|
||||
|
||||
it('should show stacked value', () => {
|
||||
expect(ctx.results[1].value).toBe(17);
|
||||
});
|
||||
});
|
||||
|
||||
describeSharedTooltip('steppedLine false, stack true, individual false, series stack false', (ctx: any) => {
|
||||
ctx.setup(() => {
|
||||
ctx.data = [
|
||||
describe('steppedLine false, stack true, individual false, series stack false', () => {
|
||||
const data = [
|
||||
{
|
||||
data: [
|
||||
[10, 15],
|
||||
@ -211,18 +191,19 @@ describeSharedTooltip('steppedLine false, stack true, individual false, series s
|
||||
hideTooltip: false,
|
||||
},
|
||||
];
|
||||
ctx.ctrl.panel.stack = true;
|
||||
ctx.pos = { x: 11 };
|
||||
scope.ctrl.panel.stack = true;
|
||||
const pos = { x: 11 };
|
||||
|
||||
it('should not show stacked value', () => {
|
||||
// @ts-ignore
|
||||
const tooltip = new GraphTooltip(elem, dashboard, scope, getSeriesFn);
|
||||
const results = tooltip.getMultiSeriesPlotHoverInfo(data, pos);
|
||||
expect(results[1].value).toBe(2);
|
||||
});
|
||||
});
|
||||
|
||||
it('should not show stacked value', () => {
|
||||
expect(ctx.results[1].value).toBe(2);
|
||||
});
|
||||
});
|
||||
|
||||
describeSharedTooltip('steppedLine false, stack true, individual true', (ctx: any) => {
|
||||
ctx.setup(() => {
|
||||
ctx.data = [
|
||||
describe('steppedLine false, stack true, individual true', () => {
|
||||
const data = [
|
||||
{
|
||||
data: [
|
||||
[10, 15],
|
||||
@ -256,12 +237,15 @@ describeSharedTooltip('steppedLine false, stack true, individual true', (ctx: an
|
||||
hideTooltip: false,
|
||||
},
|
||||
];
|
||||
ctx.ctrl.panel.stack = true;
|
||||
ctx.ctrl.panel.tooltip.value_type = 'individual';
|
||||
ctx.pos = { x: 11 };
|
||||
});
|
||||
scope.ctrl.panel.stack = true;
|
||||
scope.ctrl.panel.tooltip.value_type = 'individual';
|
||||
const pos = { x: 11 };
|
||||
|
||||
it('should not show stacked value', () => {
|
||||
expect(ctx.results[1].value).toBe(2);
|
||||
it('should not show stacked value', () => {
|
||||
// @ts-ignore
|
||||
const tooltip = new GraphTooltip(elem, dashboard, scope, getSeriesFn);
|
||||
const results = tooltip.getMultiSeriesPlotHoverInfo(data, pos);
|
||||
expect(results[1].value).toBe(2);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user