forked from octokatherine/readme.so
-
Notifications
You must be signed in to change notification settings - Fork 0
/
editor.test.js
43 lines (34 loc) · 1.34 KB
/
editor.test.js
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
import { render, screen, cleanup } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import Editor from '../pages/editor'
import { en_EN } from '../data/section-templates-en_EN'
const mockTranslations = {
'editor-desktop-optimized': 'This site is optimized for desktop',
'editor-visit-desktop': 'Please visit readme.so on a desktop to create your readme!',
}
jest.mock('next-i18next', () => ({
useTranslation: () => ({
t: jest.fn().mockImplementation((cb) => mockTranslations[cb]),
}),
}))
describe('editor page', () => {
afterEach(cleanup)
it('should render', () => {
const { container } = render(<Editor sectionTemplate={en_EN} />)
expect(container).toBeInTheDocument()
})
it('should show DownloadModal component if showModal is true', () => {
global.URL.createObjectURL = jest.fn()
render(<Editor sectionTemplate={en_EN} />)
userEvent.click(screen.getByLabelText('Download Markdown'))
expect(screen.getByText('🎉')).toBeInTheDocument()
})
it('should add section', () => {
render(<Editor sectionTemplate={en_EN} />)
userEvent.click(screen.getByText(/FAQ/))
// selected sections
expect(screen.getByText('FAQ', { selector: 'p' })).toBeInTheDocument()
// sections to be selected
expect(screen.queryByText('FAQ', { selector: 'span' })).toBeNull()
})
})