forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Uptime] Clear
selectedFilters
state when action payload is blank (e…
…lastic#99851) * Clear `selectedFilters` state when action payload is blank. * Add tests. * Fix import error.
- Loading branch information
1 parent
ea75823
commit 5dec3db
Showing
2 changed files
with
78 additions
and
4 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
x-pack/plugins/uptime/public/state/reducers/selected_filters.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { selectedFiltersReducer } from './selected_filters'; | ||
import { | ||
getSelectedFilters, | ||
setSelectedFilters, | ||
SelectedFilters, | ||
} from '../actions/selected_filters'; | ||
import { createAction } from 'redux-actions'; | ||
|
||
describe('selectedFiltersReducer', () => { | ||
let state: SelectedFilters; | ||
|
||
beforeEach(() => { | ||
state = { | ||
locations: [], | ||
ports: [], | ||
schemes: ['http'], | ||
tags: [], | ||
}; | ||
}); | ||
|
||
it('returns state by default', () => { | ||
expect(selectedFiltersReducer(state, createAction<void>('fake action')())).toEqual(state); | ||
}); | ||
|
||
describe('setSelectedFilters', () => { | ||
it('returns null for null payload', () => { | ||
expect(selectedFiltersReducer(state, setSelectedFilters(null))).toBeNull(); | ||
}); | ||
|
||
it('sets state to the action payload if state is null', () => { | ||
expect( | ||
selectedFiltersReducer( | ||
null, | ||
setSelectedFilters({ | ||
locations: [], | ||
ports: [5601], | ||
schemes: [], | ||
tags: [], | ||
}) | ||
) | ||
).toEqual({ locations: [], ports: [5601], schemes: [], tags: [] }); | ||
}); | ||
|
||
it('merges state and action payload', () => { | ||
expect( | ||
selectedFiltersReducer( | ||
{ | ||
locations: [], | ||
ports: [], | ||
schemes: [], | ||
tags: [], | ||
}, | ||
setSelectedFilters({ | ||
locations: [], | ||
ports: [5601], | ||
schemes: [], | ||
tags: ['prod'], | ||
}) | ||
) | ||
).toEqual({ locations: [], ports: [5601], schemes: [], tags: ['prod'] }); | ||
}); | ||
}); | ||
|
||
describe('getSelectedFilters', () => { | ||
it('returns the state', () => { | ||
expect(selectedFiltersReducer(state, getSelectedFilters())).toEqual(state); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters