Skip to content

Commit

Permalink
[Discover] Update jest tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jughosta committed Nov 13, 2023
1 parent 9ce18f7 commit a40409b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
Expand Up @@ -35,7 +35,7 @@ describe('changeDataView', () => {
await changeDataView(dataViewWithDefaultColumnMock.id!, params);
expect(params.appState.update).toHaveBeenCalledWith({
columns: ['default_column'], // default_column would be added as dataViewWithDefaultColumn has it as a mapped field
index: 'data-view-with-various-field-types-and-default-column-id',
index: 'data-view-with-user-default-column-id',
sort: [['@timestamp', 'desc']],
});
});
Expand Down
Expand Up @@ -41,6 +41,17 @@ const currentDataView = getDataView('curr', '', ['category', 'name']);
const nextDataView = getDataView('next', '', ['category', 'user_default_column']);

describe('Discover getDataViewAppState', () => {
test('removing fields that are not part of the next data view, keeping unknown fields ', async () => {
const result = getDataViewAppState(
currentDataView,
nextDataView,
emptyDefaultColumns,
['category', 'name', 'unknown'],
[['category', 'desc']]
);
expect(result.columns).toEqual(['category', 'unknown']);
expect(result.sort).toEqual([['category', 'desc']]);
});
test('removing fields that are not part of the next data view and adding default columns', async () => {
const result = getDataViewAppState(
currentDataView,
Expand Down
Expand Up @@ -28,8 +28,13 @@ export function getDataViewAppState(
let columns = currentColumns || [];

if (modifyColumns) {
const currentUnknownColumns = columns.filter(
(column) => !currentDataView.fields.getByName(column) && !defaultColumns.includes(column)
);
const currentColumnsRefreshed = uniq([...columns, ...defaultColumns]);
columns = currentColumnsRefreshed.filter((column) => nextDataView.fields.getByName(column));
columns = currentColumnsRefreshed.filter(
(column) => nextDataView.fields.getByName(column) || currentUnknownColumns.includes(column)
);
}

if (query && isOfAggregateQueryType(query)) {
Expand Down

0 comments on commit a40409b

Please sign in to comment.