Skip to content

Commit a966129

Browse files
authored
Merge pull request #94 from oslabs-beta/master
Merge from beta
2 parents 037ea2b + ad53648 commit a966129

File tree

150 files changed

+7123
-4470
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

150 files changed

+7123
-4470
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,7 @@
2323
npm-debug.log*
2424
yarn-debug.log*
2525
yarn-error.log*
26+
27+
28+
#configuration
29+
.vscode

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@
8282
"eslint-plugin-jsx-a11y": "^6.2.3",
8383
"eslint-plugin-react": "^7.20.0",
8484
"eslint-plugin-react-hooks": "^2.5.1",
85-
"jest-dom": "^3.5.0",
8685
"react-test-renderer": "^16.12.0",
8786
"spectron": "^5.0.0",
8887
"test-data-bot": "^0.8.0"

public/electron.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
1-
require('dotenv').config()
21
const { app, BrowserWindow } = require('electron');
32
const path = require('path');
43
const isDev = require('electron-is-dev');
54
let mainWindow;
65

7-
if (process.env.NODE_ENV === 'development') {
8-
const { default: installExtension, REACT_DEVELOPER_TOOLS } = require('electron-devtools-installer');
6+
if (isDev) console.log('electron version', process.versions.electron);
7+
8+
if (isDev) {
9+
const {
10+
default: installExtension,
11+
REACT_DEVELOPER_TOOLS,
12+
} = require('electron-devtools-installer');
913
function addDevTools() {
1014
app.whenReady().then(() => {
11-
installExtension(REACT_DEVELOPER_TOOLS)
15+
installExtension(REACT_DEVELOPER_TOOLS)
1216
.then((name) => console.log(`Added Extension: ${name}`))
1317
.catch((err) => console.log('An error occurred: ', err));
14-
});
15-
};
18+
});
19+
}
1620
}
1721
function createWindow() {
1822
mainWindow = new BrowserWindow({
@@ -31,7 +35,7 @@ function createWindow() {
3135
mainWindow.on('closed', () => (mainWindow = null));
3236
}
3337

34-
if (process.env.NODE_ENV === 'development') {
38+
if (isDev) {
3539
app.on('ready', addDevTools);
3640
}
3741

@@ -45,4 +49,4 @@ app.on('activate', () => {
4549
if (mainWindow === null) {
4650
createWindow();
4751
}
48-
});
52+
});

src/App.jsx

Lines changed: 32 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,23 @@
11
import React, { useReducer } from 'react';
22
import styles from './App.module.scss';
33
import { GlobalContext, globalState, globalReducer } from './context/reducers/globalReducer';
4-
import { ReactTestCaseContext, reactTestCaseState, reactTestCaseReducer } from './context/reducers/reactTestCaseReducer';
5-
import {
6-
PuppeteerTestCaseContext,
7-
puppeteerTestCaseState,
8-
puppeteerTestCaseReducer,
9-
} from './context/reducers/puppeteerTestCaseReducer';
10-
import {
11-
EndpointTestCaseContext,
12-
endpointTestCaseState,
13-
endpointTestCaseReducer,
14-
} from './context/reducers/endpointTestCaseReducer';
15-
import {
16-
ReduxTestCaseContext,
17-
reduxTestCaseState,
18-
reduxTestCaseReducer,
19-
} from './context/reducers/reduxTestCaseReducer';
20-
import {
21-
HooksTestCaseContext,
22-
hooksTestCaseState,
23-
hooksTestCaseReducer,
24-
} from './context/reducers/hooksTestCaseReducer';
25-
import {
26-
TestFileModalContext,
27-
testFileModalState,
28-
testFileModalReducer,
29-
} from './context/reducers/testFileModalReducer';
30-
31-
import { MockDataContext, mockDataState, mockDataReducer } from './context/reducers/mockDataReducer';
324
import ProjectLoader from './pages/ProjectLoader/ProjectLoader';
335
import NavBar from './components/NavBar/NavBar';
346
import LeftPanel from './pages//LeftPanel/LeftPanel';
357
import RightPanel from './pages/RightPanel/RightPanel';
8+
import About from './pages/About/About';
369

3710
const App = () => {
38-
const [global, dispatchToGlobal] = useReducer(globalReducer, globalState);
39-
const [reactTestCase, dispatchToReactTestCase] = useReducer(reactTestCaseReducer, reactTestCaseState);
40-
const [mockData, dispatchToMockData] = useReducer(mockDataReducer, mockDataState);
41-
const [endpointTestCase, dispatchToEndpointTestCase] = useReducer(
42-
endpointTestCaseReducer,
43-
endpointTestCaseState
44-
);
45-
46-
const [reduxTestCase, dispatchToReduxTestCase] = useReducer(
47-
reduxTestCaseReducer,
48-
reduxTestCaseState
49-
);
50-
const [hooksTestCase, dispatchToHooksTestCase] = useReducer(
51-
hooksTestCaseReducer,
52-
hooksTestCaseState
53-
);
54-
const [puppeteerTestCase, dispatchToPuppeteerTestCase] = useReducer(
55-
puppeteerTestCaseReducer,
56-
puppeteerTestCaseState
57-
);
58-
const [testFileModal, dispatchToTestFileModal] = useReducer(
59-
testFileModalReducer,
60-
testFileModalState
61-
);
11+
// useReducer takes a reducer and initial state as
12+
// args and return the current state paired with a dispatch method
13+
// distpatchTo method invokes associated reducer function
6214

15+
const [global, dispatchToGlobal] = useReducer(globalReducer, globalState);
6316

6417
if (!global.isProjectLoaded) {
6518
return (
6619
<div>
20+
{/* pass global state and dispatch function as prop to context provider for child components */}
6721
<GlobalContext.Provider value={[global, dispatchToGlobal]}>
6822
<ProjectLoader />
6923
</GlobalContext.Provider>
@@ -72,7 +26,7 @@ const App = () => {
7226
} else {
7327
return (
7428
/**
75-
* Wrap the components that we want to share the unique states with (ex: share testCase state with navbar & left panel (the two containers that hold the components that need testCaseRducer)) in the unique providers (ex: TestCaseContext.Provider).
29+
* Wrap the components that we want to share the unique states with.
7630
* You can only provide one value to a Provider.
7731
* - In order to avoid creating separate Contexts, wrap multiples in an array (ex: testCase and dispatchToTestCase).
7832
*
@@ -83,28 +37,32 @@ const App = () => {
8337
*
8438
* We access the value that we gave to the Provider through useContext
8539
*/
86-
<div id={global.isFileDirectoryOpen ?
87-
(global.isRightPanelOpen? styles.fileDirectoryOpenRightPanelOpen : styles.fileDirectoryOpenRightPanelClosed) :
88-
(global.isRightPanelOpen? styles.fileDirectoryClosedRightPanelOpen : styles.fileDirectoryClosedRightPanelClosed)
89-
}>
40+
<div
41+
id={
42+
global.isProjectLoaded === 'about'
43+
? ''
44+
: global.isFileDirectoryOpen
45+
? global.isRightPanelOpen
46+
? styles.fileDirectoryOpenRightPanelOpen
47+
: styles.fileDirectoryOpenRightPanelClosed
48+
: global.isRightPanelOpen
49+
? styles.fileDirectoryClosedRightPanelOpen
50+
: styles.fileDirectoryClosedRightPanelClosed
51+
}
52+
>
9053
<GlobalContext.Provider value={[global, dispatchToGlobal]}>
91-
<ReduxTestCaseContext.Provider value={[reduxTestCase, dispatchToReduxTestCase]}>
92-
<ReactTestCaseContext.Provider value={[reactTestCase, dispatchToReactTestCase]}>
93-
<EndpointTestCaseContext.Provider value={[endpointTestCase, dispatchToEndpointTestCase]}>
94-
<HooksTestCaseContext.Provider value={[hooksTestCase, dispatchToHooksTestCase]}>
95-
<TestFileModalContext.Provider value={[testFileModal, dispatchToTestFileModal]}>
96-
<MockDataContext.Provider value={[mockData, dispatchToMockData]}>
97-
<PuppeteerTestCaseContext.Provider value={[puppeteerTestCase, dispatchToPuppeteerTestCase]}>
98-
<NavBar />
99-
<LeftPanel />
100-
</PuppeteerTestCaseContext.Provider>
101-
</MockDataContext.Provider>
102-
</TestFileModalContext.Provider>
103-
</HooksTestCaseContext.Provider>
104-
</EndpointTestCaseContext.Provider>
105-
</ReactTestCaseContext.Provider>
106-
</ReduxTestCaseContext.Provider>
107-
{global.isRightPanelOpen ? <RightPanel /> : ''}
54+
{global.isProjectLoaded === 'about' ? (
55+
<>
56+
<NavBar inAboutPage={true} />
57+
<About dispatch={dispatchToGlobal} />{' '}
58+
</>
59+
) : (
60+
<>
61+
<NavBar inAboutPage={false} />
62+
<LeftPanel />
63+
</>
64+
)}
65+
{global.isRightPanelOpen ? <RightPanel /> : ''}
10866
</GlobalContext.Provider>
10967
</div>
11068
);

src/__tests__/Action.test.jsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import React from 'react';
2-
import ReactDOM from 'react-dom';
32
import { render } from '@testing-library/react';
43
import '@testing-library/jest-dom/extend-expect';
54
import { ReactTestCaseContext } from '../context/reducers/reactTestCaseReducer';
65
import { MockDataContext } from '../context/reducers/mockDataReducer';
7-
import Action from '../components/Action/Action';
6+
import Action from '../components/ReactTestComponent/Action/Action';
87

98
const dispatchToReactTextCase = jest.fn();
109
const dispatchToMockData = jest.fn();
@@ -35,12 +34,12 @@ const mockDataState = {
3534
describe('Assertion ', () => {
3635
it('renders without crashing', () => {
3736
const div = document.createElement('div');
38-
ReactDOM.render(
37+
render(
3938
<ReactTestCaseContext.Provider value={[reactTestCaseState, dispatchToReactTextCase]}>
4039
<MockDataContext.Provider value={[mockDataState, dispatchToMockData]}>
4140
<Action {...reactTestCaseState} />
4241
</MockDataContext.Provider>
43-
</ReactTestCaseContext.Provider>, div,
42+
</ReactTestCaseContext.Provider>
4443
);
4544
});
4645
});

src/__tests__/Assertion.test.jsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import React from 'react';
2-
import ReactDOM from 'react-dom';
3-
import { render } from '@testing-library/react';
2+
import { render, screen } from '@testing-library/react';
43
import '@testing-library/jest-dom/extend-expect';
54
import { ReactTestCaseContext } from '../context/reducers/reactTestCaseReducer';
65
import { MockDataContext } from '../context/reducers/mockDataReducer';
7-
import Assertion from '../components/Assertion/Assertion';
6+
import Assertion from '../components/ReactTestComponent/Assertion/Assertion';
7+
import userEvent from '@testing-library/user-event';
88

99
const dispatchToReactTextCase = jest.fn();
1010
const dispatchToMockData = jest.fn();
@@ -35,13 +35,21 @@ const mockDataState = {
3535

3636
describe('Assertion ', () => {
3737
it('renders without crashing', () => {
38-
const div = document.createElement('div');
39-
ReactDOM.render(
38+
// const div = document.createElement('div');
39+
40+
const { getByText, getAllByRole, debug } = render(
4041
<ReactTestCaseContext.Provider value={[reactTestCaseState, dispatchToReactTextCase]}>
4142
<MockDataContext.Provider value={[mockDataState, dispatchToMockData]}>
4243
<Assertion {...reactTestCaseState} />
4344
</MockDataContext.Provider>
44-
</ReactTestCaseContext.Provider>, div,
45+
</ReactTestCaseContext.Provider>
4546
);
47+
expect(getByText('Assertion')).toBeInTheDocument;
48+
49+
expect(getAllByRole('textbox')).toBeInTheDocument;
50+
// expect()
51+
// expect(screen.getAllByRole('Query', { name: 'Query' })).toHaveValue('Hello,\nWorld!');
52+
53+
debug();
4654
});
4755
});

src/__tests__/Hooks.test.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { renderHook, act, cleanup } from '@testing-library/react-hooks';
2+
import useToggleModal from '../components/TestMenu/testMenuHooks';
3+
4+
afterEach(cleanup);
5+
test('hooks should render', () => {
6+
const { result } = renderHook(() => useToggleModal('redux'));
7+
expect(result.current.title).toBe('redux');
8+
expect(result.current.isModalOpen).toBe(false);
9+
expect(typeof result.current.openModal).toBe('function');
10+
});
11+
12+
test('openModal should work', () => {
13+
const { result } = renderHook(() => useToggleModal('redux'));
14+
15+
act(() => {
16+
result.current.openModal();
17+
});
18+
expect(result.current.title).toBe('New Test');
19+
expect(result.current.isModalOpen).toBe(true);
20+
});
21+
22+
test('openScriptModal should work', () => {
23+
const { result } = renderHook(() => useToggleModal('redux'));
24+
25+
act(() => {
26+
result.current.openScriptModal();
27+
});
28+
expect(result.current.title).toBe('redux');
29+
expect(result.current.isModalOpen).toBe(true);
30+
});
31+
32+
test('closeModal should work', () => {
33+
const { result } = renderHook(() => useToggleModal('redux'));
34+
35+
act(() => {
36+
result.current.closeModal();
37+
});
38+
expect(result.current.title).toBe('redux');
39+
expect(result.current.isModalOpen).toBe(false);
40+
});
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
window.require = jest.fn();
2+
3+
import { actionTypes, ReduxTestCaseState } from '../utils/reduxTypes';
4+
5+
import React from 'react';
6+
import { render, screen } from '@testing-library/react';
7+
import '@testing-library/jest-dom/extend-expect';
8+
import { ReduxTestCaseContext } from '../context/reducers/reduxTestCaseReducer';
9+
import { MockDataContext } from '../context/reducers/mockDataReducer';
10+
import ReduxTestMenu from '../components/TestMenu/ReduxTestMenu';
11+
12+
const dispatchToReduxTextCase = jest.fn();
13+
const dispatchToMockData = jest.fn();
14+
15+
export const reduxTestCaseState: ReduxTestCaseState = {
16+
reduxTestStatement: '' /* the test description */,
17+
reduxStatements: [] /* both of the cards on the page at open. Each card gets an id */,
18+
};
19+
20+
const mockDataState = {
21+
mockData: [],
22+
hasMockData: false,
23+
};
24+
25+
describe('should render ReduxTestCase component', () => {
26+
it('renders Test Menu', () => {
27+
const { getByText, debug } = render();
28+
<ReduxTestCaseContext.Provider value={(reduxTestCaseState, dispatchToReduxTextCase)}>
29+
<MockDataContext.Provider value={(mockDataState, dispatchToMockData)}>
30+
<ReduxTestMenu />;
31+
</MockDataContext.Provider>
32+
</ReduxTestCaseContext.Provider>;
33+
expect(getByText('test'));
34+
screen.debug();
35+
});
36+
});

0 commit comments

Comments
 (0)