|
1 | 1 | import { render } from '@testing-library/react'; |
| 2 | +import { getMockedImportedConstant } from '@src/test/__mocks__/common/constants/constants.mock'; |
2 | 3 | import { MockServicesProvider } from '@src/test/__mocks__/providers/ServicesProvider.mock'; |
3 | 4 | import { ModalComplexLookup } from '@components/ComplexLookupField/ModalComplexLookup'; |
4 | 5 | import { setInitialGlobalState } from '@src/test/__mocks__/store'; |
5 | 6 | import { useSearchState, useUIState, useMarcPreviewState } from '@src/store'; |
6 | | -import { ComplexLookupType, Authority } from '@common/constants/complexLookup.constants'; |
| 7 | +import * as ComplexLookupConstants from '@common/constants/complexLookup.constants'; |
7 | 8 | import { Modal } from '@components/Modal'; |
8 | 9 |
|
9 | 10 | jest.mock('@common/constants/build.constants', () => ({ IS_EMBEDDED_MODE: false })); |
@@ -56,14 +57,53 @@ jest.mock('@components/Modal', () => ({ |
56 | 57 | )), |
57 | 58 | })); |
58 | 59 |
|
| 60 | +const mockComplexLookupsConfig = getMockedImportedConstant(ComplexLookupConstants, 'COMPLEX_LOOKUPS_CONFIG'); |
| 61 | + |
| 62 | +mockComplexLookupsConfig({ |
| 63 | + authorities: { |
| 64 | + api: { |
| 65 | + endpoints: { |
| 66 | + base: '/contributor-authorities', |
| 67 | + }, |
| 68 | + }, |
| 69 | + segments: { |
| 70 | + primary: ['search'], |
| 71 | + }, |
| 72 | + labels: { |
| 73 | + modal: { |
| 74 | + title: { |
| 75 | + creator: 'creator.title', |
| 76 | + }, |
| 77 | + }, |
| 78 | + }, |
| 79 | + }, |
| 80 | + authoritiesSubject: { |
| 81 | + api: { |
| 82 | + endpoints: { |
| 83 | + base: '/subject-authorities', |
| 84 | + }, |
| 85 | + }, |
| 86 | + segments: { |
| 87 | + primary: ['search'], |
| 88 | + }, |
| 89 | + labels: { |
| 90 | + modal: { |
| 91 | + title: { |
| 92 | + subject: 'subject.title', |
| 93 | + }, |
| 94 | + }, |
| 95 | + }, |
| 96 | + }, |
| 97 | +}); |
| 98 | + |
59 | 99 | describe('ModalComplexLookup', () => { |
60 | 100 | const defaultProps = { |
61 | 101 | isOpen: true, |
62 | 102 | onAssign: jest.fn(), |
63 | 103 | onClose: jest.fn(), |
64 | 104 | value: 'test value', |
65 | | - assignEntityName: ComplexLookupType.ContributorAuthorities, |
66 | | - baseLabelType: Authority.Creator, |
| 105 | + assignEntityName: ComplexLookupConstants.ComplexLookupType.ContributorAuthorities, |
| 106 | + baseLabelType: ComplexLookupConstants.Authority.Creator, |
67 | 107 | }; |
68 | 108 | const mockStores = { |
69 | 109 | search: { |
@@ -142,4 +182,17 @@ describe('ModalComplexLookup', () => { |
142 | 182 | expect(mockStores.search.resetQuery).toHaveBeenCalled(); |
143 | 183 | }); |
144 | 184 | }); |
| 185 | + |
| 186 | + describe('ComplexLookupType handling', () => { |
| 187 | + it('uses ContributorAuthorities config by default', () => { |
| 188 | + renderComponent(); |
| 189 | + |
| 190 | + expect(Modal).toHaveBeenCalledWith( |
| 191 | + expect.objectContaining({ |
| 192 | + title: expect.anything(), |
| 193 | + }), |
| 194 | + {}, |
| 195 | + ); |
| 196 | + }); |
| 197 | + }); |
145 | 198 | }); |
0 commit comments