Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core] Use describeTreeView in existing tests for useTreeViewItems #12732

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,60 +1,24 @@
import * as React from 'react';
import { expect } from 'chai';
import { createRenderer, ErrorBoundary } from '@mui-internal/test-utils';
import { RichTreeView } from '@mui/x-tree-view/RichTreeView';
import { SimpleTreeView } from '@mui/x-tree-view/SimpleTreeView';
import { TreeItem } from '@mui/x-tree-view/TreeItem';
import { describeTreeView } from 'test/utils/tree-view/describeTreeView';

describe('useTreeViewItems', () => {
const { render } = createRenderer();

it('should throw an error when two items have the same ID (items prop approach)', function test() {
// TODO is this fixed?
if (!/jsdom/.test(window.navigator.userAgent)) {
// can't catch render errors in the browser for unknown reason
// tried try-catch + error boundary + window onError preventDefault
this.skip();
}

expect(() =>
render(
<ErrorBoundary>
<RichTreeView
items={[
{ id: '1', label: '1' },
{ id: '1', label: 'B' },
]}
/>
</ErrorBoundary>,
),
).toErrorDev([
'MUI X: The Tree View component requires all items to have a unique `id` property.',
'MUI X: The Tree View component requires all items to have a unique `id` property.',
'The above error occurred in the <ForwardRef(RichTreeView)> component:',
]);
});

it('should throw an error when two items have the same ID (JSX approach)', function test() {
describeTreeView('useTreeViewItems plugin', ({ render, treeViewComponent }) => {
it('should throw an error when two items have the same ID', function test() {
// TODO is this fixed?
if (!/jsdom/.test(window.navigator.userAgent)) {
// can't catch render errors in the browser for unknown reason
// tried try-catch + error boundary + window onError preventDefault
this.skip();
}

expect(() =>
render(
<ErrorBoundary>
<SimpleTreeView>
<TreeItem itemId="1" label="A" />
<TreeItem itemId="1" label="B" />
</SimpleTreeView>
</ErrorBoundary>,
),
).toErrorDev([
'MUI X: The Tree View component requires all items to have a unique `id` property.',
'MUI X: The Tree View component requires all items to have a unique `id` property.',
'The above error occurred in the <ForwardRef(SimpleTreeView)> component:',
]);
expect(() => render({ items: [{ id: '1' }, { id: '1' }], withErrorBoundary: true })).toErrorDev(
[
...(treeViewComponent === 'SimpleTreeView'
? ['Encountered two children with the same key']
: []),
'MUI X: The Tree View component requires all items to have a unique `id` property.',
'MUI X: The Tree View component requires all items to have a unique `id` property.',
`The above error occurred in the <ForwardRef(${treeViewComponent})> component`,
],
);
});
});