-
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.
feat(dashboard): direct link to single chart/tab/header in dashboard (#…
…6964) * direct display for pre-selected tab * update parents * add AnchorLink component * add unit tests
- Loading branch information
Grace Guo
authored
Apr 9, 2019
1 parent
139f299
commit c50e6bc
Showing
33 changed files
with
813 additions
and
26 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
superset/assets/spec/javascripts/components/AnchorLink_spec.jsx
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,63 @@ | ||
/** | ||
* 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 React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import sinon from 'sinon'; | ||
|
||
import AnchorLink from '../../../src/components/AnchorLink'; | ||
import URLShortLinkButton from '../../../src/components/URLShortLinkButton'; | ||
|
||
describe('AnchorLink', () => { | ||
const props = { | ||
anchorLinkId: 'CHART-123', | ||
}; | ||
|
||
it('should scroll the AnchorLink into view upon mount', () => { | ||
const callback = sinon.spy(); | ||
const clock = sinon.useFakeTimers(); | ||
const stub = sinon.stub(document, 'getElementById').returns({ | ||
scrollIntoView: callback, | ||
}); | ||
|
||
const wrapper = shallow(<AnchorLink {...props} />); | ||
wrapper.instance().getLocationHash = () => (props.anchorLinkId); | ||
wrapper.update(); | ||
|
||
wrapper.instance().componentDidMount(); | ||
clock.tick(2000); | ||
expect(callback.callCount).toEqual(1); | ||
stub.restore(); | ||
}); | ||
|
||
it('should render anchor link with id', () => { | ||
const wrapper = shallow(<AnchorLink {...props} />); | ||
expect(wrapper.find(`#${props.anchorLinkId}`)).toHaveLength(1); | ||
expect(wrapper.find(URLShortLinkButton)).toHaveLength(0); | ||
}); | ||
|
||
it('should render URLShortLinkButton', () => { | ||
const wrapper = shallow(<AnchorLink {...props} showShortLinkButton />); | ||
expect(wrapper.find(URLShortLinkButton)).toHaveLength(1); | ||
expect(wrapper.find(URLShortLinkButton).prop('placement')).toBe('right'); | ||
|
||
const targetUrl = wrapper.find(URLShortLinkButton).prop('url'); | ||
const hash = targetUrl.slice(targetUrl.indexOf('#') + 1); | ||
expect(hash).toBe(props.anchorLinkId); | ||
}); | ||
}); |
100 changes: 100 additions & 0 deletions
100
superset/assets/spec/javascripts/dashboard/actions/dashboardState_spec.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,100 @@ | ||
/** | ||
* 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/connection'; | ||
|
||
import { saveDashboardRequest } from '../../../../src/dashboard/actions/dashboardState'; | ||
import { UPDATE_COMPONENTS_PARENTS_LIST } from '../../../../src/dashboard/actions/dashboardLayout'; | ||
import mockDashboardData from '../fixtures/mockDashboardData'; | ||
import { DASHBOARD_GRID_ID } from '../../../../src/dashboard/util/constants'; | ||
|
||
describe('dashboardState actions', () => { | ||
const mockState = { | ||
dashboardState: { | ||
hasUnsavedChanges: true, | ||
}, | ||
dashboardInfo: {}, | ||
dashboardLayout: { | ||
past: [], | ||
present: mockDashboardData.positions, | ||
future: {}, | ||
}, | ||
}; | ||
const newDashboardData = mockDashboardData; | ||
|
||
let postStub; | ||
beforeEach(() => { | ||
postStub = sinon | ||
.stub(SupersetClient, 'post') | ||
.resolves('the value you want to return'); | ||
}); | ||
afterEach(() => { | ||
postStub.restore(); | ||
}); | ||
|
||
function setup(stateOverrides) { | ||
const state = { ...mockState, ...stateOverrides }; | ||
const getState = sinon.spy(() => state); | ||
const dispatch = sinon.stub(); | ||
return { getState, dispatch, state }; | ||
} | ||
|
||
describe('saveDashboardRequest', () => { | ||
it('should dispatch UPDATE_COMPONENTS_PARENTS_LIST action', () => { | ||
const { getState, dispatch } = setup({ | ||
dashboardState: { hasUnsavedChanges: false }, | ||
}); | ||
const thunk = saveDashboardRequest(newDashboardData, 1, 'save_dash'); | ||
thunk(dispatch, getState); | ||
expect(dispatch.callCount).toBe(1); | ||
expect(dispatch.getCall(0).args[0].type).toBe( | ||
UPDATE_COMPONENTS_PARENTS_LIST, | ||
); | ||
}); | ||
|
||
it('should post dashboard data with updated redux state', () => { | ||
const { getState, dispatch } = setup({ | ||
dashboardState: { hasUnsavedChanges: false }, | ||
}); | ||
|
||
// start with mockDashboardData, it didn't have parents attr | ||
expect( | ||
newDashboardData.positions[DASHBOARD_GRID_ID].parents, | ||
).not.toBeDefined(); | ||
|
||
// mock redux work: dispatch an event, cause modify redux state | ||
const mockParentsList = ['ROOT_ID']; | ||
dispatch.callsFake(() => { | ||
mockState.dashboardLayout.present[ | ||
DASHBOARD_GRID_ID | ||
].parents = mockParentsList; | ||
}); | ||
|
||
// call saveDashboardRequest, it should post dashboard data with updated | ||
// layout object (with parents attribute) | ||
const thunk = saveDashboardRequest(newDashboardData, 1, 'save_dash'); | ||
thunk(dispatch, getState); | ||
expect(postStub.callCount).toBe(1); | ||
const postPayload = postStub.getCall(0).args[0].postPayload; | ||
expect(postPayload.data.positions[DASHBOARD_GRID_ID].parents).toBe( | ||
mockParentsList, | ||
); | ||
}); | ||
}); | ||
}); |
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
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
28 changes: 28 additions & 0 deletions
28
superset/assets/spec/javascripts/dashboard/fixtures/mockDashboardData.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,28 @@ | ||
/** | ||
* 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 { dashboardLayout } from './mockDashboardLayout'; | ||
|
||
// mock the object to be posted to save_dash or copy_dash API | ||
export default { | ||
css: '', | ||
dashboard_title: 'Test 1', | ||
default_filters: {}, | ||
expanded_slices: {}, | ||
positions: dashboardLayout.present, | ||
}; |
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
Oops, something went wrong.