1- import '@testing-library/jest-dom' ;
1+ // @vitest -environment jsdom
22
3+ import { describe , it , expect } from 'vitest'
34import {
45 fireEvent ,
56 render ,
@@ -23,27 +24,28 @@ import React from 'react';
2324import StateManager from '../app/src/components/StateManagement/StateManagement' ;
2425import store from '../app/src/redux/store' ;
2526
26- describe ( 'Bottom Panel Render Test ' , ( ) => {
27- test ( 'should render all six tabs' , ( ) => {
28- render (
27+ describe ( 'Bottom Panel Render test ' , ( ) => {
28+ it ( 'should render all six tabs' , ( ) => {
29+ const { unmount } = render (
2930 < Provider store = { store } >
3031 < BottomTabs />
3132 </ Provider >
3233 ) ;
33- expect ( screen . getAllByRole ( 'tab' ) ) . toHaveLength ( 6 ) ;
34- // expect(screen.getByText('Code Preview')).toBeInTheDocument();
35- expect ( screen . getByText ( 'Component Tree' ) ) . toBeInTheDocument ( ) ;
36- expect ( screen . getByText ( 'Creation Panel' ) ) . toBeInTheDocument ( ) ;
37- expect ( screen . getByText ( 'Customization' ) ) . toBeInTheDocument ( ) ;
38- expect ( screen . getByText ( 'CSS Editor' ) ) . toBeInTheDocument ( ) ;
39- expect ( screen . getByText ( 'Context Manager' ) ) . toBeInTheDocument ( ) ;
40- expect ( screen . getByText ( 'State Manager' ) ) . toBeInTheDocument ( ) ;
34+ expect ( screen . getAllByRole ( 'tab' ) ) . toHaveLength ( 8 ) ;
35+ expect ( screen . getByText ( 'Component Tree' ) ) . toBeDefined ( ) ;
36+ expect ( screen . getByText ( 'Creation Panel' ) ) . toBeDefined ( ) ;
37+ expect ( screen . getByText ( 'Customization' ) ) . toBeDefined ( ) ;
38+ expect ( screen . getByText ( 'CSS Editor' ) ) . toBeDefined ( ) ;
39+ expect ( screen . getByText ( 'Context Manager' ) ) . toBeDefined ( ) ;
40+ expect ( screen . getByText ( 'State Manager' ) ) . toBeDefined ( ) ;
41+ expect ( screen . getByText ( 'MUI Props' ) ) . toBeDefined ( ) ;
42+ unmount ( ) ;
4143 } ) ;
4244} ) ;
4345
4446describe ( 'Creation Panel' , ( ) => {
45- test ( 'should invalidate empty field in New Component name' , async ( ) => {
46- render (
47+ it ( 'should invalidate empty field in New Component name' , async ( ) => {
48+ const { unmount } = render (
4749 < Provider store = { store } >
4850 < ComponentPanel isThemeLight = { null } />
4951 </ Provider >
@@ -54,18 +56,19 @@ describe('Creation Panel', () => {
5456 await waitFor ( ( ) => {
5557 expect (
5658 screen . getByText ( 'Component name cannot be blank.' )
57- ) . toBeInTheDocument ( ) ;
59+ ) . toBeDefined ( ) ;
5860 } ) ;
61+ unmount ( ) ;
5962 } ) ;
6063
61- test ( 'should invalidate New Component name containing symbols' , async ( ) => {
62- render (
64+ it ( 'should invalidate New Component name containing symbols' , async ( ) => {
65+ const { unmount } = render (
6366 < Provider store = { store } >
6467 < ComponentPanel isThemeLight = { null } />
6568 </ Provider >
6669 ) ;
6770
68- fireEvent . change ( screen . getByLabelText ( 'Name: ' ) , {
71+ fireEvent . change ( screen . getByLabelText ( 'Name' ) , {
6972 target : {
7073 value : '!@#'
7174 }
@@ -76,12 +79,15 @@ describe('Creation Panel', () => {
7679 await waitFor ( ( ) => {
7780 expect (
7881 screen . getByText ( 'Component name must start with a letter.' )
79- ) . toBeInTheDocument ( ) ;
82+ ) . toBeDefined ( ) ;
8083 } ) ;
84+ unmount ( ) ;
8185 } ) ;
86+ } )
8287
83- test ( 'should invalidate empty field in HTML Tag tag' , async ( ) => {
84- render (
88+ describe ( 'HTML Panel' , ( ) => {
89+ it ( 'should invalidate empty field in HTML Tag tag' , async ( ) => {
90+ const { unmount } = render (
8591 < Provider store = { store } >
8692 < HTMLPanel isThemeLight = { null } />
8793 </ Provider >
@@ -92,22 +98,23 @@ describe('Creation Panel', () => {
9298 await waitFor ( ( ) => {
9399 expect ( screen . getAllByText ( '* Input cannot be blank. *' ) ) . toHaveLength ( 2 ) ;
94100 } ) ;
101+ unmount ( ) ;
95102 } ) ;
96103
97- test ( 'should invalidate HTML Element name containing symbols' , async ( ) => {
98- render (
104+ it ( 'should invalidate HTML Element name containing symbols' , async ( ) => {
105+ const { unmount } = render (
99106 < Provider store = { store } >
100107 < HTMLPanel isThemeLight = { null } />
101108 </ Provider >
102109 ) ;
103110
104- fireEvent . change ( screen . getByLabelText ( 'Element Name: ' ) , {
111+ fireEvent . change ( screen . getByLabelText ( 'Element Name' ) , {
105112 target : {
106113 value : '!@#'
107114 }
108115 } ) ;
109116
110- fireEvent . change ( screen . getByLabelText ( 'Tag: ' ) , {
117+ fireEvent . change ( screen . getByLabelText ( 'Tag' ) , {
111118 target : {
112119 value : '!@#'
113120 }
@@ -120,49 +127,53 @@ describe('Creation Panel', () => {
120127 screen . getAllByText ( '* Input must start with a letter. *' )
121128 ) . toHaveLength ( 2 ) ;
122129 } ) ;
130+ unmount ( ) ;
123131 } ) ;
124132} ) ;
125133
126134describe ( 'Context Manager' , ( ) => {
127- test ( 'should render Create/Edit, Assign, and Display tabs' , ( ) => {
128- render (
135+ it ( 'should render Create/Edit, Assign, and Display tabs' , ( ) => {
136+ const { unmount } = render (
129137 < Provider store = { store } >
130138 < ContextManager />
131139 </ Provider >
132140 ) ;
133141 expect ( screen . getAllByRole ( 'tab' ) ) . toHaveLength ( 3 ) ;
142+ unmount ( ) ;
134143 } ) ;
135- test ( 'Create/Edit Tab should contain all buttons, inputs field, and a data table' , ( ) => {
136- render (
144+ it ( 'Create/Edit Tab should contain all buttons, inputs field, and a data table' , ( ) => {
145+ const { unmount } = render (
137146 < Provider store = { store } >
138147 < ContextManager />
139148 </ Provider >
140149 ) ;
141150 expect ( screen . getAllByRole ( 'textbox' ) ) . toHaveLength ( 3 ) ;
142- expect ( screen . getAllByRole ( 'button' ) ) . toHaveLength ( 4 ) ;
143- expect ( screen . getByText ( 'Context Name' ) ) . toBeInTheDocument ( ) ;
144- expect ( screen . getByRole ( 'table' ) ) . toBeInTheDocument ( ) ;
151+ expect ( screen . getAllByRole ( 'button' ) ) . toHaveLength ( 3 ) ;
152+ expect ( screen . getByText ( 'Context Name' ) ) . toBeDefined ( ) ;
153+ expect ( screen . getByRole ( 'table' ) ) . toBeDefined ( ) ;
154+ unmount ( ) ;
145155 } ) ;
146- test ( 'Assign Tab should contain all buttons and input fields' , ( ) => {
147- render (
156+ it ( 'Assign Tab should contain all buttons and input fields' , ( ) => {
157+ const { unmount } = render (
148158 < Provider store = { store } >
149159 < ContextManager />
150160 </ Provider >
151161 ) ;
152162
153163 fireEvent . click ( screen . getByText ( 'Assign' ) ) ;
154- expect ( screen . getByText ( 'Contexts Consumed' ) ) . toBeInTheDocument ( ) ;
164+ expect ( screen . getByText ( 'Contexts Consumed' ) ) . toBeDefined ( ) ;
155165 const dropdown = screen . getByLabelText ( 'Select Component' ) ;
156- expect ( dropdown ) . toBeInTheDocument ( ) ;
166+ expect ( dropdown ) . toBeDefined ( ) ;
157167 expect ( screen . getAllByRole ( 'button' ) ) . toHaveLength ( 1 ) ;
158168 expect ( screen . getAllByRole ( 'combobox' ) ) . toHaveLength ( 2 ) ;
159169 expect ( screen . getAllByRole ( 'table' ) ) . toHaveLength ( 2 ) ;
170+ unmount ( ) ;
160171 } ) ;
161172} ) ;
162173
163174describe ( 'State Manager' , ( ) => {
164- test ( 'Should render all containers' , ( ) => {
165- render (
175+ it ( 'Should render all containers' , ( ) => {
176+ const { unmount } = render (
166177 < Provider store = { store } >
167178 < StateManager isThemeLight = { null } />
168179 </ Provider >
@@ -171,63 +182,66 @@ describe('State Manager', () => {
171182 expect ( screen . getAllByRole ( 'textbox' ) ) . toHaveLength ( 2 ) ;
172183 expect ( screen . getAllByRole ( 'grid' ) ) . toHaveLength ( 3 ) ;
173184 expect ( screen . getAllByRole ( 'columnheader' ) ) . toHaveLength ( 9 ) ;
185+ unmount ( ) ;
174186 } ) ;
175187
176- test ( 'Display tab should render correct elements' , ( ) => {
177- render (
188+ it ( 'Display tab should render correct elements' , ( ) => {
189+ const { unmount } = render (
178190 < Provider store = { store } >
179191 < StateManager isThemeLight = { null } />
180192 </ Provider >
181193 ) ;
182194 fireEvent . click ( screen . getByText ( 'Display' ) ) ;
183- expect ( screen . getByRole ( 'table' ) ) . toBeInTheDocument ( ) ;
195+ expect ( screen . getByRole ( 'table' ) ) . toBeDefined ( ) ;
184196 expect (
185197 screen . getByText ( 'State Initialized in Current Component:' )
186- ) . toBeInTheDocument ( ) ;
198+ ) . toBeDefined ( ) ;
199+ unmount ( ) ;
187200 } ) ;
188201} ) ;
189202
190203describe ( 'Customization Panel' , ( ) => {
191- test ( 'Should render customization container with no elements in Canvas' , ( ) => {
192- render (
204+ it ( 'Should render customization container with no elements in Canvas' , ( ) => {
205+ const { unmount } = render (
193206 < Provider store = { store } >
194207 < BrowserRouter >
195- < CustomizationPanel />
208+ < CustomizationPanel isThemeLight = { true } />
196209 </ BrowserRouter >
197210 </ Provider >
198211 ) ;
199- expect ( screen . getByText ( 'Parent Component:' ) ) . toBeInTheDocument ( ) ;
200- expect ( screen . getByText ( 'App' ) ) . toBeInTheDocument ( ) ;
201- expect (
202- screen . getByText (
203- 'Drag and drop an html element (or focus one) to see what happens!'
204- )
205- ) . toBeInTheDocument ( ) ;
212+ expect ( screen . getByText ( 'Parent Component:' ) ) . toBeDefined ( ) ;
213+ expect ( screen . getByText ( 'App' ) ) . toBeDefined ( ) ;
214+ expect ( screen . getByText ( 'Drag or click an html element to the canvas to see what happens!' ) ) . toBeDefined ( ) ;
215+ unmount ( ) ;
206216 } ) ;
207- test ( 'Should render all buttons and inputs when Canvas has element' , ( ) => {
208- render (
217+ } )
218+
219+ describe ( 'Canvas' , ( ) => {
220+ it ( 'Should render all buttons and inputs when Canvas has element' , async ( ) => {
221+ const { unmount } = render (
209222 < Provider store = { store } >
210223 < BrowserRouter >
211224 < DndProvider backend = { HTML5Backend } >
212225 < DragDropPanel />
213226 < MainContainer />
214- < CustomizationPanel />
227+ < CustomizationPanel isThemeLight = { true } />
215228 </ DndProvider >
216229 </ BrowserRouter >
217230 </ Provider >
218231 ) ;
219232 const drop = screen . getByTestId ( 'drop' ) ;
220233 const div = screen . getAllByText ( 'Div' ) [ 0 ] ;
221- expect ( drop ) . toBeInTheDocument ( ) ;
222- expect ( div ) . toBeInTheDocument ( ) ;
234+ expect ( drop ) . toBeDefined ( ) ;
235+ expect ( div ) . toBeDefined ( ) ;
223236 fireEvent . dragStart ( div ) ;
224237 fireEvent . dragEnter ( drop ) ;
225238 fireEvent . dragOver ( drop ) ;
226239 fireEvent . drop ( drop ) ;
227240 //check if customization panel elements are rendering correctly
228- const panel = screen . getByTestId ( 'customization' ) ;
241+ const panel = screen . getAllByTestId ( 'customization' ) [ 0 ] ;
229242 expect ( within ( panel ) . getAllByRole ( 'textbox' ) ) . toHaveLength ( 4 ) ;
230243 // check dropdowns
231- expect ( within ( panel ) . getAllByRole ( 'button' ) ) . toHaveLength ( 12 ) ;
244+ expect ( within ( panel ) . getAllByRole ( 'button' ) ) . toHaveLength ( 6 ) ;
245+ unmount ( ) ;
232246 } ) ;
233247} ) ;
0 commit comments