Skip to content

Commit

Permalink
fix: Coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisChV committed Apr 22, 2024
1 parent cdaf7b5 commit b491d9b
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/content-tags-drawer/ContentTagsCollapsibleHelper.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ const useContentTagsCollapsibleHelper = (
if (isExplicit) {
traversal[tag].lineage = tagLineage;
}
} else {
} /* istanbul ignore next */ else {
traversal[tag].explicit = isExplicit;
traversal[tag].lineage = tagLineage;
}
Expand Down
19 changes: 11 additions & 8 deletions src/content-tags-drawer/ContentTagsDrawer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ const ContentTagsDrawer = ({ id, onClose }) => {
}, []);

useEffect(() => {
/* istanbul ignore next */
if (commitGlobalStagedTagsStatus === 'success') {
showToastAfterSave();
toReadMode();
Expand Down Expand Up @@ -162,14 +163,16 @@ const ContentTagsDrawer = ({ id, onClose }) => {
</div>
</Container>
)}
{toastMessage && (
<Toast
show
onClose={closeToast}
>
{toastMessage}
</Toast>
)}
{/* istanbul ignore next */
toastMessage && (
<Toast
show
onClose={closeToast}
>
{toastMessage}
</Toast>
)
}
</div>
</ContentTagsDrawerContext.Provider>
);
Expand Down
17 changes: 17 additions & 0 deletions src/content-tags-drawer/ContentTagsDrawer.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
useContentTaxonomyTagsData,
useContentData,
useTaxonomyTagsData,
useContentTaxonomyTagsUpdater,
} from './data/apiHooks';
import { getTaxonomyListData } from '../taxonomy/data/api';
import messages from './messages';
Expand Down Expand Up @@ -73,6 +74,10 @@ describe('<ContentTagsDrawer />', () => {
// By default, we mock the API call with a promise that never resolves.
// You can override this in specific test.
getTaxonomyListData.mockReturnValue(new Promise(() => {}));
useContentTaxonomyTagsUpdater.mockReturnValue({
isError: false,
mutate: mockMutate,
});
});

const setupMockDataForStagedTagsTesting = () => {
Expand Down Expand Up @@ -465,6 +470,18 @@ describe('<ContentTagsDrawer />', () => {
expect(screen.queryByRole('button', { name: /save/i })).not.toBeInTheDocument();
});

it('shows spinner when loading commit tags', async () => {
setupMockDataForStagedTagsTesting();
useContentTaxonomyTagsUpdater.mockReturnValue({
status: 'loading',
isError: false,
mutate: mockMutate,
});
render(<RootWrapper />);
expect(await screen.findByText('Taxonomy 1')).toBeInTheDocument();
expect(screen.getByRole('status')).toBeInTheDocument();
});

it('should test adding a content tag to the staged tags for a taxonomy', async () => {
setupMockDataForStagedTagsTesting();
render(<RootWrapper />);
Expand Down
3 changes: 3 additions & 0 deletions src/content-tags-drawer/ContentTagsDrawerHelper.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ const useContentTagsDrawerContext = (contentId) => {
}, [setStagedContentTags]);

// Open a collapsible of a taxonomy
/* istanbul ignore next */
const openCollapsible = React.useCallback((taxonomyId) => {
setColapsibleStates(prevStates => ({
...prevStates,
Expand All @@ -187,6 +188,7 @@ const useContentTagsDrawerContext = (contentId) => {
}, [setColapsibleStates]);

// Close a collapsible of a taxonomy
/* istanbul ignore next */
const closeCollapsible = React.useCallback((taxonomyId) => {
setColapsibleStates(prevStates => ({
...prevStates,
Expand Down Expand Up @@ -234,6 +236,7 @@ const useContentTagsDrawerContext = (contentId) => {
]);

// Build toast message and show toast after save drawer.
/* istanbul ignore next */
const showToastAfterSave = React.useCallback(() => {
const tagsAddedList = Object.values(globalStagedContentTags);
const tagsRemovedList = Object.values(globalStagedRemovedContentTags);
Expand Down
1 change: 1 addition & 0 deletions src/content-tags-drawer/common/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import React from 'react';
/** @typedef {import("../data/types.mjs").TagsInTaxonomy} TagsInTaxonomy */
/** @typedef {import("../data/types.mjs").StagedTagData} StagedTagData */

/* istanbul ignore next */
export const ContentTagsDrawerContext = React.createContext({
stagedContentTags: /** @type{Record<number, StagedTagData[]>} */ ({}),
globalStagedContentTags: /** @type{Record<number, StagedTagData[]>} */ ({}),
Expand Down

0 comments on commit b491d9b

Please sign in to comment.