Skip to content

Commit

Permalink
fix: action params state and params tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Marginy605 committed Dec 14, 2023
1 parent 08917e5 commit ba80c53
Show file tree
Hide file tree
Showing 2 changed files with 145 additions and 157 deletions.
157 changes: 0 additions & 157 deletions src/shared/modules/__tests__/helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
pickExceptActionParamsFromParams,
transformParamsToActionParams,
} from '../helpers';
import {getItemsParams} from '../state-and-params';

const DEFAULT_CONTROL_ID = 'controlId';
const DEFAULT_WIDGET_ID = 'widgetId';
Expand Down Expand Up @@ -94,149 +93,6 @@ const exeptActionParam3 = {
},
};

const config = {
id: '7kw',
items: [
{
id: 'nvp',
data: {
tabs: [
{
id: 'rkq',
title: 'test',
params: {},
chartId: 'some-chart',
isDefault: true,
autoHeight: false,
description: '',
enableActionParams: true,
},
],
hideTitle: true,
},
type: 'widget',
layout: {
h: 12,
w: 12,
},
namespace: 'default',
},
{
id: 'Q9K',
data: {
title: 'Year',
source: {},
},
type: 'control',
layout: {
h: 2,
w: 8,
},
defaults: {
year_some_id: '',
},
namespace: 'default',
},
],
title: 'test',
layout: [
{
h: 12,
i: 'nvp',
w: 12,
x: 0,
y: 0,
},
{
h: 2,
i: 'Q9K',
w: 8,
x: 12,
y: 0,
},
],
aliases: {},
connections: [],
salt: '123',
counter: 1,
};
const itemsStateAndParamsActionParamTest1 = {
nvp: {
params: {
_ap_year_some_id: ['2022'],
},
},
__meta__: {
queue: [
{
id: 'nvp',
tabId: 'rkq',
},
],
version: 2,
},
};

const stateAndParamsActionParamsRes1 = {
Q9K: {
year_some_id: ['2022'],
},
nvp: {
_ap_year_some_id: ['2022'],
year_some_id: '',
},
};

const plugins = [
{
type: 'title',
defaultLayout: {
x: 0,
y: null,
w: 36,
h: 2,
minW: 4,
minH: 2,
},
},
{
type: 'text',
defaultLayout: {
x: 0,
y: null,
w: 12,
h: 6,
minW: 4,
minH: 2,
},
},
{
getDistincts: {
promise: {},
},
type: 'control',
defaultLayout: {
x: 0,
y: null,
w: 8,
h: 2,
minW: 4,
minH: 2,
},
},
{
type: 'widget',
defaultLayout: {
x: 0,
y: null,
w: 12,
h: 12,
minW: 4,
minH: 2,
},
},
];

const getMockedWidgetItem = ({id = DEFAULT_WIDGET_ID, tabs}: MockedWidgetItemArgs): ConfigItem => ({
id,
data: {tabs},
Expand Down Expand Up @@ -508,17 +364,4 @@ describe('modules.helpers', () => {
);
});
});

describe('state and params with actionParams', () => {
it('check state 1', () => {
const res = getItemsParams({
defaultGlobalParams: {},
globalParams: {},
config,
itemsStateAndParams: itemsStateAndParamsActionParamTest1,
plugins,
});
expect(res).toEqual(stateAndParamsActionParamsRes1);
});
});
});
145 changes: 145 additions & 0 deletions src/shared/units/__tests__/state-and-params.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -599,3 +599,148 @@ describe('getItemsStateAndParams actionParams variants check', () => {
});
});
});

const config = {
id: '7kw',
items: [
{
id: 'nvp',
data: {
tabs: [
{
id: 'rkq',
title: 'test',
params: {},
chartId: 'some-chart',
isDefault: true,
autoHeight: false,
description: '',
enableActionParams: true,
},
],
hideTitle: true,
},
type: 'widget',
layout: {
h: 12,
w: 12,
},
namespace: 'default',
},
{
id: 'Q9K',
data: {
title: 'Year',
source: {},
},
type: 'control',
layout: {
h: 2,
w: 8,
},
defaults: {
year_some_id: '',
},
namespace: 'default',
},
],
title: 'test',
layout: [
{
h: 12,
i: 'nvp',
w: 12,
x: 0,
y: 0,
},
{
h: 2,
i: 'Q9K',
w: 8,
x: 12,
y: 0,
},
],
aliases: {},
connections: [],
salt: '123',
counter: 1,
};
const itemsStateAndParamsActionParamTest1 = {
nvp: {
params: {
_ap_year_some_id: ['2022'],
},
},
__meta__: {
queue: [
{
id: 'nvp',
tabId: 'rkq',
},
],
version: 2,
},
};
const stateAndParamsActionParamsRes1 = {
Q9K: {
year_some_id: ['2022'],
},
nvp: {
_ap_year_some_id: ['2022'],
year_some_id: '',
},
};

const itemsStateAndParamsActionParamTest2 = {
nvp: {
params: {
_ap_another: ['2022'],
},
},
__meta__: {
queue: [
{
id: 'nvp',
tabId: 'rkq',
},
],
version: 2,
},
};

const stateAndParamsActionParamsRes2 = {
Q9K: {
params: {
year_some_id: ['2022'],
},
state: {},
},
nvp: {
params: {
_ap_year_some_id: ['2022'],
year_some_id: '',
},
state: {},
},
};

describe('state and params with actionParams', () => {
it('check state', () => {
const res1 = getItemsStateAndParamsDL({
defaultGlobalParams: {},
globalParams: {},
config,
itemsStateAndParams: itemsStateAndParamsActionParamTest1,
});
expect(res1).toEqual(stateAndParamsActionParamsRes1);

const res2 = getItemsStateAndParamsDL({
defaultGlobalParams: {},
globalParams: {},
config,
itemsStateAndParams: itemsStateAndParamsActionParamTest2,
});
expect(res2).toEqual(stateAndParamsActionParamsRes2);
});
});

0 comments on commit ba80c53

Please sign in to comment.