Skip to content

Commit 08b64d1

Browse files
authored
Merge pull request #11 from oslabs-beta/bryanna/reactTesting
Bryanna/react testing
2 parents 8d86092 + b33a199 commit 08b64d1

17 files changed

+1462
-8015
lines changed

__tests__/Header.test.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import React from 'react';
2+
import { render, screen, fireEvent } from '../src/test-utils.js';
3+
import '@testing-library/jest-dom/extend-expect';
4+
import Header from '../src/components/Header';
5+
6+
describe('Header', () => {
7+
test('renders Header component with Clear Project button with on click functionality', () => {
8+
const { getByTestId } = render(<Header />);
9+
const clearProjectButton = getByTestId('clear-project-button');
10+
expect(clearProjectButton).toBeInTheDocument();
11+
const mockFunction = jest.fn(() => true);
12+
fireEvent.click(clearProjectButton);
13+
expect(mockFunction()).toBe(true);
14+
});
15+
16+
test('renders Header component with light/dark mode Toggle with on click functionality', () => {
17+
const { getByTestId } = render(<Header />);
18+
const mockFunction = jest.fn(() => true);
19+
const themeToggle = getByTestId('toggle-theme-btn');
20+
expect(themeToggle).toBeInTheDocument();
21+
fireEvent.click(themeToggle);
22+
expect(mockFunction()).toBe(true);
23+
});
24+
});

__tests__/LeftPanel.test.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import React from 'react';
2+
import { render, screen, fireEvent } from '../src/test-utils.js';
3+
import '@testing-library/jest-dom/extend-expect';
4+
// import DnD from '../src/components/DnD';
5+
import CompCreator from '../src/components/CompCreator';
6+
import Tree from '../src/components/Tree';
7+
// import TreeRecursive from '../src/components/TreeRecursive';
8+
import TreeFile from '../src/components/TreeFile';
9+
10+
describe('Left Panel', () => {
11+
test('renders CompCreator component with input field and add button', () => {
12+
const { getByTestId } = render(<CompCreator />);
13+
expect(screen.getByText('React Component')).toBeInTheDocument();
14+
expect(screen.getByRole('textbox')).toBeInTheDocument();
15+
const addButton = getByTestId('add-button');
16+
expect(addButton).toBeInTheDocument();
17+
// const mockFunction = jest.fn(() => true);
18+
// fireEvent.click(addButton);
19+
// expect(mockFunction()).toBe(true);
20+
});
21+
22+
test('value of comp creator input field changes', () => {
23+
const { queryByPlaceholderText } = render(<CompCreator />);
24+
const input = queryByPlaceholderText('Component Name');
25+
fireEvent.change(input, { target: { value: 'test' } });
26+
expect(input.value).toBe('test');
27+
});
28+
29+
test('renders the tree component which displays file tree', () => {
30+
const { getByTestId } = render(<Tree />);
31+
expect(getByTestId('filetree')).toBeInTheDocument();
32+
});
33+
34+
// test('renders the tree folders with on click functionality', () => {
35+
// const { getByTestId } = render(<TreeRecursive />);
36+
// expect(getByTestId('folder')).toBeInTheDocument();
37+
// });
38+
39+
// test('renders the tree files with on click functionality', () => {
40+
// const { getByTestId } = render(<TreeFile />);
41+
// expect(getByTestId('file')).toBeInTheDocument();
42+
// });
43+
44+
//HAVING ISSUES WITH TESTS INVOLVING DND DUE TO PROVIDER/STORE ISSUE WITH REACT TESTING LIBRARY
45+
46+
// test('renders fflow logo with on click functionality', () => {
47+
// const { getByTestId } = render(<DnD />);
48+
// const appLogo = getByTestId('app-logo');
49+
// expect(appLogo).toBeInTheDocument();
50+
// const mockFunction = jest.fn(() => true);
51+
// fireEvent.click(appLogo);
52+
// expect(mockFunction()).toBe(true);
53+
// });
54+
55+
// test('renders tree component', () => {
56+
// render(<DnD />);
57+
// expect(screen.getByText('FOLDERS')).toBeInTheDocument();
58+
// });
59+
});

__tests__/Navigation.test.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import React from 'react';
2+
import { render, screen, fireEvent } from '../src/test-utils.js';
3+
import '@testing-library/jest-dom/extend-expect';
4+
import Navigation from '../src/components/Navigation';
5+
6+
describe('Navigation', () => {
7+
test('renders Navigation component with DnD icon button with on click functionality', () => {
8+
const { getByTestId } = render(<Navigation />);
9+
const dndButton = getByTestId('dnd-button');
10+
expect(dndButton).toBeInTheDocument();
11+
const mockFunction = jest.fn(() => true);
12+
fireEvent.click(dndButton);
13+
expect(mockFunction()).toBe(true);
14+
});
15+
16+
test('renders Navigation component with file tree icon button with on click functionality', () => {
17+
const { getByTestId } = render(<Navigation />);
18+
const fileTreeButton = getByTestId('filetree-button');
19+
expect(fileTreeButton).toBeInTheDocument();
20+
const mockFunction = jest.fn(() => true);
21+
fireEvent.click(fileTreeButton);
22+
expect(mockFunction()).toBe(true);
23+
});
24+
25+
test('renders Navigation component with save icon button with on click functionality', () => {
26+
const { getByTestId } = render(<Navigation />);
27+
const saveButton = getByTestId('save-button');
28+
expect(saveButton).toBeInTheDocument();
29+
const mockFunction = jest.fn(() => true);
30+
fireEvent.click(saveButton);
31+
expect(mockFunction()).toBe(true);
32+
});
33+
34+
test('renders Navigation component with export icon button with on click functionality', () => {
35+
const { getByTestId } = render(<Navigation />);
36+
const exportButton = getByTestId('export-button');
37+
expect(exportButton).toBeInTheDocument();
38+
const mockFunction = jest.fn(() => true);
39+
fireEvent.click(exportButton);
40+
expect(mockFunction()).toBe(true);
41+
});
42+
43+
test('renders Navigation component with trash icon button with on click functionality', () => {
44+
const { getByTestId } = render(<Navigation />);
45+
const trashButton = getByTestId('trash-button');
46+
expect(trashButton).toBeInTheDocument();
47+
const mockFunction = jest.fn(() => true);
48+
fireEvent.click(trashButton);
49+
expect(mockFunction()).toBe(true);
50+
});
51+
});

0 commit comments

Comments
 (0)