test(subdirectory): close review nits on the navbar-logo round-3 fix

Addresses three minor findings from the /review-code pass on e6a58cb047:

- pathUtils.test.ts: cover `stripAppRoot('/superset/')` (trailing slash)
  in addition to the no-slash variant — both branches now return '/'.
- Menu.test.tsx: wrap the three rooted-brand-path regressions in a
  describe block with a beforeEach that resets `observedGenericLinkTo`,
  so a future inserted test cannot leak stale state.
- Menu.test.tsx: add a regression for the theme.brandLogoHref branch —
  asserts that when `theme.brandLogoUrl` is set and `brandLogoHref` is
  already rooted, the resulting <a href> is single-prefix. Closes the
  test-coverage gap noted by the reviewer (the branch's runtime
  correctness was already covered by ensureAppRoot idempotence in
  e6a58cb047, but had no dedicated test).

71/71 touched-suite Jest tests green.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Joe Li
2026-05-14 12:29:48 -07:00
parent 7daa1741d0
commit b7c4d1e999
2 changed files with 41 additions and 2 deletions

View File

@@ -841,8 +841,12 @@ test('brand link falls back to brand.path when theme brandLogoUrl is absent', as
// already has the root stripped — the value the production Router will then
// safely re-prepend.
describe('brand link single-prefix regressions (subdirectory deployment)', () => {
beforeEach(() => {
observedGenericLinkTo = null;
});
test('brand link hands a root-stripped path to GenericLink when brand.path arrives already rooted (SPA route)', async () => {
observedGenericLinkTo = null;
applicationRootMock.mockReturnValue('/superset');
staticAssetsPrefixMock.mockReturnValue('/superset');
useSelectorMock.mockReturnValue({ roles: user.roles });
@@ -911,7 +915,6 @@ test('brand link is single-prefix when brand.path arrives already rooted (non-SP
});
test('brand link strips a nested application root before handing to GenericLink', async () => {
observedGenericLinkTo = null;
applicationRootMock.mockReturnValue('/preset/superset');
staticAssetsPrefixMock.mockReturnValue('/preset/superset');
useSelectorMock.mockReturnValue({ roles: user.roles });
@@ -941,3 +944,33 @@ test('brand link strips a nested application root before handing to GenericLink'
});
expect(observedGenericLinkTo).toBe('/welcome/');
});
test('brand link from theme.brandLogoHref is single-prefix when already rooted', async () => {
applicationRootMock.mockReturnValue('/superset');
staticAssetsPrefixMock.mockReturnValue('/superset');
useSelectorMock.mockReturnValue({ roles: user.roles });
useThemeMock.mockReturnValue({
...CoreTheme.supersetTheme,
brandLogoUrl: '/superset/static/assets/images/custom-logo.png',
brandLogoHref: '/superset/welcome/',
});
render(<Menu {...mockedProps} />, {
useRedux: true,
useQueryParams: true,
useRouter: true,
useTheme: true,
});
const brandLink = await screen.findByRole('link', {
name: /apache superset/i,
});
expect(brandLink).toHaveAttribute('href', '/superset/welcome/');
const brandImg = brandLink.querySelector('img');
expect(brandImg).toHaveAttribute(
'src',
'/superset/static/assets/images/custom-logo.png',
);
});
});

View File

@@ -275,6 +275,12 @@ test('stripAppRoot returns "/" when given the bare application root', async () =
expect(stripAppRoot('/superset')).toBe('/');
});
test('stripAppRoot returns "/" when given the application root with a trailing slash', async () => {
const { stripAppRoot } = await loadPathUtils('/superset/');
expect(stripAppRoot('/superset/')).toBe('/');
});
test('stripAppRoot respects segment boundaries — `/supersetfoo` is not the root', async () => {
const { stripAppRoot } = await loadPathUtils('/superset/');