Skip to content
Merged
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
22 changes: 20 additions & 2 deletions src/library-authoring/components/CollectionCard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,24 @@ const CollectionHitSample: CollectionHit = {
created: 1722434322294,
modified: 1722434322294,
numChildren: 2,
published: {
numChildren: 1,
},
tags: {},
};

let axiosMock: MockAdapter;
let mockShowToast;

const render = (ui: React.ReactElement) => baseRender(ui, {
extraWrapper: ({ children }) => <LibraryProvider libraryId="lib:Axim:TEST">{ children }</LibraryProvider>,
const render = (ui: React.ReactElement, showOnlyPublished: boolean = false) => baseRender(ui, {
extraWrapper: ({ children }) => (
<LibraryProvider
libraryId="lib:Axim:TEST"
showOnlyPublished={showOnlyPublished}
>
{ children }
</LibraryProvider>
),
});

describe('<CollectionCard />', () => {
Expand All @@ -52,6 +62,14 @@ describe('<CollectionCard />', () => {
expect(screen.queryByText('Collection (2)')).toBeInTheDocument();
});

it('should render published content', () => {
render(<CollectionCard collectionHit={CollectionHitSample} />, true);

expect(screen.queryByText('Collection Display Formated Name')).toBeInTheDocument();
expect(screen.queryByText('Collection description')).toBeInTheDocument();
expect(screen.queryByText('Collection (1)')).toBeInTheDocument();
});

it('should navigate to the collection if the open menu clicked', async () => {
render(<CollectionCard collectionHit={CollectionHitSample} />);

Expand Down
9 changes: 8 additions & 1 deletion src/library-authoring/components/CollectionCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,21 @@ const CollectionCard = ({ collectionHit } : CollectionCardProps) => {
const {
openCollectionInfoSidebar,
componentPickerMode,
showOnlyPublished,
} = useLibraryContext();

const {
type: componentType,
formatted,
tags,
numChildren,
published,
} = collectionHit;

const numChildrenCount = showOnlyPublished ? (
published?.numChildren || 0
) : numChildren;

const { displayName = '', description = '' } = formatted;

return (
Expand All @@ -127,7 +134,7 @@ const CollectionCard = ({ collectionHit } : CollectionCardProps) => {
displayName={displayName}
description={description}
tags={tags}
numChildren={numChildren}
numChildren={numChildrenCount}
actions={!componentPickerMode && (
<ActionRow>
<CollectionMenu collectionHit={collectionHit} />
Expand Down
2 changes: 2 additions & 0 deletions src/search-manager/data/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ export interface ContentHit extends BaseContentHit {
export interface ContentPublishedData {
description?: string,
displayName?: string,
numChildren?: number,
}

/**
Expand All @@ -151,6 +152,7 @@ export interface ContentPublishedData {
export interface CollectionHit extends BaseContentHit {
description: string;
numChildren?: number;
published?: ContentPublishedData;
}

/**
Expand Down