2019-01-15 18:53:27 -05:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2018-08-03 12:22:39 -04:00
|
|
|
import React from 'react';
|
|
|
|
import { shallow } from 'enzyme';
|
2020-05-07 17:18:10 -04:00
|
|
|
import Header from 'src/dashboard/components/Header';
|
|
|
|
import EditableTitle from 'src/components/EditableTitle';
|
|
|
|
import FaveStar from 'src/components/FaveStar';
|
|
|
|
import PublishedStatus from 'src/dashboard/components/PublishedStatus';
|
|
|
|
import HeaderActionsDropdown from 'src/dashboard/components/HeaderActionsDropdown';
|
|
|
|
import Button from 'src/components/Button';
|
|
|
|
import UndoRedoKeylisteners from 'src/dashboard/components/UndoRedoKeylisteners';
|
2018-08-03 12:22:39 -04:00
|
|
|
|
|
|
|
describe('Header', () => {
|
|
|
|
const props = {
|
|
|
|
addSuccessToast: () => {},
|
|
|
|
addDangerToast: () => {},
|
2020-01-29 18:45:20 -05:00
|
|
|
dashboardInfo: {
|
|
|
|
id: 1,
|
|
|
|
dash_edit_perm: true,
|
|
|
|
dash_save_perm: true,
|
|
|
|
userId: 1,
|
2020-06-03 13:20:56 -04:00
|
|
|
metadata: {},
|
|
|
|
common: {
|
|
|
|
conf: {},
|
|
|
|
},
|
2020-01-29 18:45:20 -05:00
|
|
|
},
|
2018-08-03 12:22:39 -04:00
|
|
|
dashboardTitle: 'title',
|
|
|
|
charts: {},
|
|
|
|
layout: {},
|
|
|
|
filters: {},
|
|
|
|
expandedSlices: {},
|
|
|
|
css: '',
|
|
|
|
isStarred: false,
|
|
|
|
onSave: () => {},
|
|
|
|
onChange: () => {},
|
|
|
|
fetchFaveStar: () => {},
|
|
|
|
fetchCharts: () => {},
|
|
|
|
saveFaveStar: () => {},
|
2019-07-11 02:14:13 -04:00
|
|
|
savePublished: () => {},
|
|
|
|
isPublished: () => {},
|
2018-08-03 12:22:39 -04:00
|
|
|
updateDashboardTitle: () => {},
|
|
|
|
editMode: false,
|
|
|
|
setEditMode: () => {},
|
2019-03-29 09:35:22 -04:00
|
|
|
showBuilderPane: () => {},
|
2018-08-03 12:22:39 -04:00
|
|
|
updateCss: () => {},
|
|
|
|
hasUnsavedChanges: false,
|
|
|
|
maxUndoHistoryExceeded: false,
|
|
|
|
|
|
|
|
// redux
|
|
|
|
onUndo: () => {},
|
|
|
|
onRedo: () => {},
|
|
|
|
undoLength: 0,
|
|
|
|
redoLength: 0,
|
|
|
|
setMaxUndoHistoryExceeded: () => {},
|
|
|
|
maxUndoHistoryToast: () => {},
|
2020-01-14 14:29:59 -05:00
|
|
|
dashboardInfoChanged: () => {},
|
|
|
|
dashboardTitleChanged: () => {},
|
2018-08-03 12:22:39 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
function setup(overrideProps) {
|
|
|
|
const wrapper = shallow(<Header {...props} {...overrideProps} />);
|
|
|
|
return wrapper;
|
|
|
|
}
|
|
|
|
|
|
|
|
describe('read-only-user', () => {
|
|
|
|
const overrideProps = {
|
2020-01-29 18:45:20 -05:00
|
|
|
dashboardInfo: {
|
2020-06-03 13:20:56 -04:00
|
|
|
...props.dashboardInfo,
|
2020-01-29 18:45:20 -05:00
|
|
|
id: 1,
|
|
|
|
dash_edit_perm: false,
|
|
|
|
dash_save_perm: false,
|
|
|
|
userId: 1,
|
|
|
|
},
|
2018-08-03 12:22:39 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
it('should render the EditableTitle', () => {
|
|
|
|
const wrapper = setup(overrideProps);
|
2020-07-29 13:53:06 -04:00
|
|
|
expect(wrapper.find(EditableTitle)).toExist();
|
2018-08-03 12:22:39 -04:00
|
|
|
});
|
|
|
|
|
2019-07-11 02:14:13 -04:00
|
|
|
it('should render the PublishedStatus', () => {
|
|
|
|
const wrapper = setup(overrideProps);
|
2020-07-29 13:53:06 -04:00
|
|
|
expect(wrapper.find(PublishedStatus)).toExist();
|
2019-07-11 02:14:13 -04:00
|
|
|
});
|
|
|
|
|
2018-08-03 12:22:39 -04:00
|
|
|
it('should render the FaveStar', () => {
|
|
|
|
const wrapper = setup(overrideProps);
|
2020-07-29 13:53:06 -04:00
|
|
|
expect(wrapper.find(FaveStar)).toExist();
|
2018-08-03 12:22:39 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should render the HeaderActionsDropdown', () => {
|
|
|
|
const wrapper = setup(overrideProps);
|
2020-07-29 13:53:06 -04:00
|
|
|
expect(wrapper.find(HeaderActionsDropdown)).toExist();
|
2018-08-03 12:22:39 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should not set up undo/redo', () => {
|
|
|
|
const wrapper = setup(overrideProps);
|
2020-07-29 13:53:06 -04:00
|
|
|
expect(wrapper.find(UndoRedoKeylisteners)).not.toExist();
|
2018-08-03 12:22:39 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('write-user', () => {
|
|
|
|
const overrideProps = {
|
|
|
|
editMode: false,
|
2020-01-29 18:45:20 -05:00
|
|
|
dashboardInfo: {
|
2020-06-03 13:20:56 -04:00
|
|
|
...props.dashboardInfo,
|
2020-01-29 18:45:20 -05:00
|
|
|
id: 1,
|
|
|
|
dash_edit_perm: true,
|
|
|
|
dash_save_perm: true,
|
|
|
|
userId: 1,
|
|
|
|
},
|
2018-08-03 12:22:39 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
it('should render the EditableTitle', () => {
|
|
|
|
const wrapper = setup(overrideProps);
|
2020-07-29 13:53:06 -04:00
|
|
|
expect(wrapper.find(EditableTitle)).toExist();
|
2018-08-03 12:22:39 -04:00
|
|
|
});
|
|
|
|
|
2019-07-11 02:14:13 -04:00
|
|
|
it('should render the PublishedStatus', () => {
|
|
|
|
const wrapper = setup(overrideProps);
|
2020-07-29 13:53:06 -04:00
|
|
|
expect(wrapper.find(PublishedStatus)).toExist();
|
2019-07-11 02:14:13 -04:00
|
|
|
});
|
|
|
|
|
2018-08-03 12:22:39 -04:00
|
|
|
it('should render the FaveStar', () => {
|
|
|
|
const wrapper = setup(overrideProps);
|
2020-07-29 13:53:06 -04:00
|
|
|
expect(wrapper.find(FaveStar)).toExist();
|
2018-08-03 12:22:39 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should render the HeaderActionsDropdown', () => {
|
|
|
|
const wrapper = setup(overrideProps);
|
2020-07-29 13:53:06 -04:00
|
|
|
expect(wrapper.find(HeaderActionsDropdown)).toExist();
|
2018-08-03 12:22:39 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should not set up undo/redo', () => {
|
|
|
|
const wrapper = setup(overrideProps);
|
2020-07-29 13:53:06 -04:00
|
|
|
expect(wrapper.find(UndoRedoKeylisteners)).not.toExist();
|
2018-08-03 12:22:39 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('write-user-with-edit-mode', () => {
|
|
|
|
const overrideProps = {
|
|
|
|
editMode: true,
|
2020-01-29 18:45:20 -05:00
|
|
|
dashboardInfo: {
|
2020-06-03 13:20:56 -04:00
|
|
|
...props.dashboardInfo,
|
2020-01-29 18:45:20 -05:00
|
|
|
id: 1,
|
|
|
|
dash_edit_perm: true,
|
|
|
|
dash_save_perm: true,
|
|
|
|
userId: 1,
|
|
|
|
},
|
2018-08-03 12:22:39 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
it('should render the EditableTitle', () => {
|
|
|
|
const wrapper = setup(overrideProps);
|
2020-07-29 13:53:06 -04:00
|
|
|
expect(wrapper.find(EditableTitle)).toExist();
|
2018-08-03 12:22:39 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should render the FaveStar', () => {
|
|
|
|
const wrapper = setup(overrideProps);
|
2020-07-29 13:53:06 -04:00
|
|
|
expect(wrapper.find(FaveStar)).toExist();
|
2018-08-03 12:22:39 -04:00
|
|
|
});
|
|
|
|
|
2019-07-11 02:14:13 -04:00
|
|
|
it('should render the PublishedStatus', () => {
|
|
|
|
const wrapper = setup(overrideProps);
|
2020-07-29 13:53:06 -04:00
|
|
|
expect(wrapper.find(PublishedStatus)).toExist();
|
2019-07-11 02:14:13 -04:00
|
|
|
});
|
|
|
|
|
2018-08-03 12:22:39 -04:00
|
|
|
it('should render the HeaderActionsDropdown', () => {
|
|
|
|
const wrapper = setup(overrideProps);
|
2020-07-29 13:53:06 -04:00
|
|
|
expect(wrapper.find(HeaderActionsDropdown)).toExist();
|
2018-08-03 12:22:39 -04:00
|
|
|
});
|
|
|
|
|
2019-03-29 09:35:22 -04:00
|
|
|
it('should render five Buttons', () => {
|
2018-08-03 12:22:39 -04:00
|
|
|
const wrapper = setup(overrideProps);
|
2020-08-05 21:53:53 -04:00
|
|
|
expect(wrapper.find(Button)).toHaveLength(4);
|
2018-08-03 12:22:39 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should set up undo/redo', () => {
|
|
|
|
const wrapper = setup(overrideProps);
|
2020-07-29 13:53:06 -04:00
|
|
|
expect(wrapper.find(UndoRedoKeylisteners)).toExist();
|
2018-08-03 12:22:39 -04:00
|
|
|
});
|
|
|
|
});
|
2020-01-29 18:45:20 -05:00
|
|
|
|
|
|
|
describe('logged-out-user', () => {
|
|
|
|
const overrideProps = {
|
|
|
|
dashboardInfo: {
|
2020-06-03 13:20:56 -04:00
|
|
|
...props.dashboardInfo,
|
2020-01-29 18:45:20 -05:00
|
|
|
id: 1,
|
|
|
|
dash_edit_perm: false,
|
|
|
|
dash_save_perm: false,
|
|
|
|
userId: null,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
it('should render the EditableTitle', () => {
|
|
|
|
const wrapper = setup(overrideProps);
|
2020-07-29 13:53:06 -04:00
|
|
|
expect(wrapper.find(EditableTitle)).toExist();
|
2020-01-29 18:45:20 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should render the PublishedStatus', () => {
|
|
|
|
const wrapper = setup(overrideProps);
|
2020-07-29 13:53:06 -04:00
|
|
|
expect(wrapper.find(PublishedStatus)).toExist();
|
2020-01-29 18:45:20 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should not render the FaveStar', () => {
|
|
|
|
const wrapper = setup(overrideProps);
|
2020-07-29 13:53:06 -04:00
|
|
|
expect(wrapper.find(FaveStar)).not.toExist();
|
2020-01-29 18:45:20 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should render the HeaderActionsDropdown', () => {
|
|
|
|
const wrapper = setup(overrideProps);
|
2020-07-29 13:53:06 -04:00
|
|
|
expect(wrapper.find(HeaderActionsDropdown)).toExist();
|
2020-01-29 18:45:20 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should not set up undo/redo', () => {
|
|
|
|
const wrapper = setup(overrideProps);
|
2020-07-29 13:53:06 -04:00
|
|
|
expect(wrapper.find(UndoRedoKeylisteners)).not.toExist();
|
2020-01-29 18:45:20 -05:00
|
|
|
});
|
|
|
|
});
|
2018-08-03 12:22:39 -04:00
|
|
|
});
|