Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Create collection Modal [FC-0062] #1259

Merged
merged 17 commits into from
Sep 14, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
chore: fix merge conflicts
ChrisChV committed Sep 13, 2024
commit 8a57c26b58d99810c9bca4b3945889788663a5ed
22 changes: 19 additions & 3 deletions src/library-authoring/LibraryAuthoringPage.test.tsx
Original file line number Diff line number Diff line change
@@ -570,7 +570,7 @@ describe('<LibraryAuthoringPage />', () => {
expect(screen.getByText(/add content/i)).toBeInTheDocument();

// Open New collection Modal
const newCollectionButton = screen.getByRole('button', { name: /collection/i });
const newCollectionButton = screen.getAllByRole('button', { name: /collection/i })[4];
fireEvent.click(newCollectionButton);
const collectionModalHeading = await screen.findByRole('heading', { name: /new collection/i });
expect(collectionModalHeading).toBeInTheDocument();
@@ -614,7 +614,7 @@ describe('<LibraryAuthoringPage />', () => {
expect(screen.getByText(/add content/i)).toBeInTheDocument();

// Open New collection Modal
const newCollectionButton = screen.getByRole('button', { name: /collection/i });
const newCollectionButton = screen.getAllByRole('button', { name: /collection/i })[4];
fireEvent.click(newCollectionButton);
const collectionModalHeading = await screen.findByRole('heading', { name: /new collection/i });
expect(collectionModalHeading).toBeInTheDocument();
@@ -647,7 +647,7 @@ describe('<LibraryAuthoringPage />', () => {
expect(screen.getByText(/add content/i)).toBeInTheDocument();

// Open New collection Modal
const newCollectionButton = screen.getByRole('button', { name: /collection/i });
const newCollectionButton = screen.getAllByRole('button', { name: /collection/i })[4];
fireEvent.click(newCollectionButton);
const collectionModalHeading = await screen.findByRole('heading', { name: /new collection/i });
expect(collectionModalHeading).toBeInTheDocument();
@@ -661,4 +661,20 @@ describe('<LibraryAuthoringPage />', () => {
fireEvent.change(descriptionField, { target: { value: description } });
fireEvent.click(createButton);
});

it('shows both components and collections in recently modified section', async () => {
await renderLibraryPage();

expect(await screen.findByText('Content library')).toBeInTheDocument();
expect((await screen.findAllByText(libraryTitle))[0]).toBeInTheDocument();

// "Recently Modified" header + sort shown
expect(screen.getAllByText('Recently Modified').length).toEqual(2);
const recentModifiedContainer = (await screen.findAllByText('Recently Modified'))[1].parentElement?.parentElement?.parentElement;
expect(recentModifiedContainer).toBeTruthy();

const container = within(recentModifiedContainer!);
expect(container.queryAllByText('Text').length).toBeGreaterThan(0);
expect(container.queryAllByText('Collection').length).toBeGreaterThan(0);
});
});
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ import { ToastContext } from '../../generic/toast-context';
const CreateCollectionModal = () => {
const intl = useIntl();
const { libraryId } = useParams();
const create = useCreateLibraryCollection(libraryId);
const create = useCreateLibraryCollection(libraryId!);
const {
isCreateCollectionModalOpen,
closeCreateCollectionModal,
13 changes: 3 additions & 10 deletions src/library-authoring/data/apiHooks.ts
Original file line number Diff line number Diff line change
@@ -216,19 +216,12 @@ export const useUpdateXBlockFields = (contentLibraryId: string, usageKey: string
/**
* Use this mutation to create a library collection
*/
export const useCreateLibraryCollection = (libraryId: string | undefined) => {
export const useCreateLibraryCollection = (libraryId: string) => {
const queryClient = useQueryClient();
return useMutation({
mutationFn: (data: CreateLibraryCollectionDataRequest) => {
if (libraryId) {
return createCollection(libraryId, data);
}
return Promise.resolve();
},
mutationFn: (data: CreateLibraryCollectionDataRequest) => createCollection(libraryId, data),
onSettled: () => {
if (libraryId) {
queryClient.invalidateQueries({ predicate: (query) => libraryQueryPredicate(query, libraryId) });
}
queryClient.invalidateQueries({ predicate: (query) => libraryQueryPredicate(query, libraryId) });
},
});
};

Unchanged files with check annotations Beta

openInfoSidebar: () => {},
openComponentInfoSidebar: (_usageKey: string) => {}, // eslint-disable-line @typescript-eslint/no-unused-vars
isCreateCollectionModalOpen: false,
openCreateCollectionModal: () => {},
closeCreateCollectionModal: () => {},

Check warning on line 30 in src/library-authoring/common/context.tsx

Codecov / codecov/patch

src/library-authoring/common/context.tsx#L29-L30

Added lines #L29 - L30 were not covered by tests
} as LibraryContextData);
/**
You are viewing a condensed version of this merge commit. You can view the full changes here.