Skip to content

Commit

Permalink
fix: lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
navinkarkera committed Oct 10, 2024
1 parent 74c6891 commit 7e4d568
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,9 @@ const render = (ui: React.ReactElement) => baseRender(ui, {
extraWrapper: ({ children }) => <LibraryProvider libraryId="lib:OpenedX:CSPROB2">{ children }</LibraryProvider>,
});



mockLibraryBlockMetadata.applyMock();
mockContentTaxonomyTagsData.applyMock();


describe('<ComponentManagement />', () => {
beforeEach(() => {
initializeMocks();
Expand Down
12 changes: 5 additions & 7 deletions src/library-authoring/component-info/ManageCollections.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import fetchMock from 'fetch-mock-jest';

import userEvent from '@testing-library/user-event';
import MockAdapter from 'axios-mock-adapter/types';
import {
initializeMocks,
render as baseRender,
Expand All @@ -10,24 +12,20 @@ import mockCollectionsResults from '../__mocks__/collection-search.json';
import { mockContentSearchConfig } from '../../search-manager/data/api.mock';
import { mockLibraryBlockMetadata } from '../data/api.mocks';
import ManageCollections from './ManageCollections';
import userEvent from '@testing-library/user-event';
import { LibraryProvider } from '../common/context';
import MockAdapter from 'axios-mock-adapter/types';
import { getLibraryBlockCollectionsUrl } from '../data/api';

const render = (ui: React.ReactElement) => baseRender(ui, {
extraWrapper: ({ children }) => <LibraryProvider libraryId="lib:OpenedX:CSPROB2">{ children }</LibraryProvider>,
});


let axiosMock: MockAdapter;
let mockShowToast;

mockLibraryBlockMetadata.applyMock();
mockContentSearchConfig.applyMock();
const searchEndpoint = 'http://mock.meilisearch.local/multi-search';


describe('<ManageCollections />', () => {
beforeEach(() => {
const mocks = initializeMocks();
Expand All @@ -54,7 +52,7 @@ describe('<ManageCollections />', () => {
axiosMock.onPatch(url).reply(200);
render(<ManageCollections
usageKey={mockLibraryBlockMetadata.usageKeyWithCollections}
collections={[{ title: 'My first collection', key: 'my-first-collection'}]}
collections={[{ title: 'My first collection', key: 'my-first-collection' }]}
/>);
const manageBtn = await screen.findByRole('button', { name: 'Manage Collections' });
userEvent.click(manageBtn);
Expand All @@ -68,7 +66,7 @@ describe('<ManageCollections />', () => {
expect(axiosMock.history.patch.length).toEqual(1);
expect(mockShowToast).toHaveBeenCalledWith('Component collections updated');
expect(JSON.parse(axiosMock.history.patch[0].data)).toEqual({
collection_keys: [ "my-first-collection", "my-second-collection" ],
collection_keys: ['my-first-collection', 'my-second-collection'],
});
});
expect(screen.queryByRole('search')).not.toBeInTheDocument();
Expand All @@ -92,7 +90,7 @@ describe('<ManageCollections />', () => {
await waitFor(() => {
expect(axiosMock.history.patch.length).toEqual(1);
expect(JSON.parse(axiosMock.history.patch[0].data)).toEqual({
collection_keys: [ "my-second-collection" ],
collection_keys: ['my-second-collection'],
});
expect(mockShowToast).toHaveBeenCalledWith('Failed to update Component collections');
});
Expand Down
4 changes: 2 additions & 2 deletions src/library-authoring/component-info/ManageCollections.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useContext, useMemo, useState, useEffect } from 'react';
import { useContext, useState } from 'react';
import { FormattedMessage, useIntl } from '@edx/frontend-platform/i18n';
import {
Button, Icon, Scrollable, SelectableBox, Stack, StatefulButton, useCheckboxSetValues,
Expand Down Expand Up @@ -49,7 +49,7 @@ const CollectionsSelectableBox = ({ usageKey, collections, onClose }: Collection
}).catch(() => {
showToast(intl.formatMessage(messages.manageCollectionsToComponentFailed));
}).finally(() => {
setBtnState('default')
setBtnState('default');
onClose();
});
};
Expand Down
1 change: 1 addition & 0 deletions src/library-authoring/components/ComponentCard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const contentHit: ContentHit = {
created: 1722434322294,
modified: 1722434322294,
lastPublished: null,
collections: {},
};

const clipboardBroadcastChannelMock = {
Expand Down
2 changes: 1 addition & 1 deletion src/library-authoring/data/api.mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ mockLibraryBlockMetadata.dataWithCollections = {
created: '2024-06-20T13:54:21Z',
modified: '2024-06-21T13:54:21Z',
tagsCount: 0,
collections: [{ title: 'My first collection', key: 'my-first-collection'}],
collections: [{ title: 'My first collection', key: 'my-first-collection' }],
} satisfies api.LibraryBlockMetadata;
/** Apply this mock. Returns a spy object that can tell you if it's been called. */
mockLibraryBlockMetadata.applyMock = () => jest.spyOn(api, 'getLibraryBlockMetadata').mockImplementation(mockLibraryBlockMetadata);
Expand Down

0 comments on commit 7e4d568

Please sign in to comment.