diff --git a/src/form/Form/NoFieldFound.test.tsx b/src/form/Form/NoFieldFound.test.tsx index 4974ea1..f5ddd93 100644 --- a/src/form/Form/NoFieldFound.test.tsx +++ b/src/form/Form/NoFieldFound.test.tsx @@ -19,6 +19,23 @@ describe('NoFieldFound Component', () => { expect(screen.getByText('No Required fields found')).toBeInTheDocument(); }); + it('should not suggest switching tabs when the All tab is already selected', () => { + const mockContextValue: CanvasFormTabsContextResult = { + selectedTab: 'All', + setSelectedTab: jest.fn(), + }; + + render( + + + , + ); + + expect(screen.getByText('No fields found')).toBeInTheDocument(); + expect(screen.getByText('No field found matching this criteria.')).toBeInTheDocument(); + expect(screen.queryByRole('button', { name: /All/i })).not.toBeInTheDocument(); + }); + it('should call onTabChange when the button is clicked', () => { const mockContextValue: CanvasFormTabsContextResult = { selectedTab: 'Required', diff --git a/src/form/Form/NoFieldFound.tsx b/src/form/Form/NoFieldFound.tsx index bb04512..7934dff 100644 --- a/src/form/Form/NoFieldFound.tsx +++ b/src/form/Form/NoFieldFound.tsx @@ -4,22 +4,32 @@ import { CanvasFormTabsContext } from '../providers/canvas-form-tabs.provider'; export const NoFieldFound: FunctionComponent<{ className?: string }> = (props) => { const canvasFormTabsContext = useContext(CanvasFormTabsContext); + const isAllTabSelected = canvasFormTabsContext.selectedTab === 'All'; return ( - - No field found matching this criteria. Please switch to the{' '} - {' '} - tab. + + No field found matching this criteria. + {!isAllTabSelected && ( + <> + {' '} + Please switch to the{' '} + {' '} + tab. + + )}