diff --git a/.changeset/two-foxes-marry.md b/.changeset/two-foxes-marry.md new file mode 100644 index 0000000000..a6ac7df666 --- /dev/null +++ b/.changeset/two-foxes-marry.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-home': patch +--- + +Fix `` to display only the selected tab, not the other way around. diff --git a/plugins/home/src/componentRenderers/ComponentTabs/ComponentTabs.test.tsx b/plugins/home/src/componentRenderers/ComponentTabs/ComponentTabs.test.tsx new file mode 100644 index 0000000000..96ab37a8aa --- /dev/null +++ b/plugins/home/src/componentRenderers/ComponentTabs/ComponentTabs.test.tsx @@ -0,0 +1,76 @@ +/* + * Copyright 2021 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { render } from '@testing-library/react'; +import userEvent from '@testing-library/user-event'; +import React from 'react'; +import { ComponentTabs } from './ComponentTabs'; + +describe('', () => { + test('should render tabs without exploding', () => { + const { getByText } = render( + <>ContentA, + }, + { + label: 'TabB', + Component: () => <>ContentB, + }, + ]} + />, + ); + + expect(getByText('TabA')).toBeInTheDocument(); + expect(getByText('TabB')).toBeInTheDocument(); + + expect(getByText('ContentA')).toBeInTheDocument(); + expect(getByText('ContentB')).toHaveStyle({ + display: 'none', + }); + }); + + test('should switch tab on click', () => { + const { getByText } = render( + <>ContentA, + }, + { + label: 'TabB', + Component: () => <>ContentB, + }, + ]} + />, + ); + + expect(getByText('ContentB')).toHaveStyle({ + display: 'none', + }); + + userEvent.click(getByText('TabB')); + + expect(getByText('ContentA')).toHaveStyle({ + display: 'none', + }); + }); +}); diff --git a/plugins/home/src/componentRenderers/ComponentTabs/ComponentTabs.tsx b/plugins/home/src/componentRenderers/ComponentTabs/ComponentTabs.tsx index f404a80980..d6d3561fe1 100644 --- a/plugins/home/src/componentRenderers/ComponentTabs/ComponentTabs.tsx +++ b/plugins/home/src/componentRenderers/ComponentTabs/ComponentTabs.tsx @@ -44,7 +44,10 @@ export const ComponentTabs = ({ ))} {tabs.map(({ Component }, idx) => ( -
+
))}