Skip to content

Commit 90fa41e

Browse files
committed
Add taxonomies hook tests
Signed-off-by: guido <[email protected]>
1 parent 00a4a5d commit 90fa41e

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { fromPartial } from '@total-typescript/shoehorn';
2+
import EntitiesSearch from '@types';
3+
import { OrderedSet } from 'immutable';
4+
5+
import { describe, expect, it, jest } from '@jest/globals';
6+
7+
import { useEntityRecords } from '../../../../sources/js/src/hooks/use-entity-records';
8+
import { useQueryViewableTaxonomies } from '../../../../sources/js/src/hooks/use-query-viewable-taxonomies';
9+
10+
jest.mock('../../../../sources/js/src/hooks/use-entity-records', () => {
11+
return {
12+
useEntityRecords: jest.fn(),
13+
};
14+
});
15+
16+
describe('useQueryViewableTaxonomies', () => {
17+
it('should return the viewable taxonomies', () => {
18+
jest.mocked(useEntityRecords).mockReturnValue({
19+
isResolving: () => false,
20+
errored: () => false,
21+
succeed: () => true,
22+
records: () =>
23+
OrderedSet([
24+
fromPartial<EntitiesSearch.Taxonomy<'edit'>>({
25+
name: 'Category',
26+
visibility: {
27+
publicly_queryable: true,
28+
},
29+
}),
30+
fromPartial<EntitiesSearch.Taxonomy<'edit'>>({
31+
name: 'Tag',
32+
visibility: {
33+
publicly_queryable: true,
34+
},
35+
}),
36+
fromPartial<EntitiesSearch.Taxonomy<'edit'>>({
37+
name: 'Author',
38+
visibility: {
39+
publicly_queryable: false,
40+
},
41+
}),
42+
]),
43+
});
44+
45+
const taxonomies = useQueryViewableTaxonomies();
46+
expect(taxonomies.records().size).toEqual(2);
47+
for (const viewableTaxonomy of taxonomies.records()) {
48+
expect(viewableTaxonomy.visibility.publicly_queryable).toEqual(
49+
true
50+
);
51+
}
52+
});
53+
});

0 commit comments

Comments
 (0)