Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Dosant committed Jan 29, 2020
1 parent 7017440 commit c0b6cbe
Showing 1 changed file with 44 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,16 @@ import { esFilters } from '../../../common';
import { coreMock } from '../../../../../core/public/mocks';
const setupMock = coreMock.createSetup();

setupMock.uiSettings.get.mockImplementation((key: string) => {
return true;
});
const uiSettingsMock = (pinnedByDefault: boolean) => (key: string) => {
switch (key) {
case 'filters:pinnedByDefault':
return pinnedByDefault;
default:
throw new Error(`Unexpected uiSettings key in FilterManager mock: ${key}`);
}
};

setupMock.uiSettings.get.mockImplementation(uiSettingsMock(true));

describe('filter_manager', () => {
let updateSubscription: Subscription | undefined;
Expand Down Expand Up @@ -224,6 +231,40 @@ describe('filter_manager', () => {
expect(newGlobalFilters).toHaveLength(2);
expect(newAppFilters).toHaveLength(1);
});

test('set filter with no state, and force pin', async () => {
const f1 = getFilter(esFilters.FilterStateStore.GLOBAL_STATE, false, false, 'age', 38);
f1.$state = undefined;

filterManager.setFilters([f1], true);
expect(filterManager.getGlobalFilters()).toHaveLength(1);
});

test('set filter with no state, and no pin', async () => {
const f1 = getFilter(esFilters.FilterStateStore.GLOBAL_STATE, false, false, 'age', 38);
f1.$state = undefined;

filterManager.setFilters([f1], false);
expect(filterManager.getAppFilters()).toHaveLength(1);
});

test('set filters with default pin', async () => {
const f1 = getFilter(esFilters.FilterStateStore.GLOBAL_STATE, false, false, 'age', 38);
f1.$state = undefined;
setupMock.uiSettings.get.mockImplementationOnce(uiSettingsMock(true));

filterManager.setFilters([f1]);
expect(filterManager.getGlobalFilters()).toHaveLength(1);
});

test('set filters without default pin', async () => {
const f1 = getFilter(esFilters.FilterStateStore.GLOBAL_STATE, false, false, 'age', 38);
f1.$state = undefined;

setupMock.uiSettings.get.mockImplementationOnce(uiSettingsMock(false));
filterManager.setFilters([f1]);
expect(filterManager.getAppFilters()).toHaveLength(1);
});
});

describe('add filters', () => {
Expand Down

0 comments on commit c0b6cbe

Please sign in to comment.