-
Notifications
You must be signed in to change notification settings - Fork 14.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Add database search in available charts on dashboard. (#19244)
* add database search * resolve lint issue * add test for sliceEntities actions * fix lint issue * add licence into test * fix pipeline broken * fix sort by recent * resolve comment
- Loading branch information
1 parent
4bfa622
commit 9622520
Showing
5 changed files
with
264 additions
and
87 deletions.
There are no files selected for viewing
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
102 changes: 102 additions & 0 deletions
102
superset-frontend/src/dashboard/actions/sliceEntities.test.js
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,102 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
import sinon from 'sinon'; | ||
import { SupersetClient } from '@superset-ui/core'; | ||
|
||
import { | ||
FETCH_ALL_SLICES_STARTED, | ||
fetchSortedSlices, | ||
fetchFilteredSlices, | ||
fetchAllSlices, | ||
} from './sliceEntities'; | ||
|
||
describe('slice entity actions', () => { | ||
const mockState = { | ||
sliceEntities: { slices: {} }, | ||
isLoading: true, | ||
errorMessage: null, | ||
lastUpdated: 0, | ||
}; | ||
|
||
function setup(stateOverrides) { | ||
const state = { ...mockState, ...stateOverrides }; | ||
const getState = sinon.spy(() => state); | ||
const dispatch = sinon.spy(); | ||
|
||
return { getState, dispatch, state }; | ||
} | ||
|
||
let spy; | ||
|
||
beforeEach(() => { | ||
spy = sinon.spy(SupersetClient); | ||
}); | ||
|
||
afterEach(() => { | ||
sinon.restore(); | ||
}); | ||
|
||
describe('fetchSortedSlices', () => { | ||
it('should dispatch an fetchAllSlicesStarted action', async () => { | ||
const { dispatch } = setup(); | ||
const thunk1 = fetchSortedSlices('userId', false, 'orderColumn'); | ||
await thunk1(dispatch); | ||
expect(dispatch.getCall(0).args[0]).toEqual({ | ||
type: FETCH_ALL_SLICES_STARTED, | ||
}); | ||
expect(spy.get.callCount).toBe(1); | ||
}); | ||
}); | ||
|
||
describe('fetchFilteredSlices', () => { | ||
it('should dispatch an fetchAllSlicesStarted action', async () => { | ||
const { dispatch, getState } = setup(); | ||
const thunk1 = fetchFilteredSlices('userId', false, 'filter_value'); | ||
await thunk1(dispatch, getState); | ||
expect(dispatch.getCall(0).args[0]).toEqual({ | ||
type: FETCH_ALL_SLICES_STARTED, | ||
}); | ||
expect(spy.get.callCount).toBe(1); | ||
}); | ||
}); | ||
|
||
describe('fetchAllSlices', () => { | ||
it('should not trigger fetchSlices when sliceEntities lastUpdate is not 0', async () => { | ||
const { dispatch, getState } = setup({ | ||
sliceEntities: { slices: {}, lastUpdated: 1 }, | ||
}); | ||
|
||
const thunk1 = fetchAllSlices('userId', false, 'filter_value'); | ||
await thunk1(dispatch, getState); | ||
|
||
expect(spy.get.callCount).toBe(0); | ||
}); | ||
|
||
it('should trigger fetchSlices when sliceEntities lastUpdate is 0', async () => { | ||
const { dispatch, getState } = setup({ | ||
sliceEntities: { slices: {}, lastUpdated: 0 }, | ||
}); | ||
|
||
const thunk1 = fetchAllSlices('userId', false, 'filter_value'); | ||
await thunk1(dispatch, getState); | ||
|
||
expect(spy.get.callCount).toBe(1); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.