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 10, 2024
commit af89cf316722e47a6a6758b422caef97834c4209
24 changes: 12 additions & 12 deletions src/library-authoring/LibraryAuthoringPage.test.tsx
Original file line number Diff line number Diff line change
@@ -10,13 +10,9 @@ import {
import { getContentSearchConfigUrl } from '../search-manager/data/api';
import mockResult from './__mocks__/library-search.json';
import mockEmptyResult from '../search-modal/__mocks__/empty-search-result.json';
import {
getContentLibraryApiUrl,
getLibraryCollectionsApiUrl,
getXBlockFieldsApiUrl,
type ContentLibrary,
} from './data/api';
import { mockContentLibrary, mockLibraryBlockTypes, mockXBlockFields } from './data/api.mocks';
import { LibraryLayout } from '.';
import { getLibraryCollectionsApiUrl } from './data/api';

mockContentLibrary.applyMock();
mockLibraryBlockTypes.applyMock();
@@ -525,16 +521,17 @@ describe('<LibraryAuthoringPage />', () => {
});

it('should create a collection', async () => {
await renderLibraryPage();
const title = 'This is a Test';
const description = 'This is the description of the Test';
const url = getLibraryCollectionsApiUrl(libraryData.id);
const url = getLibraryCollectionsApiUrl(mockContentLibrary.libraryId);
const { axiosMock } = initializeMocks();
axiosMock.onPost(url).reply(200, {
id: '1',
slug: 'this-is-a-test',
title,
description,
});
await renderLibraryPage();

expect(await screen.findByRole('heading')).toBeInTheDocument();
expect(screen.queryByText(/add content/i)).not.toBeInTheDocument();
@@ -567,16 +564,18 @@ describe('<LibraryAuthoringPage />', () => {
});

it('should show validations in create collection', async () => {
await renderLibraryPage();

const title = 'This is a Test';
const description = 'This is the description of the Test';
const url = getLibraryCollectionsApiUrl(libraryData.id);
const url = getLibraryCollectionsApiUrl(mockContentLibrary.libraryId);
const { axiosMock } = initializeMocks();
axiosMock.onPost(url).reply(200, {
id: '1',
slug: 'this-is-a-test',
title,
description,
});
await renderLibraryPage();

expect(await screen.findByRole('heading')).toBeInTheDocument();
expect(screen.queryByText(/add content/i)).not.toBeInTheDocument();
@@ -600,11 +599,12 @@ describe('<LibraryAuthoringPage />', () => {
});

it('should show error on create collection', async () => {
await renderLibraryPage();
const title = 'This is a Test';
const description = 'This is the description of the Test';
const url = getLibraryCollectionsApiUrl(libraryData.id);
const url = getLibraryCollectionsApiUrl(mockContentLibrary.libraryId);
const { axiosMock } = initializeMocks();
axiosMock.onPost(url).reply(500);
await renderLibraryPage();

expect(await screen.findByRole('heading')).toBeInTheDocument();
expect(screen.queryByText(/add content/i)).not.toBeInTheDocument();
1 change: 0 additions & 1 deletion src/library-authoring/common/context.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable react/require-default-props */
import { useToggle } from '@openedx/paragon';
import React from 'react';

@@ -27,8 +26,8 @@
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);

/**
19 changes: 5 additions & 14 deletions src/library-authoring/data/api.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
import MockAdapter from 'axios-mock-adapter';
import { initializeMockApp } from '@edx/frontend-platform';
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth';
import {
commitLibraryChanges,
createCollection,
createLibraryBlock,
getCommitLibraryChangesUrl,
getCreateLibraryBlockUrl,
getLibraryCollectionsApiUrl,
revertLibraryChanges,
} from './api';
import { initializeMocks } from '../../testUtils';
import * as api from './api';

describe('library data API', () => {
describe('createLibraryBlock', () => {
@@ -55,12 +45,13 @@ describe('library data API', () => {
});

it('should create collection', async () => {
const { axiosMock } = initializeMocks();
const libraryId = 'lib:org:1';
const url = getLibraryCollectionsApiUrl(libraryId);
const url = api.getLibraryCollectionsApiUrl(libraryId);

axiosMock.onPost(url).reply(200);

await createCollection(libraryId, {
await api.createCollection(libraryId, {
title: 'This is a test',
description: 'This is only a test',
});

Unchanged files with check annotations Beta

if (libraryId) {
return createCollection(libraryId, data);
}
return Promise.resolve();

Check warning on line 226 in src/library-authoring/data/apiHooks.ts

Codecov / codecov/patch

src/library-authoring/data/apiHooks.ts#L226

Added line #L226 was not covered by tests
},
onSettled: () => {
if (libraryId) {
You are viewing a condensed version of this merge commit. You can view the full changes here.