From 6bf5d2c06dcdd981b3391223526d1aa6d979edcd Mon Sep 17 00:00:00 2001 From: "Michael S. Molina" <70410625+michael-s-molina@users.noreply.github.com> Date: Tue, 26 Jan 2021 04:40:59 -0300 Subject: [PATCH] Fix tests errors and warnings - iteration 3 (#12212) (#12219) --- superset-frontend/spec/helpers/Worker.ts | 34 +++++++++++++++++++ superset-frontend/spec/helpers/shim.ts | 6 ++-- .../components/HeaderActionsDropdown_spec.jsx | 4 +++ .../dashboard/components/Header_spec.jsx | 9 +++++ .../gridComponents/Markdown_spec.jsx | 13 +++++-- .../CRUD/annotation/AnnotationList_spec.jsx | 1 + 6 files changed, 62 insertions(+), 5 deletions(-) create mode 100644 superset-frontend/spec/helpers/Worker.ts diff --git a/superset-frontend/spec/helpers/Worker.ts b/superset-frontend/spec/helpers/Worker.ts new file mode 100644 index 0000000000..f7da6b9e43 --- /dev/null +++ b/superset-frontend/spec/helpers/Worker.ts @@ -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 }; diff --git a/superset-frontend/spec/helpers/shim.ts b/superset-frontend/spec/helpers/shim.ts index 29f7d18cdf..32f3f27fb8 100644 --- a/superset-frontend/spec/helpers/shim.ts +++ b/superset-frontend/spec/helpers/shim.ts @@ -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 => ({ diff --git a/superset-frontend/spec/javascripts/dashboard/components/HeaderActionsDropdown_spec.jsx b/superset-frontend/spec/javascripts/dashboard/components/HeaderActionsDropdown_spec.jsx index 4d6262981d..17bc7bc3c4 100644 --- a/superset-frontend/spec/javascripts/dashboard/components/HeaderActionsDropdown_spec.jsx +++ b/superset-frontend/spec/javascripts/dashboard/components/HeaderActionsDropdown_spec.jsx @@ -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) { diff --git a/superset-frontend/spec/javascripts/dashboard/components/Header_spec.jsx b/superset-frontend/spec/javascripts/dashboard/components/Header_spec.jsx index 96aa8121b9..5e040dd5b6 100644 --- a/superset-frontend/spec/javascripts/dashboard/components/Header_spec.jsx +++ b/superset-frontend/spec/javascripts/dashboard/components/Header_spec.jsx @@ -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, diff --git a/superset-frontend/spec/javascripts/dashboard/components/gridComponents/Markdown_spec.jsx b/superset-frontend/spec/javascripts/dashboard/components/gridComponents/Markdown_spec.jsx index 04d5ad6759..22c7611bc5 100644 --- a/superset-frontend/spec/javascripts/dashboard/components/gridComponents/Markdown_spec.jsx +++ b/superset-frontend/spec/javascripts/dashboard/components/gridComponents/Markdown_spec.jsx @@ -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(); }); diff --git a/superset-frontend/spec/javascripts/views/CRUD/annotation/AnnotationList_spec.jsx b/superset-frontend/spec/javascripts/views/CRUD/annotation/AnnotationList_spec.jsx index 84b9516b04..4bc664432c 100644 --- a/superset-frontend/spec/javascripts/views/CRUD/annotation/AnnotationList_spec.jsx +++ b/superset-frontend/spec/javascripts/views/CRUD/annotation/AnnotationList_spec.jsx @@ -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 () => {