Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/form/Form/NoFieldFound.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<CanvasFormTabsContext.Provider value={mockContextValue}>
<NoFieldFound />
</CanvasFormTabsContext.Provider>,
);

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',
Expand Down
34 changes: 22 additions & 12 deletions src/form/Form/NoFieldFound.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<Card data-testid="no-field-found" className={props.className}>
<CardBody>
<Alert variant="info" title={`No ${canvasFormTabsContext.selectedTab} fields found`}>
No field found matching this criteria. Please switch to the{' '}
<Button
onClick={() => {
canvasFormTabsContext.setSelectedTab('All');
}}
variant="link"
isInline
>
<b>All</b>
</Button>{' '}
tab.
<Alert
variant="info"
title={isAllTabSelected ? 'No fields found' : `No ${canvasFormTabsContext.selectedTab} fields found`}
>
No field found matching this criteria.
{!isAllTabSelected && (
<>
{' '}
Please switch to the{' '}
<Button
onClick={() => {
canvasFormTabsContext.setSelectedTab('All');
}}
variant="link"
isInline
>
<b>All</b>
</Button>{' '}
tab.
</>
)}
</Alert>
</CardBody>
</Card>
Expand Down