Skip to content

Commit

Permalink
fix: panel: ensures there is no element when footer is not implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
dkilgore-eightfold committed Oct 17, 2023
1 parent e4f0359 commit 2d9680c
Show file tree
Hide file tree
Showing 4 changed files with 618 additions and 24 deletions.
41 changes: 30 additions & 11 deletions src/components/Panel/Panel.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { Stories } from '@storybook/addon-docs';
import { ComponentStory, ComponentMeta } from '@storybook/react';
import { Panel, PanelSize } from './';
import { PanelHeader } from './PanelHeader';
import { Button, ButtonVariant } from '../Button';
import { IconName } from '../Icon';
import { PrimaryButton } from '../Button';

export default {
title: 'Panel',
Expand Down Expand Up @@ -107,12 +107,20 @@ const Panel_Story: ComponentStory<typeof Panel> = (args) => {
const [visible, setVisible] = useState<boolean>(false);
return (
<>
<PrimaryButton text={'Open panel'} onClick={() => setVisible(true)} />
<Button
onClick={() => setVisible(true)}
text={'Open panel'}
variant={ButtonVariant.Primary}
/>
<Panel
{...args}
footer={
<div>
<PrimaryButton text={'Close'} onClick={() => setVisible(false)} />
<Button
onClick={() => setVisible(false)}
text={'Close'}
variant={ButtonVariant.Primary}
/>
</div>
}
visible={visible}
Expand All @@ -126,23 +134,25 @@ const Stacked_Story: ComponentStory<typeof Panel> = (args) => {
const [visible, setVisible] = useState<Record<string, boolean>>({});
return (
<>
<PrimaryButton
text={'Open first panel'}
<Button
onClick={() =>
setVisible({
simple: true,
})
}
text={'Open first panel'}
variant={ButtonVariant.Primary}
/>
<Panel {...args} visible={visible.simple} onClose={() => setVisible({})}>
<PrimaryButton
text={'Open second panel'}
<Button
onClick={() =>
setVisible({
...visible,
child: true,
})
}
text={'Open second panel'}
variant={ButtonVariant.Primary}
/>
<Panel
{...args}
Expand All @@ -155,14 +165,15 @@ const Stacked_Story: ComponentStory<typeof Panel> = (args) => {
})
}
>
<PrimaryButton
text={'Open third panel'}
<Button
onClick={() =>
setVisible({
...visible,
nextChild: true,
})
}
text={'Open third panel'}
variant={ButtonVariant.Primary}
/>
<Panel
{...args}
Expand All @@ -185,12 +196,20 @@ const Panel_Header_Story: ComponentStory<typeof Panel> = (args) => {
const [visible, setVisible] = useState<boolean>(false);
return (
<>
<PrimaryButton text={'Open panel'} onClick={() => setVisible(true)} />
<Button
onClick={() => setVisible(true)}
text={'Open panel'}
variant={ButtonVariant.Primary}
/>
<Panel
{...args}
footer={
<div>
<PrimaryButton text={'Close'} onClick={() => setVisible(false)} />
<Button
onClick={() => setVisible(false)}
text={'Close'}
variant={ButtonVariant.Primary}
/>
</div>
}
visible={visible}
Expand Down
23 changes: 20 additions & 3 deletions src/components/Panel/Panel.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Enzyme, { mount, ReactWrapper } from 'enzyme';
import Adapter from '@wojtekmaj/enzyme-adapter-react-17';
import MatchMediaMock from 'jest-matchmedia-mock';
import { Panel } from './';
import { Button, ButtonVariant } from '../Button';
import { IconName } from '../Icon';

Enzyme.configure({ adapter: new Adapter() });
Expand All @@ -11,8 +12,13 @@ let matchMedia: any;

describe('Panel', () => {
let wrapper: ReactWrapper;
const body = 'This is the panel body';
const title = 'This is the title';
const body: string = 'This is the panel body';
const title: string = 'This is the title';
const footer: JSX.Element = (
<div>
<Button text={'Close'} variant={ButtonVariant.Primary} />
</div>
);

beforeAll(() => {
matchMedia = new MatchMediaMock();
Expand All @@ -23,7 +29,7 @@ describe('Panel', () => {

beforeEach(() => {
wrapper = mount(
<Panel visible={false}>
<Panel footer={footer} visible={false}>
<div>{body}</div>
</Panel>
);
Expand Down Expand Up @@ -127,4 +133,15 @@ describe('Panel', () => {
});
expect(wrapper.find('.modeless').length).toBeTruthy();
});

test('Panel footer', () => {
wrapper.setProps({
visible: true,
title,
body,
footer,
});
expect(wrapper.find('.footer')).toBeTruthy();
expect(wrapper.find('.button-primary').text()).toBe('Close');
});
});
2 changes: 1 addition & 1 deletion src/components/Panel/Panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ export const Panel = React.forwardRef<PanelRef, PanelProps>(
>
{getHeader()}
{getBody()}
{getFooter()}
{!!footer && getFooter()}
</div>
</FocusTrap>
</NoFormStyle>
Expand Down
Loading

0 comments on commit 2d9680c

Please sign in to comment.