refactor: typing for explore Control and messageToasts (#11416)

This commit is contained in:
Jesse Yang
2020-10-24 21:40:36 -07:00
committed by GitHub
parent d02a61f21c
commit 8aecffd83b
19 changed files with 226 additions and 265 deletions

View File

@@ -40,7 +40,7 @@ import {
import { setUnsavedChanges } from 'src/dashboard/actions/dashboardState';
import * as dashboardFilters from 'src/dashboard/actions/dashboardFilters';
import { addWarningToast, ADD_TOAST } from 'src/messageToasts/actions';
import { ADD_TOAST } from 'src/messageToasts/actions';
import {
DASHBOARD_GRID_TYPE,
@@ -349,24 +349,27 @@ describe('dashboardLayout actions', () => {
const { getState, dispatch } = setup({
dashboardLayout: {
present: {
source: { type: ROW_TYPE },
destination: { type: ROW_TYPE, children: ['rowChild'] },
dragging: { type: CHART_TYPE, meta: { width: 1 } },
rowChild: { type: CHART_TYPE, meta: { width: 12 } },
source: { id: 'source', type: ROW_TYPE, children: ['dragging'] },
destination: {
id: 'destination',
type: ROW_TYPE,
children: ['rowChild'],
},
dragging: { id: 'dragging', type: CHART_TYPE, meta: { width: 1 } },
rowChild: { id: 'rowChild', type: CHART_TYPE, meta: { width: 12 } },
},
},
});
const dropResult = {
source: { id: 'source', type: ROW_TYPE },
destination: { id: 'destination', type: ROW_TYPE },
dragging: { id: 'dragging', type: CHART_TYPE },
dragging: { id: 'dragging', type: CHART_TYPE, meta: { width: 1 } },
};
const thunk = handleComponentDrop(dropResult);
thunk(dispatch, getState);
expect(dispatch.getCall(0).args[0].type).toEqual(
addWarningToast('').type,
);
expect(dispatch.getCall(0).args[0].type).toEqual(ADD_TOAST);
expect(dispatch.callCount).toBe(1);
});
@@ -479,13 +482,9 @@ describe('dashboardLayout actions', () => {
},
};
const thunk1 = handleComponentDrop(dropResult);
thunk1(dispatch, getState);
handleComponentDrop(dropResult)(dispatch, getState);
const thunk2 = dispatch.getCall(0).args[0];
thunk2(dispatch, getState);
expect(dispatch.getCall(1).args[0].type).toEqual(ADD_TOAST);
expect(dispatch.getCall(0).args[0].type).toEqual(ADD_TOAST);
});
});

View File

@@ -16,9 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
import { INFO_TOAST, DANGER_TOAST } from 'src/messageToasts/constants';
import { ToastType } from 'src/messageToasts/constants';
export default [
{ id: 'info_id', toastType: INFO_TOAST, text: 'info toast' },
{ id: 'danger_id', toastType: DANGER_TOAST, text: 'danger toast' },
{ id: 'info_id', toastType: ToastType.INFO, text: 'info toast' },
{ id: 'danger_id', toastType: ToastType.DANGER, text: 'danger toast' },
];

View File

@@ -16,18 +16,17 @@
* specific language governing permissions and limitations
* under the License.
*/
import {
DANGER_TOAST,
INFO_TOAST,
SUCCESS_TOAST,
} from 'src/messageToasts/constants';
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: INFO_TOAST, text: 'info test' });
expect(toast).toMatchObject({
toastType: ToastType.INFO,
text: 'info test',
});
});
it('should return a success toast', () => {
@@ -35,7 +34,7 @@ describe('getToastsFromPyFlashMessages', () => {
['success', 'success test'],
])[0];
expect(toast).toMatchObject({
toastType: SUCCESS_TOAST,
toastType: ToastType.SUCCESS,
text: 'success test',
});
});
@@ -43,7 +42,7 @@ describe('getToastsFromPyFlashMessages', () => {
it('should return a danger toast', () => {
const toast = getToastsFromPyFlashMessages([['danger', 'danger test']])[0];
expect(toast).toMatchObject({
toastType: DANGER_TOAST,
toastType: ToastType.DANGER,
text: 'danger test',
});
});