diff --git a/superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.tsx b/superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.tsx index 03d993288f4ff..347858f039eaf 100644 --- a/superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.tsx +++ b/superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.tsx @@ -34,7 +34,7 @@ import { Global } from '@emotion/react'; import { useDispatch, useSelector } from 'react-redux'; import ErrorBoundary from 'src/components/ErrorBoundary'; import BuilderComponentPane from 'src/dashboard/components/BuilderComponentPane'; -import DashboardHeader from 'src/dashboard/containers/DashboardHeader'; +import DashboardHeader from 'src/dashboard/components/Header'; import Icons from 'src/components/Icons'; import IconButton from 'src/dashboard/components/IconButton'; import { Droppable } from 'src/dashboard/components/dnd/DragDroppable'; diff --git a/superset-frontend/src/dashboard/components/Header/Header.test.tsx b/superset-frontend/src/dashboard/components/Header/Header.test.tsx index 9a2c414d00f7a..0c679f4415d34 100644 --- a/superset-frontend/src/dashboard/components/Header/Header.test.tsx +++ b/superset-frontend/src/dashboard/components/Header/Header.test.tsx @@ -16,19 +16,17 @@ * specific language governing permissions and limitations * under the License. */ +import * as redux from 'redux'; import { render, screen, fireEvent } from 'spec/helpers/testing-library'; import userEvent from '@testing-library/user-event'; import fetchMock from 'fetch-mock'; -import { getExtensionsRegistry } from '@superset-ui/core'; +import { getExtensionsRegistry, JsonObject } from '@superset-ui/core'; import setupExtensions from 'src/setup/setupExtensions'; import getOwnerName from 'src/utils/getOwnerName'; -import { HeaderProps } from './types'; import Header from '.'; +import { DASHBOARD_HEADER_ID } from '../../util/constants'; -const createProps = () => ({ - addSuccessToast: jest.fn(), - addDangerToast: jest.fn(), - addWarningToast: jest.fn(), +const initialState = { dashboardInfo: { id: 1, dash_edit_perm: false, @@ -69,74 +67,69 @@ const createProps = () => ({ userId: 1, username: 'admin', }, - reports: {}, - dashboardTitle: 'Dashboard Title', + dashboardState: { + sliceIds: [], + expandedSlices: {}, + refreshFrequency: 0, + shouldPersistRefreshFrequency: false, + css: '', + isStarred: false, + isPublished: false, + hasUnsavedChanges: false, + maxUndoHistoryExceeded: false, + editMode: false, + lastModifiedTime: 0, + }, charts: {}, - layout: {}, - expandedSlices: {}, - css: '', - customCss: '', - isStarred: false, - isLoading: false, - lastModifiedTime: 0, - refreshFrequency: 0, - shouldPersistRefreshFrequency: false, - onSave: jest.fn(), - onChange: jest.fn(), - fetchFaveStar: jest.fn(), - fetchCharts: jest.fn(), - onRefresh: jest.fn(), - saveFaveStar: jest.fn(), - savePublished: jest.fn(), - isPublished: false, - updateDashboardTitle: jest.fn(), - editMode: false, - setEditMode: jest.fn(), - showBuilderPane: jest.fn(), - updateCss: jest.fn(), - setColorScheme: jest.fn(), - setUnsavedChanges: jest.fn(), - logEvent: jest.fn(), - setRefreshFrequency: jest.fn(), - hasUnsavedChanges: false, - maxUndoHistoryExceeded: false, - onUndo: jest.fn(), - onRedo: jest.fn(), - undoLength: 0, - redoLength: 0, - setMaxUndoHistoryExceeded: jest.fn(), - maxUndoHistoryToast: jest.fn(), - dashboardInfoChanged: jest.fn(), - dashboardTitleChanged: jest.fn(), - showMenuDropdown: true, -}); -const props = createProps(); -const editableProps = { - ...props, - editMode: true, + dashboardLayout: { + present: { + [DASHBOARD_HEADER_ID]: { + meta: { + text: 'Dashboard Title', + }, + }, + }, + past: [], + future: [], + }, +}; + +const editableState = { + dashboardState: { + ...initialState.dashboardState, + editMode: true, + }, dashboardInfo: { - ...props.dashboardInfo, + ...initialState.dashboardInfo, dash_edit_perm: true, dash_save_perm: true, }, }; -const undoProps = { - ...editableProps, - undoLength: 1, + +const undoState = { + ...editableState, + dashboardLayout: { + ...initialState.dashboardLayout, + past: [{}], + }, }; -const redoProps = { - ...editableProps, - redoLength: 1, + +const redoState = { + ...editableState, + dashboardLayout: { + ...initialState.dashboardLayout, + future: [{}], + }, }; fetchMock.get('glob:*/csstemplateasyncmodelview/api/read', {}); -function setup(props: HeaderProps, initialState = {}) { +function setup(overrideState: JsonObject = {}) { return render(