chore: Moves messageToasts to the components folder (#14431)

* chore: Moves messageToasts to the components folder

* Rebases
This commit is contained in:
Michael S. Molina
2021-09-22 07:44:54 -03:00
committed by GitHub
parent b6d78bf4f2
commit 9b17e86b44
83 changed files with 179 additions and 237 deletions

View File

@@ -40,7 +40,7 @@ import {
import { setUnsavedChanges } from 'src/dashboard/actions/dashboardState';
import * as dashboardFilters from 'src/dashboard/actions/dashboardFilters';
import { ADD_TOAST } from 'src/messageToasts/actions';
import { ADD_TOAST } from 'src/components/MessageToasts/actions';
import {
DASHBOARD_GRID_TYPE,

View File

@@ -1,30 +0,0 @@
{
"extends": "prettier",
"plugins": ["prettier"],
"rules": {
"prefer-template": 2,
"new-cap": 2,
"no-restricted-syntax": 2,
"guard-for-in": 2,
"prefer-arrow-callback": 2,
"func-names": 2,
"react/jsx-no-bind": 2,
"no-confusing-arrow": 2,
"jsx-a11y/no-static-element-interactions": 2,
"jsx-a11y/anchor-has-content": 2,
"react/require-default-props": 2,
"no-plusplus": 2,
"no-mixed-operators": 0,
"no-continue": 2,
"no-bitwise": 2,
"no-multi-assign": 2,
"no-restricted-properties": 2,
"no-prototype-builtins": 2,
"class-methods-use-this": 2,
"import/no-named-as-default": 2,
"react/no-unescaped-entities": 2,
"react/no-string-refs": 2,
"react/jsx-indent": 0,
"prettier/prettier": "error"
}
}

View File

@@ -1,52 +0,0 @@
/**
* 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 Toast from 'src/messageToasts/components/Toast';
import ToastPresenter from 'src/messageToasts/components/ToastPresenter';
import mockMessageToasts from '../mockMessageToasts';
describe('ToastPresenter', () => {
const props = {
toasts: mockMessageToasts,
removeToast() {},
};
function setup(overrideProps) {
const wrapper = shallow(<ToastPresenter {...props} {...overrideProps} />);
return wrapper;
}
it('should render a div with id toast-presenter', () => {
const wrapper = setup();
expect(wrapper.find('#toast-presenter')).toExist();
});
it('should render a Toast for each toast object', () => {
const wrapper = setup();
expect(wrapper.find(Toast)).toHaveLength(props.toasts.length);
});
it('should pass removeToast to the Toast component', () => {
const removeToast = () => {};
const wrapper = setup({ removeToast });
expect(wrapper.find(Toast).first().prop('onCloseToast')).toBe(removeToast);
});
});

View File

@@ -1,62 +0,0 @@
/**
* 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 { mount } from 'enzyme';
import { ThemeProvider, supersetTheme } from '@superset-ui/core';
import Toast from 'src/messageToasts/components/Toast';
import { act } from 'react-dom/test-utils';
import mockMessageToasts from '../mockMessageToasts';
const props = {
toast: mockMessageToasts[0],
onCloseToast() {},
};
const setup = overrideProps =>
mount(<Toast {...props} {...overrideProps} />, {
wrappingComponent: ThemeProvider,
wrappingComponentProps: { theme: supersetTheme },
});
describe('Toast', () => {
it('should render', () => {
const wrapper = setup();
expect(wrapper.find('[data-test="toast-container"]')).toExist();
});
it('should render toastText within the div', () => {
const wrapper = setup();
const container = wrapper.find('[data-test="toast-container"]');
expect(container.hostNodes().childAt(1).text()).toBe(props.toast.text);
});
it('should call onCloseToast upon toast dismissal', async () =>
act(
() =>
new Promise(done => {
const onCloseToast = id => {
expect(id).toBe(props.toast.id);
done();
};
const wrapper = setup({ onCloseToast });
wrapper.find('[data-test="close-button"]').props().onClick();
}),
));
});

View File

@@ -1,24 +0,0 @@
/**
* 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 { ToastType } from 'src/messageToasts/constants';
export default [
{ id: 'info_id', toastType: ToastType.INFO, text: 'info toast' },
{ id: 'danger_id', toastType: ToastType.DANGER, text: 'danger toast' },
];

View File

@@ -1,44 +0,0 @@
/**
* 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 { ADD_TOAST, REMOVE_TOAST } from 'src/messageToasts/actions';
import messageToastsReducer from 'src/messageToasts/reducers';
describe('messageToasts reducer', () => {
it('should return initial state', () => {
expect(messageToastsReducer(undefined, {})).toEqual([]);
});
it('should add a toast', () => {
expect(
messageToastsReducer([], {
type: ADD_TOAST,
payload: { text: 'test', id: 'id', type: 'test_type' },
}),
).toEqual([{ text: 'test', id: 'id', type: 'test_type' }]);
});
it('should remove a toast', () => {
expect(
messageToastsReducer([{ id: 'id' }, { id: 'id2' }], {
type: REMOVE_TOAST,
payload: { id: 'id' },
}),
).toEqual([{ id: 'id2' }]);
});
});

View File

@@ -1,49 +0,0 @@
/**
* 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 { ToastType } from 'src/messageToasts/constants';
import getToastsFromPyFlashMessages from 'src/messageToasts/utils/getToastsFromPyFlashMessages';
describe('getToastsFromPyFlashMessages', () => {
it('should return an info toast', () => {
const toast = getToastsFromPyFlashMessages([['info', 'info test']])[0];
expect(toast).toMatchObject({
toastType: ToastType.INFO,
text: 'info test',
});
});
it('should return a success toast', () => {
const toast = getToastsFromPyFlashMessages([
['success', 'success test'],
])[0];
expect(toast).toMatchObject({
toastType: ToastType.SUCCESS,
text: 'success test',
});
});
it('should return a danger toast', () => {
const toast = getToastsFromPyFlashMessages([['danger', 'danger test']])[0];
expect(toast).toMatchObject({
toastType: ToastType.DANGER,
text: 'danger test',
});
});
});

View File

@@ -23,7 +23,7 @@ import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import shortid from 'shortid';
import * as featureFlags from 'src/featureFlags';
import { ADD_TOAST } from 'src/messageToasts/actions';
import { ADD_TOAST } from 'src/components/MessageToasts/actions';
import * as actions from 'src/SqlLab/actions/sqlLab';
import { defaultQueryEditor, query } from '../fixtures';