import { render, screen } from '@testing-library/react';
import React from 'react';
import RelatedDesigns from '../custom/CatalogDetail/RelatedDesigns';
import type { Pattern } from '../custom/CustomCatalog/CustomCard';
import { SistentThemeProvider } from '../theme';
// Carousel observes element sizes; jsdom has no ResizeObserver.
class ResizeObserverMock {
observe() {}
unobserve() {}
disconnect() {}
}
global.ResizeObserver = ResizeObserverMock as unknown as typeof ResizeObserver;
const renderWithTheme = (ui: React.ReactElement) =>
render({ui});
const profiles: Record = {
'owner-fabian': {
firstName: 'Fabian',
lastName: 'Muoghalu',
avatarUrl: 'https://example.com/fabian.png'
},
'owner-ada': {
firstName: 'Ada',
lastName: 'Lovelace',
avatarUrl: 'https://example.com/ada.png'
}
};
const useGetUserProfileByIdQuery = jest.fn(({ id }: { id: string }) => ({
data: profiles[id]
}));
const makePattern = (overrides: {
id: string;
userId: string;
name: string;
firstName: string;
lastName: string;
}): Pattern =>
({
patternFile: 'name: test',
visibility: 'published',
catalogData: { imageURL: [] },
user: { firstName: overrides.firstName, lastName: overrides.lastName },
firstName: overrides.firstName,
lastName: overrides.lastName,
avatarUrl: `https://example.com/${overrides.id}.png`,
createdAt: '2026-01-01T00:00:00Z',
updatedAt: '2026-01-02T00:00:00Z',
...overrides
}) as Pattern;
const viewedDesign = makePattern({
id: 'design-fabian',
userId: 'owner-fabian',
name: 'Agentic RAG Architecture',
firstName: 'Fabian',
lastName: 'Muoghalu'
});
const adaDesign = makePattern({
id: 'design-ada',
userId: 'owner-ada',
name: 'Agentic Cloud Cost Monitoring',
firstName: 'Ada',
lastName: 'Lovelace'
});
const fabianOtherDesign = makePattern({
id: 'design-fabian-2',
userId: 'owner-fabian',
name: 'SmartNote',
firstName: 'Fabian',
lastName: 'Muoghalu'
});
const baseProps = {
details: viewedDesign,
type: 'designs',
userProfile: { firstName: 'Fabian', lastName: 'Muoghalu', avatarUrl: 'https://example.com/fabian.png' },
technologySVGPath: '/img/meshmodels',
technologySVGSubpath: 'icons/color',
orgName: 'Layer5',
fetchingOrgError: false,
onSuggestedPatternClick: jest.fn(),
useGetUserProfileByIdQuery
};
describe('RelatedDesigns', () => {
beforeEach(() => {
jest.clearAllMocks();
});
it('shows each similar design\u2019s own author, not the viewed design\u2019s owner', () => {
// Regression: every card in "Similar Designs by Type" rendered the
// viewed design's owner as the author, because one shared userProfile
// was passed to all cards. See layer5io/meshery-cloud#6599.
renderWithTheme(
);
expect(screen.getByText('Ada Lovelace')).not.toBeNull();
expect(screen.queryByText('Fabian Muoghalu')).toBeNull();
expect(useGetUserProfileByIdQuery).toHaveBeenCalledWith(
{ id: 'owner-ada' },
{ skip: false }
);
});
it('keeps the viewed design\u2019s owner on the same-author section', () => {
renderWithTheme(
);
expect(screen.getByText('Fabian Muoghalu')).not.toBeNull();
expect(screen.getByText('Other published design by Fabian under Layer5')).not.toBeNull();
});
it('falls back to the pattern\u2019s own author fields when no profile hook is provided', () => {
renderWithTheme(
);
expect(screen.getByText('Ada Lovelace')).not.toBeNull();
expect(screen.queryByText('Fabian Muoghalu')).toBeNull();
});
});