Skip to content

Commit

Permalink
Fixed tests (deephaven#445)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmingles committed May 21, 2024
1 parent f83ab39 commit 9937ba9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 33 deletions.
6 changes: 3 additions & 3 deletions plugins/ui/src/js/src/elements/ElementUtils.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
wrapElementChildren,
} from './ElementUtils';
import ObjectView from './ObjectView';
import { ITEM_ELEMENT_NAME } from './ElementConstants';
import { ELEMENT_NAME } from './ElementConstants';

const { asMock, createMockProxy } = TestUtils;

Expand Down Expand Up @@ -136,7 +136,7 @@ describe('wrapElementChildren', () => {
: textValue;

const expected = {
[ELEMENT_KEY]: ITEM_ELEMENT_NAME,
[ELEMENT_KEY]: ELEMENT_NAME.item,
props: {
key: itemKey ?? textValue,
textValue: expectedTextValue,
Expand All @@ -145,7 +145,7 @@ describe('wrapElementChildren', () => {
};

const actual = wrapElementChildren({
[ELEMENT_KEY]: ITEM_ELEMENT_NAME,
[ELEMENT_KEY]: ELEMENT_NAME.item,
props: givenProps,
});

Expand Down
15 changes: 5 additions & 10 deletions plugins/ui/src/js/src/layout/LayoutUtils.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,7 @@ import {
import Row from './Row';
import Stack from './Stack';
import ReactPanel from './ReactPanel';
import {
PANEL_ELEMENT_NAME,
ROW_ELEMENT_NAME,
COLUMN_ELEMENT_NAME,
STACK_ELEMENT_NAME,
} from '../elements/ElementConstants';
import { ELEMENT_NAME } from '../elements/ElementConstants';

beforeEach(() => {
TestUtils.disableConsoleOutput();
Expand All @@ -30,7 +25,7 @@ describe('isPanelElementNode', () => {
test.each([
[{ props: { title: 'test' } }, false],
[{ props: { title: 'test' }, __dhElemName: 'a different name' }, false],
[{ props: { title: 'test' }, __dhElemName: PANEL_ELEMENT_NAME }, true],
[{ props: { title: 'test' }, __dhElemName: ELEMENT_NAME.panel }, true],
])(`isPanelElementNode(%s)`, (element, result) => {
expect(isPanelElementNode(element)).toBe(result);
});
Expand All @@ -40,7 +35,7 @@ describe('isRowElementNode', () => {
test.each([
[{ props: { height: 100 } }, false],
[{ props: { height: 100 }, __dhElemName: 'a different name' }, false],
[{ props: { height: 100 }, __dhElemName: ROW_ELEMENT_NAME }, true],
[{ props: { height: 100 }, __dhElemName: ELEMENT_NAME.row }, true],
])(`isRowElementNode(%s)`, (element, result) => {
expect(isRowElementNode(element)).toBe(result);
});
Expand All @@ -50,7 +45,7 @@ describe('isColumnElementNode', () => {
test.each([
[{ props: { width: 100 } }, false],
[{ props: { width: 100 }, __dhElemName: 'a different name' }, false],
[{ props: { width: 100 }, __dhElemName: COLUMN_ELEMENT_NAME }, true],
[{ props: { width: 100 }, __dhElemName: ELEMENT_NAME.column }, true],
])(`isColumnElementNode(%s)`, (element, result) => {
expect(isColumnElementNode(element)).toBe(result);
});
Expand All @@ -64,7 +59,7 @@ describe('isStackElementNode', () => {
false,
],
[
{ props: { height: 100, width: 100 }, __dhElemName: STACK_ELEMENT_NAME },
{ props: { height: 100, width: 100 }, __dhElemName: ELEMENT_NAME.stack },
true,
],
])(`isStackElementNode(%s)`, (element, result) => {
Expand Down
17 changes: 7 additions & 10 deletions plugins/ui/src/js/src/widget/DocumentHandler.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ import DocumentHandler, { DocumentHandlerProps } from './DocumentHandler';
import { ReactPanelProps } from '../layout/LayoutUtils';
import { MixedPanelsError, NoChildrenError } from '../errors';
import { getComponentForElement } from './WidgetUtils';
import {
DASHBOARD_ELEMENT_NAME,
PANEL_ELEMENT_NAME,
} from '../elements/ElementConstants';
import { ELEMENT_NAME } from '../elements/ElementConstants';

const mockReactPanel = jest.fn((props: ReactPanelProps) => (
<div>ReactPanel</div>
Expand Down Expand Up @@ -67,7 +64,7 @@ it('should throw an error if the document mixes panel and non-panel elements', (
TestUtils.disableConsoleOutput();

const children = makeDocument([
makeElement(PANEL_ELEMENT_NAME),
makeElement(ELEMENT_NAME.panel),
makeElement('not panel element'),
]);
expect(() => render(makeDocumentHandler({ children }))).toThrow(
Expand All @@ -83,25 +80,25 @@ it('should combine multiple single elements into one panel', () => {

it('should render multiple panels', () => {
const children = makeDocument([
makeElement(PANEL_ELEMENT_NAME),
makeElement(PANEL_ELEMENT_NAME),
makeElement(ELEMENT_NAME.panel),
makeElement(ELEMENT_NAME.panel),
]);
render(makeDocumentHandler({ children }));
expect(mockReactPanel).toHaveBeenCalledTimes(2);
});

it('should throw an error if the document mixes dashboard and non-dashboard elements', () => {
const children = makeDocument([
makeElement(PANEL_ELEMENT_NAME),
makeElement(DASHBOARD_ELEMENT_NAME),
makeElement(ELEMENT_NAME.panel),
makeElement(ELEMENT_NAME.dashboard),
]);
expect(() => render(makeDocumentHandler({ children }))).toThrow(
MixedPanelsError
);
});

it('should render a dashboard', () => {
const children = makeDocument([makeElement(DASHBOARD_ELEMENT_NAME)]);
const children = makeDocument([makeElement(ELEMENT_NAME.dashboard)]);
render(makeDocumentHandler({ children }));
expect(mockReactPanel).toHaveBeenCalledTimes(0);
});
15 changes: 5 additions & 10 deletions plugins/ui/src/js/src/widget/WidgetUtils.test.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import React from 'react';
import { Text } from '@deephaven/components';
import {
FRAGMENT_ELEMENT_NAME,
ITEM_ELEMENT_NAME,
HTML_ELEMENT_NAME_PREFIX,
ICON_ELEMENT_TYPE_PREFIX,
} from '../elements/ElementConstants';
import { ELEMENT_NAME, ELEMENT_PREFIX } from '../elements/ElementConstants';
import { ElementNode, ELEMENT_KEY } from '../elements/ElementUtils';
import HTMLElementView from '../elements/HTMLElementView';
import IconElementView from '../elements/IconElementView';
Expand Down Expand Up @@ -33,9 +28,9 @@ describe('getComponentTypeForElement', () => {
describe('getComponentForElement', () => {
it.each([
/* eslint-disable react/jsx-key */
[`${HTML_ELEMENT_NAME_PREFIX}div`, HTMLElementView],
[`${ELEMENT_PREFIX.html}div`, HTMLElementView],
[`${SPECTRUM_ELEMENT_TYPE_PREFIX}ActionButton`, SpectrumElementView],
[`${ICON_ELEMENT_TYPE_PREFIX}vsAdd`, IconElementView],
[`${ELEMENT_PREFIX.icon}vsAdd`, IconElementView],
/* eslint-enable react/jsx-key */
] as [string, ({ element }: { element: unknown }) => JSX.Element][])(
'should use expected element factory function: %s',
Expand All @@ -52,12 +47,12 @@ describe('getComponentForElement', () => {
)('should spread props for element nodes: %s', elementKey => {
let element: ElementNode = { [ELEMENT_KEY]: elementKey };

if (elementKey === FRAGMENT_ELEMENT_NAME) {
if (elementKey === ELEMENT_NAME.fragment) {
element = {
...element,
props: { key: 'mock.key', children: ['Some child'] },
};
} else if (elementKey === ITEM_ELEMENT_NAME) {
} else if (elementKey === ELEMENT_NAME.item) {
element = {
...element,
props: { children: <Text>Some child</Text> },
Expand Down

0 comments on commit 9937ba9

Please sign in to comment.