Skip to content

Commit 54bc2f5

Browse files
committed
test: add tests
1 parent 84311ae commit 54bc2f5

6 files changed

Lines changed: 78 additions & 12 deletions

File tree

src/library-authoring/import-course/stepper/ImportStepperPage.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ describe('<ImportStepperModal />', () => {
159159
expect(courseCard).toBeChecked();
160160
});
161161

162-
it('should import select course on button click', async () => {
162+
it('should import selected course on button click', async () => {
163163
(useGetBlockTypes as jest.Mock).mockReturnValue({
164164
isPending: false,
165165
data: {

src/library-authoring/import-course/stepper/ReviewImportDetails.test.tsx

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useCourseDetails } from '@src/course-outline/data/apiHooks';
22
import { useMigrationInfo } from '@src/library-authoring/data/apiHooks';
3-
import { useGetBlockTypes } from '@src/search-manager';
3+
import { useGetBlockTypes, useGetContentHits } from '@src/search-manager';
44
import { render as baseRender, screen, initializeMocks } from '@src/testUtils';
55
import { LibraryProvider } from '@src/library-authoring/common/context/LibraryContext';
66
import { mockContentLibrary } from '@src/library-authoring/data/api.mocks';
@@ -25,6 +25,7 @@ jest.mock('@src/library-authoring/data/apiHooks', () => ({
2525
// Mock the useGetBlockTypes hook
2626
jest.mock('@src/search-manager', () => ({
2727
useGetBlockTypes: jest.fn().mockReturnValue({ isPending: true, data: null }),
28+
useGetContentHits: jest.fn().mockReturnValue({ isPending: true, data: null }),
2829
}));
2930

3031
const render = (element: React.ReactElement) => {
@@ -80,7 +81,7 @@ describe('ReviewImportDetails', () => {
8081
}],
8182
},
8283
});
83-
(useGetBlockTypes as jest.Mock).mockReturnValue({
84+
(useGetBlockTypes as jest.Mock).mockReturnValueOnce({
8485
isPending: false,
8586
data: { html: 1 },
8687
});
@@ -103,7 +104,7 @@ describe('ReviewImportDetails', () => {
103104
isPending: false,
104105
data: null,
105106
});
106-
(useGetBlockTypes as jest.Mock).mockReturnValue({
107+
(useGetBlockTypes as jest.Mock).mockReturnValueOnce({
107108
isPending: false,
108109
data: {
109110
chapter: 1,
@@ -134,13 +135,63 @@ describe('ReviewImportDetails', () => {
134135
expect(markAnalysisComplete).toHaveBeenCalledWith(true);
135136
});
136137

138+
it('considers children blocks of unsupportedBlocks', async () => {
139+
(useCourseDetails as jest.Mock).mockReturnValue({ isPending: false, data: { title: 'Test Course' } });
140+
(useMigrationInfo as jest.Mock).mockReturnValue({
141+
isPending: false,
142+
data: null,
143+
});
144+
(useGetContentHits as jest.Mock).mockReturnValue({
145+
isPending: false,
146+
data: {
147+
hits: [{usage_key: "some-usage-key"}],
148+
estimatedTotalHits: 1,
149+
},
150+
});
151+
(useGetBlockTypes as jest.Mock).mockReturnValueOnce({
152+
isPending: false,
153+
data: {
154+
chapter: 1,
155+
sequential: 2,
156+
vertical: 3,
157+
library_content: 1,
158+
html: 1,
159+
problem: 4,
160+
},
161+
}).mockReturnValueOnce({
162+
isPending: false,
163+
data: {
164+
problem: 2,
165+
},
166+
});
167+
168+
render(<ReviewImportDetails markAnalysisComplete={markAnalysisComplete} courseId="test-course-id" />);
169+
170+
expect(await screen.findByRole('alert')).toBeInTheDocument();
171+
expect(await screen.findByText(/Import Analysis Complete/i)).toBeInTheDocument();
172+
expect(await screen.findByText(
173+
/25.00% of content cannot be imported. For details see below./i,
174+
)).toBeInTheDocument();
175+
expect(await screen.findByText(/Total Blocks/i)).toBeInTheDocument();
176+
expect(await screen.findByText('9/12')).toBeInTheDocument();
177+
expect(await screen.findByText('Sections')).toBeInTheDocument();
178+
expect(await screen.findByText('1')).toBeInTheDocument();
179+
expect(await screen.findByText('Subsections')).toBeInTheDocument();
180+
expect(await screen.findByText('2')).toBeInTheDocument();
181+
expect(await screen.findByText('Units')).toBeInTheDocument();
182+
expect(await screen.findByText('3')).toBeInTheDocument();
183+
expect(await screen.findByText('Components')).toBeInTheDocument();
184+
expect(await screen.findByText('3/6')).toBeInTheDocument();
185+
expect(markAnalysisComplete).toHaveBeenCalledWith(true);
186+
});
187+
137188
it('renders success alert when no unsupported blocks', async () => {
138189
(useCourseDetails as jest.Mock).mockReturnValue({ isPending: false, data: { title: 'Test Course' } });
139190
(useMigrationInfo as jest.Mock).mockReturnValue({
140191
isPending: false,
141192
data: null,
142193
});
143-
(useGetBlockTypes as jest.Mock).mockReturnValue({
194+
(useGetBlockTypes as jest.Mock).mockReturnValueOnce({
144195
isPending: false,
145196
data: {
146197
chapter: 1,

src/library-authoring/import-course/stepper/ReviewImportDetails.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ import { useEffect, useMemo } from 'react';
88
import { CheckCircle, Warning } from '@openedx/paragon/icons';
99
import { useLibraryContext } from '@src/library-authoring/common/context/LibraryContext';
1010
import { useMigrationInfo } from '@src/library-authoring/data/apiHooks';
11-
import { useGetBlockTypes } from '@src/search-manager';
11+
import { useGetBlockTypes, useGetContentHits } from '@src/search-manager';
1212
import { SummaryCard } from './SummaryCard';
1313
import messages from '../messages';
14-
import { useGetContentHits } from '../../../search-manager/data/apiHooks';
1514

1615
interface Props {
1716
courseId?: string;
@@ -141,10 +140,16 @@ export const ReviewImportDetails = ({ courseId, markAnalysisComplete }: Props) =
141140
return unsupportedBlocks;
142141
}, [unsupportedBlockTypes]);
143142

144-
const { data: unsupportedBlocksData } = useGetContentHits([
145-
`context_key = "${courseId}"`,
146-
`block_type IN [${unsupportedBlockTypes?.flatMap(([value]) => `"${value}"`).join(',')}]`,
147-
], totalUnsupportedBlocks > 0, totalUnsupportedBlocks, 'always');
143+
const { data: unsupportedBlocksData } = useGetContentHits(
144+
[
145+
`context_key = "${courseId}"`,
146+
`block_type IN [${unsupportedBlockTypes?.flatMap(([ value ]) => `"${value}"`).join(',')}]`,
147+
],
148+
totalUnsupportedBlocks > 0,
149+
[ "usage_key" ],
150+
totalUnsupportedBlocks,
151+
'always'
152+
);
148153

149154
const { data: unsupportedBlocksChildren } = useGetBlockTypes([
150155
`context_key = "${courseId}"`,

src/search-manager/data/api.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,13 +561,15 @@ export const fetchContentHits = async (
561561
indexName: string,
562562
extraFilter?: Filter,
563563
limit?: number,
564+
attributesToRetrieve?: string[],
564565
): Promise<SearchResponse<Record<string, any>>> => {
565566
// Convert 'extraFilter' into an array
566567
const extraFilterFormatted = forceArray(extraFilter);
567568

568569
const results = await client.index(indexName).search('', {
569570
filter: extraFilterFormatted,
570571
limit,
572+
attributesToRetrieve,
571573
});
572574

573575
return results;

src/search-manager/data/apiHooks.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ export const useGetBlockTypes = (extraFilters: Filter, enabled: boolean = true)
309309
export const useGetContentHits = (
310310
extraFilters: Filter,
311311
enabled: boolean = true,
312+
attributesToRetrieve?: string[],
312313
limit?: number,
313314
refetchOnMount?: boolean | 'always',
314315
) => {
@@ -322,7 +323,13 @@ export const useGetContentHits = (
322323
indexName,
323324
extraFilters,
324325
],
325-
queryFn: enabled ? () => fetchContentHits(client!, indexName!, extraFilters, limit) : skipToken,
326+
queryFn: enabled ? () => fetchContentHits(
327+
client!,
328+
indexName!,
329+
extraFilters,
330+
limit,
331+
attributesToRetrieve,
332+
) : skipToken,
326333
refetchOnMount,
327334
});
328335
};

src/search-manager/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export {
1313
useContentSearchConnection,
1414
useContentSearchResults,
1515
useGetBlockTypes,
16+
useGetContentHits,
1617
buildSearchQueryKey,
1718
} from './data/apiHooks';
1819
export { TypesFilterData } from './hooks';

0 commit comments

Comments
 (0)