-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
115 additions
and
1 deletion.
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
27 changes: 27 additions & 0 deletions
27
src/test/__tests__/components/PreviewExternalResourceControls.test.tsx
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,27 @@ | ||
import { PreviewExternalResourceControls } from '@components/PreviewExternalResourceControls'; | ||
import { fireEvent, screen } from '@testing-library/dom'; | ||
import { render } from '@testing-library/react'; | ||
import { RecoilRoot } from 'recoil'; | ||
|
||
const navigate = jest.fn(); | ||
|
||
jest.mock('react-router-dom', () => ({ | ||
...jest.requireActual('react-router-dom'), | ||
useNavigate: () => navigate, | ||
})); | ||
|
||
describe('PreviewExternalResourceControls', () => { | ||
beforeEach(() => | ||
render( | ||
<RecoilRoot> | ||
<PreviewExternalResourceControls /> | ||
</RecoilRoot>, | ||
), | ||
); | ||
|
||
test('navigates back', () => { | ||
fireEvent.click(screen.getByTestId('close-external-preview-button')); | ||
|
||
expect(navigate).toHaveBeenCalled(); | ||
}); | ||
}); |
37 changes: 37 additions & 0 deletions
37
src/test/__tests__/components/PreviewExternalResourcePane.test.tsx
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,37 @@ | ||
import { PreviewExternalResourcePane } from '@components/PreviewExternalResourcePane'; | ||
import state from '@state'; | ||
import { fireEvent, screen } from '@testing-library/dom'; | ||
import { render } from '@testing-library/react'; | ||
import { RecoilRoot } from 'recoil'; | ||
|
||
const navigate = jest.fn(); | ||
const getRecordTitle = jest.fn(); | ||
|
||
jest.mock('react-router-dom', () => ({ | ||
...jest.requireActual('react-router-dom'), | ||
useNavigate: () => navigate, | ||
})); | ||
|
||
jest.mock('@common/helpers/record.helper', () => ({ | ||
getRecordTitle: () => getRecordTitle(), | ||
})); | ||
|
||
describe('PreviewExternalResourcePane', () => { | ||
beforeEach(() => | ||
render( | ||
<RecoilRoot initializeState={snapshot => snapshot.set(state.inputs.record, {})}> | ||
<PreviewExternalResourcePane /> | ||
</RecoilRoot>, | ||
), | ||
); | ||
|
||
test('invokes getRecordTitle', () => { | ||
expect(getRecordTitle).toHaveBeenCalled(); | ||
}); | ||
|
||
test('navigates back', () => { | ||
fireEvent.click(screen.getByTestId('nav-close-button')); | ||
|
||
expect(navigate).toHaveBeenCalled(); | ||
}); | ||
}); |
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,48 @@ | ||
import { fetchExternalRecordForPreview } from '@src/test/__mocks__/common/hooks/useRecordControls.mock'; | ||
import '@src/test/__mocks__/common/hooks/useRecordControls.mock'; | ||
import state from '@state'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { ExternalResourcePreview } from '@views'; | ||
import { Fragment, ReactNode } from 'react'; | ||
import { RecoilRoot } from 'recoil'; | ||
|
||
jest.mock('@common/constants/build.constants', () => ({ IS_EMBEDDED_MODE: false })); | ||
|
||
jest.mock('react-intl', () => ({ | ||
FormattedMessage: ({ id, values }: any) => { | ||
return ( | ||
<div id={id}> | ||
{Object.entries(values).map(([k, v]) => ( | ||
<Fragment key={k}>{v as ReactNode}</Fragment> | ||
))} | ||
</div> | ||
); | ||
}, | ||
})); | ||
|
||
describe('ExternalResourcePreview', () => { | ||
const renderComponent = (withRecord = false) => | ||
render( | ||
<RecoilRoot initializeState={snapshot => snapshot.set(state.inputs.record, withRecord ? {} : null)}> | ||
<ExternalResourcePreview /> | ||
</RecoilRoot>, | ||
); | ||
|
||
test('calls fetchExternalRecordForPreview on externalId change', () => { | ||
renderComponent(); | ||
|
||
expect(fetchExternalRecordForPreview).toHaveBeenCalled(); | ||
}); | ||
|
||
test('renders ExternalResourceLoader if no record is present', () => { | ||
renderComponent(); | ||
|
||
expect(screen.getByTestId('external-resource-loader')).toBeInTheDocument(); | ||
}); | ||
|
||
test('renders Preview if record is present', () => { | ||
renderComponent(true); | ||
|
||
expect(screen.getByTestId('preview-fields')).toBeInTheDocument(); | ||
}); | ||
}); |