Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions superset-frontend/spec/helpers/Worker.ts
Original file line number Diff line number Diff line change
@@ -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 };
6 changes: 4 additions & 2 deletions superset-frontend/spec/helpers/shim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() });
Expand All @@ -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 => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -50,6 +53,7 @@ describe('HeaderActionsDropdown', () => {
updateCss: () => {},
userCanEdit: false,
userCanSave: false,
lastModifiedTime: 0,
};

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -45,13 +46,16 @@ describe('Markdown', () => {
editMode: false,
availableColumnCount: 12,
columnWidth: 50,
redoLength: 0,
undoLength: 0,
onResizeStart() {},
onResize() {},
onResizeStop() {},
handleComponentDrop() {},
updateComponents() {},
deleteComponent() {},
logEvent() {},
addDangerToast() {},
};

function setup(overrideProps) {
Expand Down Expand Up @@ -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();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down