123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493 |
- import {act, render} from 'sentry-test/reactTestingLibrary';
- import {DiscoverDatasets} from 'sentry/utils/discover/types';
- import {
- PageParamsProvider,
- useExplorePageParams,
- useSetExploreDataset,
- useSetExploreFields,
- useSetExploreGroupBys,
- useSetExploreMode,
- useSetExplorePageParams,
- useSetExploreQuery,
- useSetExploreSortBys,
- useSetExploreVisualizes,
- } from 'sentry/views/explore/contexts/pageParamsContext';
- import {Mode} from 'sentry/views/explore/contexts/pageParamsContext/mode';
- import {ChartType} from 'sentry/views/insights/common/components/chart';
- describe('PageParamsProvider', function () {
- let pageParams: ReturnType<typeof useExplorePageParams>;
- let setPageParams: ReturnType<typeof useSetExplorePageParams>;
- let setDataset: ReturnType<typeof useSetExploreDataset>;
- let setFields: ReturnType<typeof useSetExploreFields>;
- let setGroupBys: ReturnType<typeof useSetExploreGroupBys>;
- let setMode: ReturnType<typeof useSetExploreMode>;
- let setQuery: ReturnType<typeof useSetExploreQuery>;
- let setSortBys: ReturnType<typeof useSetExploreSortBys>;
- let setVisualizes: ReturnType<typeof useSetExploreVisualizes>;
- function Component() {
- pageParams = useExplorePageParams();
- setPageParams = useSetExplorePageParams();
- setDataset = useSetExploreDataset();
- setFields = useSetExploreFields();
- setGroupBys = useSetExploreGroupBys();
- setMode = useSetExploreMode();
- setQuery = useSetExploreQuery();
- setSortBys = useSetExploreSortBys();
- setVisualizes = useSetExploreVisualizes();
- return <br />;
- }
- function renderTestComponent(defaultPageParams?: any) {
- render(
- <PageParamsProvider>
- <Component />
- </PageParamsProvider>,
- {disableRouterMocks: true}
- );
- act(() =>
- setPageParams({
- dataset: DiscoverDatasets.SPANS_EAP_RPC,
- fields: ['id', 'timestamp'],
- groupBys: ['span.op'],
- mode: Mode.AGGREGATE,
- query: '',
- sortBys: [{field: 'count(span.self_time)', kind: 'asc'}],
- visualizes: [
- {
- chartType: ChartType.AREA,
- label: 'A',
- yAxes: ['count(span.self_time)'],
- },
- ],
- ...defaultPageParams,
- })
- );
- }
- it('has expected default', function () {
- render(
- <PageParamsProvider>
- <Component />
- </PageParamsProvider>,
- {disableRouterMocks: true}
- );
- expect(pageParams).toEqual({
- dataset: undefined,
- fields: [
- 'id',
- 'span.op',
- 'span.description',
- 'span.duration',
- 'transaction',
- 'timestamp',
- ],
- groupBys: ['span.op'],
- mode: Mode.SAMPLES,
- query: '',
- sortBys: [{field: 'timestamp', kind: 'desc'}],
- visualizes: [
- {
- chartType: ChartType.LINE,
- label: 'A',
- yAxes: ['avg(span.duration)'],
- },
- ],
- });
- });
- it('correctly updates dataset', function () {
- renderTestComponent();
- act(() => setDataset(DiscoverDatasets.SPANS_EAP));
- expect(pageParams).toEqual({
- dataset: DiscoverDatasets.SPANS_EAP,
- fields: ['id', 'timestamp'],
- groupBys: ['span.op'],
- mode: Mode.AGGREGATE,
- query: '',
- sortBys: [{field: 'count(span.self_time)', kind: 'asc'}],
- visualizes: [
- {
- chartType: ChartType.AREA,
- label: 'A',
- yAxes: ['count(span.self_time)'],
- },
- ],
- });
- });
- it('correctly updates fields', function () {
- renderTestComponent();
- act(() => setFields(['id', 'span.op', 'timestamp']));
- expect(pageParams).toEqual({
- dataset: DiscoverDatasets.SPANS_EAP_RPC,
- fields: ['id', 'span.op', 'timestamp'],
- groupBys: ['span.op'],
- mode: Mode.AGGREGATE,
- query: '',
- sortBys: [{field: 'count(span.self_time)', kind: 'asc'}],
- visualizes: [
- {
- chartType: ChartType.AREA,
- label: 'A',
- yAxes: ['count(span.self_time)'],
- },
- ],
- });
- });
- it('correctly updates groupBys', function () {
- renderTestComponent();
- act(() => setGroupBys(['browser.name', 'sdk.name']));
- expect(pageParams).toEqual({
- dataset: DiscoverDatasets.SPANS_EAP_RPC,
- fields: ['id', 'timestamp'],
- groupBys: ['browser.name', 'sdk.name'],
- mode: Mode.AGGREGATE,
- query: '',
- sortBys: [{field: 'count(span.self_time)', kind: 'asc'}],
- visualizes: [
- {
- chartType: ChartType.AREA,
- label: 'A',
- yAxes: ['count(span.self_time)'],
- },
- ],
- });
- });
- it('correctly gives default for empty groupBys', function () {
- renderTestComponent();
- act(() => setGroupBys([]));
- expect(pageParams).toEqual({
- dataset: DiscoverDatasets.SPANS_EAP_RPC,
- fields: ['id', 'timestamp'],
- groupBys: ['span.op'],
- mode: Mode.AGGREGATE,
- query: '',
- sortBys: [{field: 'count(span.self_time)', kind: 'asc'}],
- visualizes: [
- {
- chartType: ChartType.AREA,
- label: 'A',
- yAxes: ['count(span.self_time)'],
- },
- ],
- });
- });
- it('permits ungrouped', function () {
- renderTestComponent();
- act(() => setGroupBys(['']));
- expect(pageParams).toEqual({
- dataset: DiscoverDatasets.SPANS_EAP_RPC,
- fields: ['id', 'timestamp'],
- groupBys: [''],
- mode: Mode.AGGREGATE,
- query: '',
- sortBys: [{field: 'count(span.self_time)', kind: 'asc'}],
- visualizes: [
- {
- chartType: ChartType.AREA,
- label: 'A',
- yAxes: ['count(span.self_time)'],
- },
- ],
- });
- });
- it('correctly updates mode from samples to aggregates', function () {
- renderTestComponent({mode: Mode.SAMPLES});
- act(() => setMode(Mode.AGGREGATE));
- expect(pageParams).toEqual({
- dataset: DiscoverDatasets.SPANS_EAP_RPC,
- fields: ['id', 'timestamp'],
- groupBys: ['span.op'],
- mode: Mode.AGGREGATE,
- query: '',
- sortBys: [{field: 'count(span.self_time)', kind: 'asc'}],
- visualizes: [
- {
- chartType: ChartType.AREA,
- label: 'A',
- yAxes: ['count(span.self_time)'],
- },
- ],
- });
- });
- it('correctly updates mode from aggregates to sample without group bys', function () {
- renderTestComponent({mode: Mode.AGGREGATE, groupBys: [''], sortBys: null});
- act(() => setMode(Mode.SAMPLES));
- expect(pageParams).toEqual({
- dataset: DiscoverDatasets.SPANS_EAP_RPC,
- fields: ['id', 'timestamp'],
- groupBys: [''],
- mode: Mode.SAMPLES,
- query: '',
- sortBys: [{field: 'timestamp', kind: 'desc'}],
- visualizes: [
- {
- chartType: ChartType.AREA,
- label: 'A',
- yAxes: ['count(span.self_time)'],
- },
- ],
- });
- });
- it('correctly updates mode from aggregates to sample with group bys', function () {
- renderTestComponent({
- mode: Mode.AGGREGATE,
- sortBys: null,
- fields: ['id', 'sdk.name', 'sdk.version', 'timestamp'],
- groupBys: ['sdk.name', 'sdk.version', 'span.op', ''],
- });
- act(() => setMode(Mode.SAMPLES));
- expect(pageParams).toEqual({
- dataset: DiscoverDatasets.SPANS_EAP_RPC,
- fields: ['id', 'sdk.name', 'sdk.version', 'timestamp', 'span.op'],
- groupBys: ['sdk.name', 'sdk.version', 'span.op', ''],
- mode: Mode.SAMPLES,
- query: '',
- sortBys: [{field: 'timestamp', kind: 'desc'}],
- visualizes: [
- {
- chartType: ChartType.AREA,
- label: 'A',
- yAxes: ['count(span.self_time)'],
- },
- ],
- });
- });
- it('correctly updates query', function () {
- renderTestComponent();
- act(() => setQuery('foo:bar'));
- expect(pageParams).toEqual({
- dataset: DiscoverDatasets.SPANS_EAP_RPC,
- fields: ['id', 'timestamp'],
- groupBys: ['span.op'],
- mode: Mode.AGGREGATE,
- query: 'foo:bar',
- sortBys: [{field: 'count(span.self_time)', kind: 'asc'}],
- visualizes: [
- {
- chartType: ChartType.AREA,
- label: 'A',
- yAxes: ['count(span.self_time)'],
- },
- ],
- });
- });
- it('correctly updates sort bys in samples mode with known field', function () {
- renderTestComponent({mode: Mode.SAMPLES});
- act(() => setSortBys([{field: 'id', kind: 'desc'}]));
- expect(pageParams).toEqual({
- dataset: DiscoverDatasets.SPANS_EAP_RPC,
- fields: ['id', 'timestamp'],
- groupBys: ['span.op'],
- mode: Mode.SAMPLES,
- query: '',
- sortBys: [{field: 'id', kind: 'desc'}],
- visualizes: [
- {
- chartType: ChartType.AREA,
- label: 'A',
- yAxes: ['count(span.self_time)'],
- },
- ],
- });
- });
- it('correctly updates sort bys in samples mode with unknown field', function () {
- renderTestComponent({mode: Mode.SAMPLES});
- act(() => setSortBys([{field: 'span.op', kind: 'desc'}]));
- expect(pageParams).toEqual({
- dataset: DiscoverDatasets.SPANS_EAP_RPC,
- fields: ['id', 'timestamp'],
- groupBys: ['span.op'],
- mode: Mode.SAMPLES,
- query: '',
- sortBys: [{field: 'timestamp', kind: 'desc'}],
- visualizes: [
- {
- chartType: ChartType.AREA,
- label: 'A',
- yAxes: ['count(span.self_time)'],
- },
- ],
- });
- });
- it('correctly updates sort bys in aggregates mode with known y axis', function () {
- renderTestComponent({
- mode: Mode.AGGREGATE,
- visualizes: [
- {
- chartType: ChartType.AREA,
- label: 'A',
- yAxes: ['min(span.self_time)', 'max(span.duration)'],
- },
- ],
- });
- act(() => setSortBys([{field: 'max(span.duration)', kind: 'desc'}]));
- expect(pageParams).toEqual({
- dataset: DiscoverDatasets.SPANS_EAP_RPC,
- fields: ['id', 'timestamp'],
- groupBys: ['span.op'],
- mode: Mode.AGGREGATE,
- query: '',
- sortBys: [{field: 'max(span.duration)', kind: 'desc'}],
- visualizes: [
- {
- chartType: ChartType.AREA,
- label: 'A',
- yAxes: ['min(span.self_time)', 'max(span.duration)'],
- },
- ],
- });
- });
- it('correctly updates sort bys in aggregates mode with unknown y axis', function () {
- renderTestComponent({
- mode: Mode.AGGREGATE,
- visualizes: [
- {
- chartType: ChartType.AREA,
- label: 'A',
- yAxes: ['min(span.self_time)', 'max(span.duration)'],
- },
- ],
- });
- act(() => setSortBys([{field: 'avg(span.duration)', kind: 'desc'}]));
- expect(pageParams).toEqual({
- dataset: DiscoverDatasets.SPANS_EAP_RPC,
- fields: ['id', 'timestamp'],
- groupBys: ['span.op'],
- mode: Mode.AGGREGATE,
- query: '',
- sortBys: [{field: 'min(span.self_time)', kind: 'desc'}],
- visualizes: [
- {
- chartType: ChartType.AREA,
- label: 'A',
- yAxes: ['min(span.self_time)', 'max(span.duration)'],
- },
- ],
- });
- });
- it('correctly updates sort bys in aggregates mode with known group by', function () {
- renderTestComponent({mode: Mode.AGGREGATE, groupBys: ['sdk.name']});
- act(() => setSortBys([{field: 'sdk.name', kind: 'desc'}]));
- expect(pageParams).toEqual({
- dataset: DiscoverDatasets.SPANS_EAP_RPC,
- fields: ['id', 'timestamp'],
- groupBys: ['sdk.name'],
- mode: Mode.AGGREGATE,
- query: '',
- sortBys: [{field: 'sdk.name', kind: 'desc'}],
- visualizes: [
- {
- chartType: ChartType.AREA,
- label: 'A',
- yAxes: ['count(span.self_time)'],
- },
- ],
- });
- });
- it('correctly updates sort bys in aggregates mode with unknown group by', function () {
- renderTestComponent({mode: Mode.AGGREGATE, groupBys: ['sdk.name']});
- act(() => setSortBys([{field: 'sdk.version', kind: 'desc'}]));
- expect(pageParams).toEqual({
- dataset: DiscoverDatasets.SPANS_EAP_RPC,
- fields: ['id', 'timestamp'],
- groupBys: ['sdk.name'],
- mode: Mode.AGGREGATE,
- query: '',
- sortBys: [{field: 'count(span.self_time)', kind: 'desc'}],
- visualizes: [
- {
- chartType: ChartType.AREA,
- label: 'A',
- yAxes: ['count(span.self_time)'],
- },
- ],
- });
- });
- it('correctly updates visualizes with labels', function () {
- renderTestComponent();
- act(() =>
- setVisualizes([
- {
- chartType: ChartType.AREA,
- yAxes: ['count(span.self_time)'],
- },
- {
- chartType: ChartType.LINE,
- yAxes: ['avg(span.duration)', 'avg(span.self_time)'],
- },
- ])
- );
- expect(pageParams).toEqual({
- dataset: DiscoverDatasets.SPANS_EAP_RPC,
- fields: ['id', 'timestamp'],
- groupBys: ['span.op'],
- mode: Mode.AGGREGATE,
- query: '',
- sortBys: [{field: 'count(span.self_time)', kind: 'asc'}],
- visualizes: [
- {
- chartType: ChartType.AREA,
- label: 'A',
- yAxes: ['count(span.self_time)'],
- },
- {
- chartType: ChartType.LINE,
- label: 'B',
- yAxes: ['avg(span.duration)', 'avg(span.self_time)'],
- },
- ],
- });
- });
- });
|