Fix tests errors and warnings - iteration 3 (#12212) (#12219)

This commit is contained in:
Michael S. Molina 2021-01-26 04:40:59 -03:00 committed by GitHub
parent 22d52eadb2
commit 6bf5d2c06d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 62 additions and 5 deletions

View File

@ -0,0 +1,34 @@
/**
* 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.
*/
class Worker {
url: string;
onMessage: Function;
constructor(stringUrl: string) {
this.url = stringUrl;
this.onMessage = () => {};
}
postMessage(msg: string) {
this.onMessage(msg);
}
}
export { Worker };

View File

@ -24,7 +24,7 @@ import jQuery from 'jquery';
import { configure } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import { configure as configureTranslation } from '@superset-ui/core';
import { Worker } from './Worker';
import setupSupersetClient from './setupSupersetClient';
configure({ adapter: new Adapter() });
@ -42,10 +42,12 @@ if (defaultView != null) {
}
const g = global as any;
g.window = g.window || {};
g.window.location = { href: 'about:blank' };
g.window.performance = { now: () => new Date().getTime() };
g.window.Worker = Worker;
g.URL.createObjectURL = () => '';
Object.defineProperty(window, 'matchMedia', {
writable: true,
value: jest.fn().mockImplementation(query => ({

View File

@ -24,6 +24,9 @@ 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';
import fetchMock from 'fetch-mock';
fetchMock.get('glob:*/csstemplateasyncmodelview/api/read', {});
describe('HeaderActionsDropdown', () => {
const props = {
@ -50,6 +53,7 @@ describe('HeaderActionsDropdown', () => {
updateCss: () => {},
userCanEdit: false,
userCanSave: false,
lastModifiedTime: 0,
};
function setup(overrideProps) {

View File

@ -30,6 +30,7 @@ describe('Header', () => {
const props = {
addSuccessToast: () => {},
addDangerToast: () => {},
addWarningToast: () => {},
dashboardInfo: {
id: 1,
dash_edit_perm: true,
@ -46,7 +47,12 @@ describe('Header', () => {
filters: {},
expandedSlices: {},
css: '',
customCss: '',
isStarred: false,
isLoading: false,
lastModifiedTime: 0,
refreshFrequency: 0,
shouldPersistRefreshFrequency: false,
onSave: () => {},
onChange: () => {},
fetchFaveStar: () => {},
@ -59,6 +65,9 @@ describe('Header', () => {
setEditMode: () => {},
showBuilderPane: () => {},
updateCss: () => {},
setColorSchemeAndUnsavedChanges: () => {},
logEvent: () => {},
setRefreshFrequency: () => {},
hasUnsavedChanges: false,
maxUndoHistoryExceeded: false,

View File

@ -21,11 +21,12 @@ import React from 'react';
import { styledMount as mount } from 'spec/helpers/theming';
import sinon from 'sinon';
import ReactMarkdown from 'react-markdown';
import { act } from 'react-dom/test-utils';
import { MarkdownEditor } from 'src/components/AsyncAceEditor';
import Markdown from 'src/dashboard/components/gridComponents/Markdown';
import MarkdownModeDropdown from 'src/dashboard/components/menu/MarkdownModeDropdown';
import DeleteComponentButton from 'src/dashboard/components/DeleteComponentButton';
import waitForComponentToPaint from 'spec/helpers/waitForComponentToPaint';
import DragDroppable from 'src/dashboard/components/dnd/DragDroppable';
import WithPopoverMenu from 'src/dashboard/components/menu/WithPopoverMenu';
import ResizableContainer from 'src/dashboard/components/resizable/ResizableContainer';
@ -45,6 +46,8 @@ describe('Markdown', () => {
editMode: false,
availableColumnCount: 12,
columnWidth: 50,
redoLength: 0,
undoLength: 0,
onResizeStart() {},
onResize() {},
onResizeStop() {},
@ -52,6 +55,7 @@ describe('Markdown', () => {
updateComponents() {},
deleteComponent() {},
logEvent() {},
addDangerToast() {},
};
function setup(overrideProps) {
@ -109,11 +113,14 @@ describe('Markdown', () => {
expect(wrapper.find(ReactMarkdown)).toExist();
});
it('should render an AceEditor when focused and editMode=true and editorMode=edit', () => {
it('should render an AceEditor when focused and editMode=true and editorMode=edit', async () => {
const wrapper = setup({ editMode: true });
expect(wrapper.find(MarkdownEditor)).not.toExist();
expect(wrapper.find(ReactMarkdown)).toExist();
wrapper.find(WithPopoverMenu).simulate('click'); // focus + edit
act(() => {
wrapper.find(WithPopoverMenu).simulate('click'); // focus + edit
});
await waitForComponentToPaint(wrapper);
expect(wrapper.find(MarkdownEditor)).toExist();
expect(wrapper.find(ReactMarkdown)).not.toExist();
});

View File

@ -147,6 +147,7 @@ describe('AnnotationList', () => {
act(() => {
wrapper.find('button').last().props().onClick();
});
await waitForComponentToPaint(wrapper);
});
it('shows/hides bulk actions when bulk actions is clicked', async () => {