MCPcopy
hub / github.com/primer/react / render

Function render

packages/react/src/drafts/MarkdownEditor/MarkdownEditor.test.tsx:44–108  ·  view source on GitHub ↗
(ui: React.ReactElement)

Source from the content-addressed store, hash-verified

42const assertNotNull: <T>(t: T | null) => asserts t is T = t => expect(t).not.toBeNull()
43
44const render = async (ui: React.ReactElement) => {
45 const result = _render(ui)
46 // eslint-disable-next-line testing-library/await-async-events
47 const user = userEvent.setup()
48
49 const getInput = () => result.getByRole('textbox') as HTMLTextAreaElement
50
51 const getToolbar = () => result.getByRole('toolbar')
52
53 const getFooter = () => result.getByRole('contentinfo')
54
55 const getToolbarButton = (label: string) => within(getToolbar()).getByRole('button', {name: label})
56
57 const queryForToolbarButton = (label: string) => within(getToolbar()).queryByRole('button', {name: label})
58
59 const getActionButton = (label: string) => within(getFooter()).getByRole('button', {name: label})
60
61 const getViewSwitch = () => {
62 const button = result.queryByRole('tab', {name: 'Preview'}) || result.queryByRole('tab', {name: 'Edit'})
63 if (!button) throw new Error('View switch button not found')
64 return button
65 }
66
67 const queryForPreview = () =>
68 result.queryByRole('heading', {name: 'Rendered Markdown Preview'})?.parentElement ?? null
69
70 const getPreview = () => {
71 const previewContainer = result.getByRole('heading', {name: 'Rendered Markdown Preview'}).parentElement
72 assertNotNull(previewContainer)
73 return previewContainer
74 }
75
76 const getEditorContainer = () => result.getByRole('group')
77
78 const queryForUploadButton = () =>
79 result.queryByRole('button', {name: 'Add files'}) ||
80 result.queryByRole('button', {name: 'Paste, drop, or click to add files'})
81
82 const queryForSuggestionsList = () => result.queryByRole('listbox')
83
84 const getSuggestionsList = () => result.getByRole('listbox')
85
86 const getAllSuggestions = () => within(getSuggestionsList()).queryAllByRole('option')
87
88 // Wait for the double render caused by slots to complete
89 await waitFor(() => result.getByText('Test Editor'))
90
91 return {
92 ...result,
93 getInput,
94 getToolbar,
95 getToolbarButton,
96 user,
97 queryForUploadButton,
98 getFooter,
99 getViewSwitch,
100 getPreview,
101 queryForPreview,

Calls

no outgoing calls

Tested by

no test coverage detected