1
- import '@testing-library/jest-dom' ;
1
+ // @vitest -environment jsdom
2
2
3
+ import { describe , it , expect } from 'vitest'
3
4
import {
4
5
fireEvent ,
5
6
render ,
@@ -23,27 +24,28 @@ import React from 'react';
23
24
import StateManager from '../app/src/components/StateManagement/StateManagement' ;
24
25
import store from '../app/src/redux/store' ;
25
26
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 (
29
30
< Provider store = { store } >
30
31
< BottomTabs />
31
32
</ Provider >
32
33
) ;
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 ( ) ;
41
43
} ) ;
42
44
} ) ;
43
45
44
46
describe ( '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 (
47
49
< Provider store = { store } >
48
50
< ComponentPanel isThemeLight = { null } />
49
51
</ Provider >
@@ -54,18 +56,19 @@ describe('Creation Panel', () => {
54
56
await waitFor ( ( ) => {
55
57
expect (
56
58
screen . getByText ( 'Component name cannot be blank.' )
57
- ) . toBeInTheDocument ( ) ;
59
+ ) . toBeDefined ( ) ;
58
60
} ) ;
61
+ unmount ( ) ;
59
62
} ) ;
60
63
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 (
63
66
< Provider store = { store } >
64
67
< ComponentPanel isThemeLight = { null } />
65
68
</ Provider >
66
69
) ;
67
70
68
- fireEvent . change ( screen . getByLabelText ( 'Name: ' ) , {
71
+ fireEvent . change ( screen . getByLabelText ( 'Name' ) , {
69
72
target : {
70
73
value : '!@#'
71
74
}
@@ -76,12 +79,15 @@ describe('Creation Panel', () => {
76
79
await waitFor ( ( ) => {
77
80
expect (
78
81
screen . getByText ( 'Component name must start with a letter.' )
79
- ) . toBeInTheDocument ( ) ;
82
+ ) . toBeDefined ( ) ;
80
83
} ) ;
84
+ unmount ( ) ;
81
85
} ) ;
86
+ } )
82
87
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 (
85
91
< Provider store = { store } >
86
92
< HTMLPanel isThemeLight = { null } />
87
93
</ Provider >
@@ -92,22 +98,23 @@ describe('Creation Panel', () => {
92
98
await waitFor ( ( ) => {
93
99
expect ( screen . getAllByText ( '* Input cannot be blank. *' ) ) . toHaveLength ( 2 ) ;
94
100
} ) ;
101
+ unmount ( ) ;
95
102
} ) ;
96
103
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 (
99
106
< Provider store = { store } >
100
107
< HTMLPanel isThemeLight = { null } />
101
108
</ Provider >
102
109
) ;
103
110
104
- fireEvent . change ( screen . getByLabelText ( 'Element Name: ' ) , {
111
+ fireEvent . change ( screen . getByLabelText ( 'Element Name' ) , {
105
112
target : {
106
113
value : '!@#'
107
114
}
108
115
} ) ;
109
116
110
- fireEvent . change ( screen . getByLabelText ( 'Tag: ' ) , {
117
+ fireEvent . change ( screen . getByLabelText ( 'Tag' ) , {
111
118
target : {
112
119
value : '!@#'
113
120
}
@@ -120,49 +127,53 @@ describe('Creation Panel', () => {
120
127
screen . getAllByText ( '* Input must start with a letter. *' )
121
128
) . toHaveLength ( 2 ) ;
122
129
} ) ;
130
+ unmount ( ) ;
123
131
} ) ;
124
132
} ) ;
125
133
126
134
describe ( '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 (
129
137
< Provider store = { store } >
130
138
< ContextManager />
131
139
</ Provider >
132
140
) ;
133
141
expect ( screen . getAllByRole ( 'tab' ) ) . toHaveLength ( 3 ) ;
142
+ unmount ( ) ;
134
143
} ) ;
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 (
137
146
< Provider store = { store } >
138
147
< ContextManager />
139
148
</ Provider >
140
149
) ;
141
150
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 ( ) ;
145
155
} ) ;
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 (
148
158
< Provider store = { store } >
149
159
< ContextManager />
150
160
</ Provider >
151
161
) ;
152
162
153
163
fireEvent . click ( screen . getByText ( 'Assign' ) ) ;
154
- expect ( screen . getByText ( 'Contexts Consumed' ) ) . toBeInTheDocument ( ) ;
164
+ expect ( screen . getByText ( 'Contexts Consumed' ) ) . toBeDefined ( ) ;
155
165
const dropdown = screen . getByLabelText ( 'Select Component' ) ;
156
- expect ( dropdown ) . toBeInTheDocument ( ) ;
166
+ expect ( dropdown ) . toBeDefined ( ) ;
157
167
expect ( screen . getAllByRole ( 'button' ) ) . toHaveLength ( 1 ) ;
158
168
expect ( screen . getAllByRole ( 'combobox' ) ) . toHaveLength ( 2 ) ;
159
169
expect ( screen . getAllByRole ( 'table' ) ) . toHaveLength ( 2 ) ;
170
+ unmount ( ) ;
160
171
} ) ;
161
172
} ) ;
162
173
163
174
describe ( 'State Manager' , ( ) => {
164
- test ( 'Should render all containers' , ( ) => {
165
- render (
175
+ it ( 'Should render all containers' , ( ) => {
176
+ const { unmount } = render (
166
177
< Provider store = { store } >
167
178
< StateManager isThemeLight = { null } />
168
179
</ Provider >
@@ -171,63 +182,66 @@ describe('State Manager', () => {
171
182
expect ( screen . getAllByRole ( 'textbox' ) ) . toHaveLength ( 2 ) ;
172
183
expect ( screen . getAllByRole ( 'grid' ) ) . toHaveLength ( 3 ) ;
173
184
expect ( screen . getAllByRole ( 'columnheader' ) ) . toHaveLength ( 9 ) ;
185
+ unmount ( ) ;
174
186
} ) ;
175
187
176
- test ( 'Display tab should render correct elements' , ( ) => {
177
- render (
188
+ it ( 'Display tab should render correct elements' , ( ) => {
189
+ const { unmount } = render (
178
190
< Provider store = { store } >
179
191
< StateManager isThemeLight = { null } />
180
192
</ Provider >
181
193
) ;
182
194
fireEvent . click ( screen . getByText ( 'Display' ) ) ;
183
- expect ( screen . getByRole ( 'table' ) ) . toBeInTheDocument ( ) ;
195
+ expect ( screen . getByRole ( 'table' ) ) . toBeDefined ( ) ;
184
196
expect (
185
197
screen . getByText ( 'State Initialized in Current Component:' )
186
- ) . toBeInTheDocument ( ) ;
198
+ ) . toBeDefined ( ) ;
199
+ unmount ( ) ;
187
200
} ) ;
188
201
} ) ;
189
202
190
203
describe ( '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 (
193
206
< Provider store = { store } >
194
207
< BrowserRouter >
195
- < CustomizationPanel />
208
+ < CustomizationPanel isThemeLight = { true } />
196
209
</ BrowserRouter >
197
210
</ Provider >
198
211
) ;
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 ( ) ;
206
216
} ) ;
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 (
209
222
< Provider store = { store } >
210
223
< BrowserRouter >
211
224
< DndProvider backend = { HTML5Backend } >
212
225
< DragDropPanel />
213
226
< MainContainer />
214
- < CustomizationPanel />
227
+ < CustomizationPanel isThemeLight = { true } />
215
228
</ DndProvider >
216
229
</ BrowserRouter >
217
230
</ Provider >
218
231
) ;
219
232
const drop = screen . getByTestId ( 'drop' ) ;
220
233
const div = screen . getAllByText ( 'Div' ) [ 0 ] ;
221
- expect ( drop ) . toBeInTheDocument ( ) ;
222
- expect ( div ) . toBeInTheDocument ( ) ;
234
+ expect ( drop ) . toBeDefined ( ) ;
235
+ expect ( div ) . toBeDefined ( ) ;
223
236
fireEvent . dragStart ( div ) ;
224
237
fireEvent . dragEnter ( drop ) ;
225
238
fireEvent . dragOver ( drop ) ;
226
239
fireEvent . drop ( drop ) ;
227
240
//check if customization panel elements are rendering correctly
228
- const panel = screen . getByTestId ( 'customization' ) ;
241
+ const panel = screen . getAllByTestId ( 'customization' ) [ 0 ] ;
229
242
expect ( within ( panel ) . getAllByRole ( 'textbox' ) ) . toHaveLength ( 4 ) ;
230
243
// check dropdowns
231
- expect ( within ( panel ) . getAllByRole ( 'button' ) ) . toHaveLength ( 12 ) ;
244
+ expect ( within ( panel ) . getAllByRole ( 'button' ) ) . toHaveLength ( 6 ) ;
245
+ unmount ( ) ;
232
246
} ) ;
233
247
} ) ;
0 commit comments