|
| 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