Skip to content

Commit 7c82050

Browse files
authored
Merge pull request #15 from oslabs-beta/feature/testing
Feature/testing
2 parents 637049d + b1f61d6 commit 7c82050

25 files changed

+1715
-1000
lines changed

__tests__/BottomTabs.test.tsx

Lines changed: 73 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import '@testing-library/jest-dom';
1+
// @vitest-environment jsdom
22

3+
import { describe, it, expect } from 'vitest'
34
import {
45
fireEvent,
56
render,
@@ -23,27 +24,28 @@ import React from 'react';
2324
import StateManager from '../app/src/components/StateManagement/StateManagement';
2425
import 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

4446
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(
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

126134
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(
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

163174
describe('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

190203
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(
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
});

__tests__/DragAndDrop.test.tsx

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import '@testing-library/jest-dom';
2-
1+
// @viit-enviroment jsdom
2+
// import '@testing-library/jest-dom';
3+
import { describe, it, expect } from 'vitest';
34
import { fireEvent, render, screen } from '@testing-library/react';
45

56
import ComponentDrag from '../app/src/components/left/ComponentDrag';
@@ -21,42 +22,42 @@ function TestContext(component) {
2122
}
2223

2324
describe('Drag and Drop Side Panel', () => {
24-
test('Renders all HTML Element choices', () => {
25+
it('Renders all HTML Element choices', () => {
2526
render(TestContext(<DragDropPanel />));
26-
expect(screen.getByText('Div')).toBeInTheDocument();
27-
expect(screen.getByText('Img')).toBeInTheDocument();
28-
expect(screen.getByText('Form')).toBeInTheDocument();
29-
expect(screen.getByText('Button')).toBeInTheDocument();
30-
expect(screen.getByText('Link')).toBeInTheDocument();
31-
expect(screen.getByText('Paragraph')).toBeInTheDocument();
32-
expect(screen.getByText('Header 1')).toBeInTheDocument();
33-
expect(screen.getByText('Header 2')).toBeInTheDocument();
34-
expect(screen.getByText('Span')).toBeInTheDocument();
35-
expect(screen.getByText('Input')).toBeInTheDocument();
36-
expect(screen.getByText('Label')).toBeInTheDocument();
37-
expect(screen.getByText('Ordered List')).toBeInTheDocument();
38-
expect(screen.getByText('Unordered List')).toBeInTheDocument();
39-
expect(screen.getByText('Menu')).toBeInTheDocument();
40-
expect(screen.getByText('List')).toBeInTheDocument();
27+
expect(screen.getByText('Div')).toBeDefined();
28+
expect(screen.getByText('Img')).toBeDefined();
29+
expect(screen.getByText('Form')).toBeDefined();
30+
expect(screen.getByText('Button')).toBeDefined();
31+
expect(screen.getByText('Link')).toBeDefined();
32+
expect(screen.getByText('Paragraph')).toBeDefined();
33+
expect(screen.getByText('Header 1')).toBeDefined();
34+
expect(screen.getByText('Header 2')).toBeDefined();
35+
expect(screen.getByText('Span')).toBeDefined();
36+
expect(screen.getByText('Input')).toBeDefined();
37+
expect(screen.getByText('Label')).toBeDefined();
38+
expect(screen.getByText('Ordered List')).toBeDefined();
39+
expect(screen.getByText('Unordered List')).toBeDefined();
40+
expect(screen.getByText('Menu')).toBeDefined();
41+
expect(screen.getByText('List')).toBeDefined();
4142
expect(screen.queryByText('separator')).toBe(null);
4243
});
4344

44-
test('Renders all React Router Component choices', () => {
45+
it('Renders all React Router Component choices', () => {
4546
render(TestContext(<DragDropPanel />));
4647

47-
expect(screen.getByText('Switch')).toBeInTheDocument();
48-
expect(screen.getByText('Route')).toBeInTheDocument();
49-
expect(screen.getByText('LinkTo')).toBeInTheDocument();
48+
expect(screen.getAllByText('Switch')[0]).toBeDefined();
49+
expect(screen.getAllByText('Route')[0]).toBeDefined();
50+
expect(screen.getAllByText('LinkTo')[0]).toBeDefined();
5051
});
5152

52-
test.skip('Should render Roots Components and Reusbale components', () => {
53-
render(TestContext(<ComponentDrag />));
53+
it.skip('Should render Roots Components and Reusbale components', () => {
54+
render(TestContext(<ComponentDrag isThemeLight={true} isVisible={true} />));
5455

55-
expect(screen.getByText('Root Components')).toBeInTheDocument();
56-
expect(screen.getByText('Reusable Components')).toBeInTheDocument();
56+
expect(screen.getByText('Root Components')).toBeDefined();
57+
expect(screen.getByText('Reusable Components')).toBeDefined();
5758
});
5859

59-
test('test drag and drop', () => {
60+
it('test drag and drop', () => {
6061
render(
6162
TestContext(
6263
<>
@@ -66,13 +67,13 @@ describe('Drag and Drop Side Panel', () => {
6667
)
6768
);
6869
const drop = screen.getByTestId('drop');
69-
const div = screen.getByText('Div');
70-
expect(drop).toBeInTheDocument();
71-
expect(div).toBeInTheDocument();
70+
const div = screen.getAllByText('Div')[0];
71+
expect(drop).toBeDefined();
72+
expect(div).toBeDefined();
7273
fireEvent.dragStart(div);
7374
fireEvent.dragEnter(drop);
7475
fireEvent.dragOver(drop);
7576
fireEvent.drop(drop);
76-
expect(within(drop).getByText('div')).toBeInTheDocument();
77+
expect(within(drop).getByText('div')).toBeDefined();
7778
});
7879
});

0 commit comments

Comments
 (0)