|
| 1 | +import React, { useReducer} from 'react'; |
| 2 | +import '@testing-library/jest-dom'; |
| 3 | +import { DndProvider } from 'react-dnd'; |
| 4 | +import { HTML5Backend } from 'react-dnd-html5-backend'; |
| 5 | +import { render, fireEvent, cleanup, screen } from '@testing-library/react'; |
| 6 | + |
| 7 | +import StateContext from '../app/src/context/context'; |
| 8 | +import initialState from '../app/src/context/initialState'; |
| 9 | +import reducer from '../app/src/reducers/componentReducer'; |
| 10 | +import HTMLPanel from '../app/src/components/left/HTMLPanel'; |
| 11 | + |
| 12 | + |
| 13 | +function Test() { |
| 14 | + const [state, dispatch] = useReducer(reducer, initialState); |
| 15 | + return ( |
| 16 | + <DndProvider backend={HTML5Backend}> |
| 17 | + <StateContext.Provider value={[state, dispatch]} > |
| 18 | + <HTMLPanel /> |
| 19 | + </StateContext.Provider> |
| 20 | + </DndProvider> |
| 21 | + ) |
| 22 | +} |
| 23 | + |
| 24 | + |
| 25 | +test('Renders HTMLPanel component', () => { |
| 26 | + render( |
| 27 | + <Test/> |
| 28 | + ); |
| 29 | + expect(screen.getAllByRole('textbox')).toHaveLength(2); |
| 30 | + // console.log(container.firstChild); |
| 31 | + expect(screen.getByText('Div')).toBeInTheDocument(); |
| 32 | + expect(screen.getByText('Image')).toBeInTheDocument(); |
| 33 | + expect(screen.getByText('Form')).toBeInTheDocument(); |
| 34 | + expect(screen.getByText('List')).toBeInTheDocument(); |
| 35 | + expect(screen.getByText('Button')).toBeInTheDocument(); |
| 36 | + expect(screen.getByText('Link')).toBeInTheDocument(); |
| 37 | + expect(screen.getByText('Paragraph')).toBeInTheDocument(); |
| 38 | + expect(screen.getByText('Header 1')).toBeInTheDocument(); |
| 39 | + expect(screen.getByText('Header 2')).toBeInTheDocument(); |
| 40 | + expect(screen.getByText('Span')).toBeInTheDocument(); |
| 41 | +}) |
| 42 | + |
| 43 | +test('Adds new custom element', () => { |
| 44 | + render( |
| 45 | + <Test/> |
| 46 | + ); |
| 47 | + |
| 48 | + fireEvent.change(screen.getAllByRole('textbox')[0], { |
| 49 | + target: { value: 'Testing' } |
| 50 | + }); |
| 51 | + fireEvent.change(screen.getAllByRole('textbox')[1], { |
| 52 | + target: { value: 'Testing' } |
| 53 | + }); |
| 54 | + |
| 55 | + fireEvent.click(screen.getByDisplayValue('Add Element')); |
| 56 | + |
| 57 | + expect(screen.getByText('Testing')).toBeInTheDocument(); |
| 58 | +}) |
| 59 | + |
0 commit comments