Skip to content

Commit f560be5

Browse files
committed
Merge branch 'master' into hooksImport
2 parents b8b4454 + 29c1bb4 commit f560be5

File tree

6 files changed

+41
-35
lines changed

6 files changed

+41
-35
lines changed

src/__tests__/jest.config.js

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/components/ReduxTestComponent/Middleware/Middleware.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ const Middleware = ({ middleware, index }) => {
108108
</div>
109109

110110
<div id={styles.middlewareBox}>
111-
<label htmlFor='typesFile'>Query Type</label>
111+
<label htmlFor='typesFile'>Middleware Function</label>
112112
<input
113113
id='queryType'
114114
placeholder='eg. thunk'

src/components/ReduxTestComponent/Reducer/Reducer.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Draggable } from 'react-beautiful-dnd';
33
import styles from './Reducer.module.scss';
44
import { ReduxTestCaseContext } from '../../../context/reducers/reduxTestCaseReducer';
55
import { deleteReducer, updateReducer } from '../../../context/actions/reduxTestCaseActions';
6+
import { updateHooksTestStatement } from '../../../context/actions/hooksTestCaseActions';
67

78
const closeIcon = require('../../../assets/images/close.png');
89
const dragIcon = require('../../../assets/images/drag-vertical.png');

src/components/ReduxTestComponent/Reducer/Reducer.module.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,4 @@
4545
}
4646
position: relative;
4747
}
48+

src/context/reducers/puppeteerTestCaseReducer.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createContext } from 'react';
22
import { PuppeteerTestCaseState, PuppeteerAction } from '../../utils/puppeteerTypes';
3-
//import { actionTypes } from '../actions/puppeteerTestCaseActions';
3+
44
export const PuppeteerTestCaseContext = createContext<any>(null);
55

66
export const puppeteerTestCaseState = {
@@ -21,7 +21,7 @@ export const puppeteerTestCaseState = {
2121
browserOptionId: 0,
2222
},
2323
],
24-
statementId: 0,
24+
statementId: 1,
2525
modalOpen: false,
2626
};
2727

