Skip to content

Commit 7becfbe

Browse files
test Section visibility and SubPanel handling
1 parent 51f7b46 commit 7becfbe

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

src/components/containers/Section.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ class Section extends Component {
5959
}
6060

6161
render() {
62-
const hasVisibleChildren = this.children.some(childIsVisible);
62+
const hasVisibleChildren =
63+
(this.children && this.children.some(childIsVisible)) ||
64+
Boolean(this.subPanel);
6365

6466
return hasVisibleChildren ? (
6567
<div className="section">

src/components/containers/SubPanel.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@ export default class SubPanel extends Component {
1515

1616
render() {
1717
const toggleClass = `subpanel__toggle ${this.props.toggleIconClass}`;
18+
const isVisible = this.props.show || this.state.isVisible;
1819
return (
1920
<span>
2021
<span>
2122
<i className={toggleClass} onClick={this.toggleVisibility} />
2223
</span>
23-
{this.state.isVisible ? (
24+
{isVisible ? (
2425
<div className="subpanel">
2526
<div className="subpanel__cover" onClick={this.toggleVisibility} />
2627
<div>{this.props.children}</div>
@@ -33,6 +34,7 @@ export default class SubPanel extends Component {
3334

3435
SubPanel.propTypes = {
3536
toggleIconClass: PropTypes.string.isRequired,
37+
show: PropTypes.bool,
3638
};
3739

3840
SubPanel.defaultProps = {

src/components/containers/__tests__/Section-test.js

+24-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
22
import Section from '../Section';
3+
import SubPanel from '../SubPanel';
34
import {Flaglist, Info, Numeric} from '../../fields';
45
import {TestEditor, fixtures, plotly} from '../../../lib/test-utils';
56
import {connectTraceToPlot} from '../../../lib';
@@ -47,7 +48,7 @@ describe('Section', () => {
4748
).toBe(false);
4849
});
4950

50-
fit('is visible if it contains any non attr children', () => {
51+
it('is visible if it contains any non attr children', () => {
5152
const wrapper = mount(
5253
<TestEditor
5354
plotly={plotly}
@@ -89,4 +90,26 @@ describe('Section', () => {
8990
expect(wrapper.find(Flaglist).exists()).toBe(false);
9091
expect(wrapper.find(Numeric).exists()).toBe(false);
9192
});
93+
94+
it('will render first subPanel even with no visible attrs', () => {
95+
const wrapper = mount(
96+
<TestEditor
97+
plotly={plotly}
98+
onUpdate={jest.fn()}
99+
{...fixtures.scatter({deref: true})}
100+
>
101+
<Section name="test-section">
102+
<SubPanel show>
103+
<Info>INFO</Info>
104+
</SubPanel>
105+
<SubPanel show>
106+
<Info>MISINFORMATION</Info>
107+
</SubPanel>
108+
</Section>
109+
</TestEditor>
110+
).find('[name="test-section"]');
111+
112+
expect(wrapper.find(Info).length).toBe(1);
113+
expect(wrapper.find(Info).text()).toBe('INFO');
114+
});
92115
});

0 commit comments

Comments
 (0)