-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add simple smoke tests for FileEditor
- Loading branch information
Showing
2 changed files
with
116 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import * as React from 'react' | ||
import renderer from 'react-test-renderer' | ||
import { renderHook } from '@testing-library/react-hooks' | ||
|
||
import AsyncResult from 'utils/AsyncResult' | ||
|
||
import { useState } from './State' | ||
import { Editor } from './FileEditor' | ||
|
||
jest.mock('utils/AWS', () => ({ S3: { use: () => {} } })) | ||
|
||
jest.mock('./Skeleton', () => () => <div>Skeleton</div>) | ||
|
||
jest.mock('utils/NamedRoutes', () => ({ | ||
...jest.requireActual('utils/NamedRoutes'), | ||
use: jest.fn(() => ({ urls: {} })), | ||
})) | ||
|
||
jest.mock( | ||
'react-router-dom', | ||
jest.fn(() => ({ | ||
...jest.requireActual('react-router-dom'), | ||
useParams: jest.fn(() => ({ bucket: 'b', key: 'k' })), | ||
useLocation: jest.fn(() => ({ search: '?edit=true' })), | ||
})), | ||
) | ||
|
||
jest.mock( | ||
'components/Preview/Display', | ||
jest.fn(() => () => <h1>Display error</h1>), | ||
) | ||
|
||
jest.mock( | ||
'components/Preview/loaders/utils', | ||
jest.fn(() => ({ | ||
...jest.requireActual('components/Preview/loaders/utils'), | ||
useObjectGetter: () => ({ | ||
case: (cases: any) => AsyncResult.case(cases, AsyncResult.Ok({ Body: 'body' })), | ||
}), | ||
})), | ||
) | ||
|
||
jest.mock( | ||
'./TextEditor', | ||
jest.fn(() => () => <h1>Text Editor</h1>), | ||
) | ||
|
||
jest.mock( | ||
'constants/config', | ||
jest.fn(() => ({})), | ||
) | ||
|
||
const loadMode = jest.fn((): 'fulfilled' => { | ||
throw Promise.resolve(null) | ||
}) | ||
|
||
jest.mock( | ||
'./loader', | ||
jest.fn(() => ({ | ||
loadMode: jest.fn(() => loadMode()), | ||
detect: () => 'text', | ||
useWriteData: () => {}, | ||
})), | ||
) | ||
|
||
describe('components/FileEditor/FileEditor', () => { | ||
describe('Editor', () => { | ||
const handle = { bucket: 'b', key: 'k' } | ||
const { result } = renderHook(() => useState(handle)) | ||
it('Show skeleton', () => { | ||
const tree = renderer | ||
.create( | ||
<Editor | ||
{...result.current} | ||
className="root" | ||
editing={{ brace: 'json' }} | ||
handle={handle} | ||
/>, | ||
) | ||
.toJSON() | ||
expect(tree).toMatchSnapshot() | ||
}) | ||
|
||
it('Show TextEditor', () => { | ||
loadMode.mockImplementation(() => 'fulfilled') | ||
const tree = renderer | ||
.create( | ||
<Editor | ||
{...result.current} | ||
className="root" | ||
editing={{ brace: 'json' }} | ||
handle={handle} | ||
/>, | ||
) | ||
.toJSON() | ||
expect(tree).toMatchSnapshot() | ||
}) | ||
}) | ||
}) |
17 changes: 17 additions & 0 deletions
17
catalog/app/components/FileEditor/__snapshots__/FileEditor.spec.tsx.snap
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,17 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`components/FileEditor/FileEditor Editor Show TextEditor 1`] = ` | ||
<div | ||
className="makeStyles-tab-1 makeStyles-active-2" | ||
> | ||
<h1> | ||
Text Editor | ||
</h1> | ||
</div> | ||
`; | ||
|
||
exports[`components/FileEditor/FileEditor Editor Show skeleton 1`] = ` | ||
<div> | ||
Skeleton | ||
</div> | ||
`; |