Skip to content

Commit

Permalink
fix encoded paths and fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
slax57 committed Jan 24, 2025
1 parent 67b2001 commit 0d16fa0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
3 changes: 2 additions & 1 deletion packages/ra-ui-materialui/src/form/TabbedForm.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ describe('<TabbedForm />', () => {

const tabs = await screen.findAllByRole('tab');
expect(tabs.length).toEqual(2);
await screen.findByLabelText('Title');
const titleInput = await screen.findByLabelText('Title');
expect(titleInput).toBeVisible();
});

it('should set the style of an inactive Tab button with errors', async () => {
Expand Down
15 changes: 6 additions & 9 deletions packages/ra-ui-materialui/src/form/TabbedFormView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,15 @@ export const TabbedFormView = (props: TabbedFormViewProps): ReactElement => {
return null;
}
const tabPath = getTabbedFormTabFullPath(tab, index);
console.log(
'matchPath',
`${splatPathBase}/${tabPath}`,
location.pathname
);
const hidden = syncWithLocation
? !matchPath(
`${splatPathBase}/${tabPath}`,
// The current location might have encoded segments (e.g. the record id) but resolvedPath.pathname doesn't
// and the match would fail.
getDecodedPathname(location.pathname)
location.pathname
)
: tabValue !== index;

Expand All @@ -98,12 +101,6 @@ export const TabbedFormView = (props: TabbedFormViewProps): ReactElement => {
);
};

/**
* Returns the pathname with each segment decoded
*/
const getDecodedPathname = (pathname: string) =>
pathname.split('/').map(decodeURIComponent).join('/');

const DefaultTabs = <TabbedFormTabs />;
const DefaultComponent = ({ children }) => (
<CardContent>{children}</CardContent>
Expand Down
1 change: 1 addition & 0 deletions test-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// expect(element).toHaveTextContent(/react/i)
// learn more: https://github.com/testing-library/jest-dom
import '@testing-library/jest-dom';
import '@testing-library/jest-dom/jest-globals';

// Ignore warnings about act()
// See https://github.com/testing-library/react-testing-library/issues/281,
Expand Down

0 comments on commit 0d16fa0

Please sign in to comment.