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';
|
|
|
|
import { DropdownButton, MenuItem } from 'react-bootstrap';
|
2020-05-07 17:18:10 -04:00
|
|
|
import RefreshIntervalModal from 'src/dashboard/components/RefreshIntervalModal';
|
|
|
|
import URLShortLinkModal from 'src/components/URLShortLinkModal';
|
|
|
|
import HeaderActionsDropdown from 'src/dashboard/components/HeaderActionsDropdown';
|
|
|
|
import SaveModal from 'src/dashboard/components/SaveModal';
|
|
|
|
import CssEditor from 'src/dashboard/components/CssEditor';
|
2018-08-03 12:22:39 -04:00
|
|
|
|
|
|
|
describe('HeaderActionsDropdown', () => {
|
|
|
|
const props = {
|
|
|
|
addSuccessToast: () => {},
|
|
|
|
addDangerToast: () => {},
|
|
|
|
dashboardId: 1,
|
|
|
|
dashboardTitle: 'Title',
|
|
|
|
hasUnsavedChanges: false,
|
2020-05-05 13:10:56 -04:00
|
|
|
customCss: '',
|
2018-08-03 12:22:39 -04:00
|
|
|
onChange: () => {},
|
|
|
|
updateCss: () => {},
|
|
|
|
forceRefreshAllCharts: () => {},
|
|
|
|
startPeriodicRender: () => {},
|
|
|
|
editMode: false,
|
|
|
|
userCanEdit: false,
|
|
|
|
userCanSave: false,
|
|
|
|
layout: {},
|
|
|
|
filters: {},
|
|
|
|
expandedSlices: {},
|
|
|
|
onSave: () => {},
|
|
|
|
};
|
|
|
|
|
|
|
|
function setup(overrideProps) {
|
|
|
|
const wrapper = shallow(
|
|
|
|
<HeaderActionsDropdown {...props} {...overrideProps} />,
|
|
|
|
);
|
|
|
|
return wrapper;
|
|
|
|
}
|
|
|
|
|
|
|
|
describe('readonly-user', () => {
|
|
|
|
const overrideProps = { userCanSave: false };
|
|
|
|
|
|
|
|
it('should render the DropdownButton', () => {
|
|
|
|
const wrapper = setup(overrideProps);
|
2020-07-29 13:53:06 -04:00
|
|
|
expect(wrapper.find(DropdownButton)).toExist();
|
2018-08-03 12:22:39 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should not render the SaveModal', () => {
|
|
|
|
const wrapper = setup(overrideProps);
|
2020-07-29 13:53:06 -04:00
|
|
|
expect(wrapper.find(SaveModal)).not.toExist();
|
2018-08-03 12:22:39 -04:00
|
|
|
});
|
|
|
|
|
2020-09-16 17:20:52 -04:00
|
|
|
it('should render four MenuItems', () => {
|
2018-08-03 12:22:39 -04:00
|
|
|
const wrapper = setup(overrideProps);
|
2020-09-16 17:20:52 -04:00
|
|
|
expect(wrapper.find(MenuItem)).toHaveLength(4);
|
2018-08-03 12:22:39 -04:00
|
|
|
});
|
|
|
|
|
2019-08-13 16:49:39 -04:00
|
|
|
it('should render the RefreshIntervalModal', () => {
|
2018-08-03 12:22:39 -04:00
|
|
|
const wrapper = setup(overrideProps);
|
2020-07-29 13:53:06 -04:00
|
|
|
expect(wrapper.find(RefreshIntervalModal)).toExist();
|
2018-08-03 12:22:39 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should render the URLShortLinkModal', () => {
|
|
|
|
const wrapper = setup(overrideProps);
|
2020-07-29 13:53:06 -04:00
|
|
|
expect(wrapper.find(URLShortLinkModal)).toExist();
|
2018-08-03 12:22:39 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should not render the CssEditor', () => {
|
|
|
|
const wrapper = setup(overrideProps);
|
2020-07-29 13:53:06 -04:00
|
|
|
expect(wrapper.find(CssEditor)).not.toExist();
|
2018-08-03 12:22:39 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('write-user', () => {
|
|
|
|
const overrideProps = { userCanSave: true };
|
|
|
|
|
|
|
|
it('should render the DropdownButton', () => {
|
|
|
|
const wrapper = setup(overrideProps);
|
2020-07-29 13:53:06 -04:00
|
|
|
expect(wrapper.find(DropdownButton)).toExist();
|
2018-08-03 12:22:39 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should render the SaveModal', () => {
|
|
|
|
const wrapper = setup(overrideProps);
|
2020-07-29 13:53:06 -04:00
|
|
|
expect(wrapper.find(SaveModal)).toExist();
|
2018-08-03 12:22:39 -04:00
|
|
|
});
|
|
|
|
|
2020-09-16 17:20:52 -04:00
|
|
|
it('should render four MenuItems', () => {
|
2018-08-03 12:22:39 -04:00
|
|
|
const wrapper = setup(overrideProps);
|
2020-09-16 17:20:52 -04:00
|
|
|
expect(wrapper.find(MenuItem)).toHaveLength(4);
|
2018-08-03 12:22:39 -04:00
|
|
|
});
|
|
|
|
|
2019-08-13 16:49:39 -04:00
|
|
|
it('should render the RefreshIntervalModal', () => {
|
2018-08-03 12:22:39 -04:00
|
|
|
const wrapper = setup(overrideProps);
|
2020-07-29 13:53:06 -04:00
|
|
|
expect(wrapper.find(RefreshIntervalModal)).toExist();
|
2018-08-03 12:22:39 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should render the URLShortLinkModal', () => {
|
|
|
|
const wrapper = setup(overrideProps);
|
2020-07-29 13:53:06 -04:00
|
|
|
expect(wrapper.find(URLShortLinkModal)).toExist();
|
2018-08-03 12:22:39 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should not render the CssEditor', () => {
|
|
|
|
const wrapper = setup(overrideProps);
|
2020-07-29 13:53:06 -04:00
|
|
|
expect(wrapper.find(CssEditor)).not.toExist();
|
2018-08-03 12:22:39 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('write-user-with-edit-mode', () => {
|
|
|
|
const overrideProps = { userCanSave: true, editMode: true };
|
|
|
|
|
|
|
|
it('should render the DropdownButton', () => {
|
|
|
|
const wrapper = setup(overrideProps);
|
2020-07-29 13:53:06 -04:00
|
|
|
expect(wrapper.find(DropdownButton)).toExist();
|
2018-08-03 12:22:39 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should render the SaveModal', () => {
|
|
|
|
const wrapper = setup(overrideProps);
|
2020-07-29 13:53:06 -04:00
|
|
|
expect(wrapper.find(SaveModal)).toExist();
|
2018-08-03 12:22:39 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should render three MenuItems', () => {
|
|
|
|
const wrapper = setup(overrideProps);
|
2018-10-15 16:10:18 -04:00
|
|
|
expect(wrapper.find(MenuItem)).toHaveLength(3);
|
2018-08-03 12:22:39 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should render the RefreshIntervalModal', () => {
|
|
|
|
const wrapper = setup(overrideProps);
|
2020-07-29 13:53:06 -04:00
|
|
|
expect(wrapper.find(RefreshIntervalModal)).toExist();
|
2018-08-03 12:22:39 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should render the URLShortLinkModal', () => {
|
|
|
|
const wrapper = setup(overrideProps);
|
2020-07-29 13:53:06 -04:00
|
|
|
expect(wrapper.find(URLShortLinkModal)).toExist();
|
2018-08-03 12:22:39 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should render the CssEditor', () => {
|
|
|
|
const wrapper = setup(overrideProps);
|
2020-07-29 13:53:06 -04:00
|
|
|
expect(wrapper.find(CssEditor)).toExist();
|
2018-08-03 12:22:39 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|