-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: merge useContentTaxonomyTagsCount and useContentTagsCount
- Loading branch information
Showing
19 changed files
with
92 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 21 additions & 18 deletions
39
src/content-tags-drawer/tags-sidebar-controls/TagsSidebarHeader.test.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,39 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { IntlProvider } from '@edx/frontend-platform/i18n'; | ||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; | ||
import TagsSidebarHeader from './TagsSidebarHeader'; | ||
import { useContentTaxonomyTagsCount } from '../data/apiHooks'; | ||
|
||
jest.mock('../data/apiHooks', () => ({ | ||
useContentTaxonomyTagsCount: jest.fn(() => ({ | ||
isSuccess: false, | ||
data: 17, | ||
})), | ||
const mockGetTagsCount = jest.fn(); | ||
|
||
jest.mock('../../generic/data/api', () => ({ | ||
...jest.requireActual('../../generic/data/api'), | ||
getTagsCount: () => mockGetTagsCount(), | ||
})); | ||
|
||
jest.mock('react-router-dom', () => ({ | ||
...jest.requireActual('react-router-dom'), | ||
useParams: () => ({ blockId: '123' }), | ||
})); | ||
|
||
const queryClient = new QueryClient(); | ||
|
||
const RootWrapper = () => ( | ||
<IntlProvider locale="en" messages={{}}> | ||
<TagsSidebarHeader /> | ||
<QueryClientProvider client={queryClient}> | ||
<TagsSidebarHeader /> | ||
</QueryClientProvider> | ||
</IntlProvider> | ||
); | ||
|
||
describe('<TagsSidebarHeader>', () => { | ||
it('should not render count on loading', () => { | ||
it('should render count only after query is complete', async () => { | ||
let resolvePromise; | ||
mockGetTagsCount.mockReturnValueOnce(new Promise((resolve) => { resolvePromise = resolve; })); | ||
render(<RootWrapper />); | ||
expect(screen.getByRole('heading', { name: /unit tags/i })).toBeInTheDocument(); | ||
expect(screen.queryByText('17')).not.toBeInTheDocument(); | ||
}); | ||
|
||
it('should render count after query is complete', () => { | ||
useContentTaxonomyTagsCount.mockReturnValue({ | ||
isSuccess: true, | ||
data: 17, | ||
}); | ||
render(<RootWrapper />); | ||
expect(screen.getByRole('heading', { name: /unit tags/i })).toBeInTheDocument(); | ||
expect(screen.getByText('17')).toBeInTheDocument(); | ||
resolvePromise({ 123: 17 }); | ||
expect(await screen.findByText('17')).toBeInTheDocument(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...rse-outline/__mocks__/contentTagsCount.js → src/generic/__mocks__/contentTagsCount.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/* eslint-disable import/prefer-default-export */ | ||
export { default as contentTagsCountMock } from './contentTagsCount'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.