-
Notifications
You must be signed in to change notification settings - Fork 0
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
13 changed files
with
265 additions
and
18 deletions.
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
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 |
---|---|---|
|
@@ -27,7 +27,7 @@ | |
tr { | ||
padding: 0.5rem 0 | ||
} | ||
|
||
// text-decoration: underline; | ||
.button-primary { | ||
margin: 0.2rem 0; | ||
} | ||
|
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
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
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
39 changes: 39 additions & 0 deletions
39
src/test/__tests__/common/hooks/useProcessedRecordAndSchema.test.ts
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,39 @@ | ||
import '@src/test/__mocks__/common/hooks/useServicesContext.mock'; | ||
import { useProcessedRecordAndSchema } from '@common/hooks/useProcessedRecordAndSchema.hook'; | ||
import { act, renderHook } from '@testing-library/react'; | ||
import { useSetRecoilState } from 'recoil'; | ||
|
||
jest.mock('recoil'); | ||
|
||
describe('useProcessedRecordAndSchema', () => { | ||
const mockSetState = jest.fn(); | ||
const props = { | ||
baseSchema: {} as Schema, | ||
userValues: {}, | ||
record: { key: 'value' }, | ||
}; | ||
|
||
beforeEach(() => { | ||
(useSetRecoilState as jest.Mock).mockReturnValueOnce(mockSetState).mockReturnValueOnce(jest.fn()); | ||
}); | ||
|
||
test("doesn't update state when asked not to", () => { | ||
const { result } = renderHook(useProcessedRecordAndSchema); | ||
|
||
act(() => { | ||
result.current.getProcessedRecordAndSchema({ ...props, noStateUpdate: true }); | ||
}); | ||
|
||
expect(mockSetState).not.toHaveBeenCalled(); | ||
}); | ||
|
||
test('updates state when not asked to not update state', () => { | ||
const { result } = renderHook(useProcessedRecordAndSchema); | ||
|
||
act(() => { | ||
result.current.getProcessedRecordAndSchema(props); | ||
}); | ||
|
||
expect(mockSetState).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,75 @@ | ||
import '@src/test/__mocks__/common/hooks/useRecordControls.mock'; | ||
import '@src/test/__mocks__/common/hooks/useNavigateToEditPage.mock'; | ||
import { navigateToEditPage } from '@src/test/__mocks__/common/hooks/useNavigateToEditPage.mock'; | ||
import { getRecordAndInitializeParsing } from '@src/test/__mocks__/common/hooks/useRecordControls.mock'; | ||
import * as RecordFormatter from '@common/helpers/recordFormatting.helper'; | ||
import { InstancesList } from '@components/InstancesList'; | ||
import { fireEvent, render } from '@testing-library/react'; | ||
import { BrowserRouter } from 'react-router-dom'; | ||
|
||
jest.mock('recoil'); | ||
jest.mock('@common/constants/build.constants', () => ({ IS_EMBEDDED_MODE: true })); | ||
|
||
describe('InstancesList', () => { | ||
const renderWithProps = () => { | ||
const contents = [ | ||
{ | ||
__meta: { | ||
id: 'mockId', | ||
key: 'mockId', | ||
}, | ||
title: { | ||
label: 'mockTitle', | ||
}, | ||
publisher: { | ||
label: 'mockPubName', | ||
}, | ||
pubDate: { | ||
label: 'mockPubDate', | ||
}, | ||
}, | ||
]; | ||
|
||
jest.spyOn(RecordFormatter, 'formatDependeciesTable').mockReturnValue(contents); | ||
|
||
return render( | ||
<BrowserRouter> | ||
<InstancesList | ||
contents={{ keys: { uri: 'mockUri' }, entries: [{ key: 'value' }] }} | ||
type="mockType" | ||
refId="mockRefId" | ||
/> | ||
, | ||
</BrowserRouter>, | ||
); | ||
}; | ||
test("renders table when there's content", () => { | ||
const { getByText } = renderWithProps(); | ||
|
||
expect(getByText('mockTitle')).toBeInTheDocument(); | ||
}); | ||
|
||
test('invokes new instance control', () => { | ||
const { getByTestId } = renderWithProps(); | ||
|
||
fireEvent.click(getByTestId('new-instance')); | ||
|
||
expect(navigateToEditPage).toHaveBeenCalled(); | ||
}); | ||
|
||
test('invokes preview control', () => { | ||
const { getByTestId } = renderWithProps(); | ||
|
||
fireEvent.click(getByTestId('preview-button__mockId')); | ||
|
||
expect(getRecordAndInitializeParsing).toHaveBeenCalled(); | ||
}); | ||
|
||
test('invokes edit control', () => { | ||
const { getByTestId } = renderWithProps(); | ||
|
||
fireEvent.click(getByTestId('edit-button__mockId')); | ||
|
||
expect(navigateToEditPage).toHaveBeenCalled(); | ||
}); | ||
}); |
Oops, something went wrong.