Skip to content

Commit

Permalink
Add some unit tests to ensure the height attribute gets set
Browse files Browse the repository at this point in the history
  • Loading branch information
mofojed committed Mar 5, 2024
1 parent 0b41a88 commit f8f4832
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions plugins/ui/src/js/src/elements/spectrum/TabPanels.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import {
Item,
Tabs,
TabList,
Provider,
defaultTheme,
} from '@adobe/react-spectrum';
import TabPanels from './TabPanels';
import Flex from './Flex';

describe('TabPanels', () => {
function renderTabPanelsChild(children: React.ReactNode) {
return render(
<Provider theme={defaultTheme}>
<Tabs selectedKey="foo">
<TabList>
<Item key="foo">Foo</Item>
</TabList>
<TabPanels>
<Item key="foo">{children}</Item>
</TabPanels>
</Tabs>
</Provider>
);
}

it('should add height=100% prop to flex child', () => {
const flexChild = <Flex data-testid="flex-child">Flex Child</Flex>;
renderTabPanelsChild(flexChild);
const flexElement = screen.queryByTestId('flex-child');
expect(flexElement).toHaveStyle('height: 100%');
});

it('should not add height=100% prop to non-flex child', () => {
const nonFlexChild = <div data-testid="non-flex-child">Non-Flex Child</div>;
renderTabPanelsChild(nonFlexChild);
const nonFlexElement = screen.queryByTestId('non-flex-child');
expect(nonFlexElement).not.toHaveStyle('height: 100%');
});
});

0 comments on commit f8f4832

Please sign in to comment.