@@ -56,10 +56,14 @@ export const puppeteerTestCaseReducer = (
5656

5757
switch (action.type) {
5858
case 'DELETE_PUPPETEER_TEST':
59-
puppeteerStatements = puppeteerStatements.filter((statement) => statement.id !== action.id);
59+
puppeteerStatements.splice(action.id, 1);
60+
puppeteerStatements.forEach((statement) => {
61+
if (statement.id > action.id) statement.id -= 1;
62+
});
6063
return {
6164
...state,
6265
puppeteerStatements,
66+
statementId: state.statementId - 1,
6367
};
6468

6569
case 'ADD_PUPPETEER_PAINT_TIMING': {
@@ -90,7 +94,7 @@ export const puppeteerTestCaseReducer = (
9094
browserOptionId: 0,
9195
},
9296
],
93-
statementId: 0,
97+
statementId: 1,
9498
};
9599

96100
case 'DELETE_BROWSER_OPTION':
@@ -171,7 +175,6 @@ export const puppeteerTestCaseReducer = (
171175
puppeteerStatements: [...action.draggableStatements],
172176
};
173177
case 'OPEN_INFO_MODAL':
174-
console.log('reducer');
175178
return {
176179
...state,
177180
modalOpen: true,

src/context/useGenerateTest.jsx

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,8 @@ function useGenerateTest(test, projectFilePath) {
186186
187187
beforeEach(() => {
188188
state = ${reducer.initialState}
189-
});\n`;
189+
});
190+
\n`;
190191
}
191192

192193
// Middleware Import Statements
@@ -424,12 +425,14 @@ function useGenerateTest(test, projectFilePath) {
424425
// Middleware Filepath
425426
function createPathToMiddlewares(statement) {
426427
let filePath = null;
428+
console.log(filePath);
427429
if (statement.middlewaresFilePath) {
428430
filePath = path.relative(projectFilePath, statement.middlewaresFilePath);
429431
filePath = filePath.replace(/\\/g, '/');
430432
}
431-
if (!testFileCode.includes(`import * as middleware from`) && filePath) {
432-
testFileCode += `import * as middleware from '../${filePath}';`;
433+
434+
if (!testFileCode.includes(`import ${statement.queryType} from `)) {
435+
testFileCode += `import ${statement.queryType} from '../${filePath}';`;
433436
}
434437
}
435438

@@ -534,37 +537,45 @@ function useGenerateTest(test, projectFilePath) {
534537

535538
// Middleware Jest Test Code
536539
const addMiddleware = (middleware) => {
537-
testFileCode += `\n it('', () => {
538-
const ${middleware.queryValue} = () => {
540+
// testFileCode += `\n it('', () => {
541+
if (!testFileCode.includes(`const store`)) {
542+
testFileCode += `\n const createStore = () => {
539543
const store = {
540544
getState: jest.fn(() => ({})),
541545
dispatch: jest.fn()
542546
}
543547
const next = jest.fn()
544548
const invoke = action => ${middleware.queryType}(store)(next)(action)
545549
return { store, next, invoke }
546-
}
547-
});
550+
}
548551
\n`;
552+
}
549553

550554
if (middleware.queryValue === 'passes_non_functional_arguments') {
551-
testFileCode += `const { next, invoke } = ${middleware.queryValue}()
555+
testFileCode += `\n
556+
it('${middleware.queryValue}', () => {
557+
const { next, invoke } = createStore()
552558
const action = {type : 'TEST'}
553559
invoke(action)
554-
expect(${middleware.querySelector}).${middleware.queryVariant}(action)`;
560+
expect(${middleware.querySelector}).${middleware.queryVariant}(action)
561+
})`;
555562
} else if (middleware.queryValue === 'calls_the_function') {
556-
testFileCode += `const { invoke } = ${middleware.queryValue}()
563+
testFileCode += `\n it('${middleware.queryValue}', () => {
564+
const { invoke } = createStore()
557565
const fn = jest.fn()
558566
invoke(fn)
559-
expect(${middleware.querySelector}).${middleware.queryVariant}()`;
567+
expect(${middleware.querySelector}).${middleware.queryVariant}()
568+
})`;
560569
} else if (middleware.queryValue === 'passes_functional_arguments') {
561-
testFileCode += `const { store, invoke } = ${middleware.queryValue}()
570+
testFileCode += `\n it('${middleware.queryValue}', () => {
571+
const { store, invoke } = createStore()
562572
invoke((dispatch, getState) => {
563573
dispatch('Test Dispatch')
564574
getState()
565575
})
566576
expect(${middleware.querySelector}).${middleware.queryVariant}('Test Dispatch')
567-
expect(${middleware.querySelector}).${middleware.queryVariant}()`;
577+
expect(${middleware.querySelector}).${middleware.queryVariant}()
578+
})`;
568579
}
569580
};
570581

@@ -573,14 +584,14 @@ function useGenerateTest(test, projectFilePath) {
573584
// pass in reducer to expect. pass in initial state as 1st arg, key
574585
// if payload exists, add key/value pair to testfile code
575586
if (reducer.payloadKey) {
576-
testFileCode += `it('${reducer.itStatement}', () => {
587+
testFileCode += `\n it('${reducer.itStatement}', () => {
577588
expect(${reducer.reducerName}(state, { type: actionTypes.${reducer.reducerAction}, ${reducer.payloadKey}: ${reducer.payloadValue} })).toEqual({
578-
...state, ${reducer.expectedKey}: ${reducer.expectedValue} })})
589+
...state, ${reducer.expectedKey}: ${reducer.expectedValue} })
579590
`;
580591
} else {
581-
testFileCode += `it('${reducer.itStatement}', () => {
592+
testFileCode += `\n it('${reducer.itStatement}', () => {
582593
expect(${reducer.reducerName}(state, { type: actionTypes.${reducer.reducerAction}})).toEqual({
583-
...state, ${reducer.expectedKey}: ${reducer.expectedValue} })})
594+
...state, ${reducer.expectedKey}: ${reducer.expectedValue} })
584595
`;
585596
}
586597
}
@@ -786,6 +797,7 @@ function useGenerateTest(test, projectFilePath) {
786797
});
787798
`;
788799
};
800+
789801
switch (test) {
790802
case 'react':
791803
var reactTestCase = testState;
@@ -847,6 +859,7 @@ function useGenerateTest(test, projectFilePath) {
847859
e4x: true,
848860
}))
849861
);
862+
850863
default:
851864
return 'not a test';
852865
}

0 commit comments

Comments
 (0)