forked from SolidOS/solid-panes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathview.test.tsx
More file actions
44 lines (33 loc) · 1.34 KB
/
view.test.tsx
File metadata and controls
44 lines (33 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/* eslint-env jest */
import * as React from 'react'
import {
render,
fireEvent
} from '@testing-library/react'
import { View } from './view'
import { workaroundActError } from './actErrorWorkaround'
workaroundActError()
it('should properly render markdown', () => {
const { container } = render(<View markdown='Some **awesome** markdown' onSave={jest.fn()}/>)
expect(container).toMatchSnapshot()
})
describe('Edit mode', () => {
it('should properly render the edit form', () => {
const { container, getByRole } = render(<View markdown='Arbitrary markdown' onSave={jest.fn()}/>)
const editButton = getByRole('button')
editButton.click()
expect(container).toMatchSnapshot()
})
it('should call the onSave handler after saving the new content', () => {
const mockHandler = jest.fn().mockReturnValue(Promise.resolve())
const { getByRole, getByDisplayValue } = render(<View markdown='Arbitrary markdown' onSave={mockHandler}/>)
const editButton = getByRole('button')
editButton.click()
const textarea = getByDisplayValue('Arbitrary markdown')
fireEvent.change(textarea, { target: { value: 'Some _other_ markdown' } })
const renderButton = getByRole('button')
renderButton.click()
expect(mockHandler.mock.calls.length).toBe(1)
expect(mockHandler.mock.calls[0][0]).toBe('Some _other_ markdown')
})
})