Skip to content

Commit 1dab352

Browse files
Rachel YooRachel Yoo
authored andcommitted
edited readme and organized exportfilemodal
1 parent 1429ba4 commit 1dab352

File tree

2 files changed

+70
-53
lines changed

2 files changed

+70
-53
lines changed

README.md

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,36 @@
11
![](https://lh5.googleusercontent.com/5Gr2dZXHJdmIiASsPw9put-6mR20e4g1gOk-af4krREaJ7NqkZnqXLD5QgiotfNHYhGRh387HSqdhjRwxdwOvQzg9ChhfIrZz0FdxVu6gktBtG-sy1MX6Xq36Gmrzu_6G_K7LDQZ)
22

3-
Spearmint helps developers easily create functional React/Redux tests without writing any code. It dynamically converts user inputs into executable Jest test code by using DOM query selectors provided by @testing-library.
3+
Spearmint helps developers easily create functional React/Redux/Endpoint tests without writing any code. It dynamically converts user inputs into executable Jest test code by using DOM query selectors provided by @testing-library.
44

5-
Spearmint is currently under development! We just finished our MVP and are looking for beta testers. Please open a new issue with details to report a bug. Adding support to mock API requests, context, and hooks are on the roadmap.
5+
Spearmint is currently under development! We just finished our MVP and are looking for beta testers. Please open a new issue with details to report a bug.
66

77
## How to use
88

9-
Download spearmint @ spearmintjs.com. Available for Mac OS and Windows. To run tests generated by spearmint install jest, @testing-library/jest-dom, @testing-library/react, and test-data-bot in your dev dependencies.
9+
Download spearmint @ spearmintjs.com. Available for Mac OS and Windows.
10+
11+
To run React tests generated by spearmint, install the following in your dev dependencies.
1012

1113
npm i -D jest @testing-library/jest-dom @testing-library/react test-data-bot
1214

15+
To run Redux tests generated by spearmint, install the following in your dev dependencies, in addition to your React test installations above.
16+
17+
npm i -D redux-mock-store redux-thunk fetch-mock
18+
19+
To run Hooks / Context tests generated by spearmint, install the following in your dev dependencies, in addition to your React test installations above.
20+
21+
npm i -D @testing-library/react-hooks
22+
23+
To run Endpoint tests generated by spearmint, install the following in your dev dependencies.
24+
25+
npm i -D jest supertest
26+
1327
## How it works
1428

15-
1. On the initial screen, enter the URL of your project and load your React/Redux application to start creating tests.
29+
1. On the initial screen, enter the URL of your project and load your React/Redux/Node application to start creating tests.
1630

1731
![](https://lh4.googleusercontent.com/CAFpoefRUUxgNosudQuc7gabSReFiI_puZ_WTjrzUSzB6pgOUdQ1babF2mxJql2lC8TQ-jjVLOgG5Qka8SUfF2fi-u2H9xSP7rZ_0Udpj-ISFPAY028UYKIUZcgOApnipVZwE7xh)
1832

19-
2. Utilize our auto-complete, drop-down options, and tooltips features to easily create arrangement, action, and assertion test statements for React, in addition to reducer, action creator, asynchronous action creator, and middleware test statements for Redux.
33+
2. Utilize our auto-complete, drop-down options, and tooltips features to easily create arrangement, action, and assertion test statements for React; reducer, action creator, asynchronous action creator, and middleware test statements for Redux; and hooks, context,and endpoint test statements.
2034

2135
![](https://lh5.googleusercontent.com/5VYUlGG5VDdZxdZEh5aokuilhKRp8B5QyVmxvtW_abLYCAzYN-s-el1oV5WMtGuTzbEO2I6l8Ys_yK2gC0fCi8ISHwjh4LlgezsrPWd7mDEtLbPqBYf1J4pgkGmfIV4yq4I_dpQg)
2236

@@ -29,12 +43,12 @@ Download spearmint @ spearmintjs.com. Available for Mac OS and Windows. To run t
2943
## Team
3044

3145
> Alex [@apark0720](https://github.com/apark0720)  · 
32-
> Johnny [@johnny-lim](https://github.com/johnny-lim)  · 
33-
> Julie [@julicious100](https://github.com/julicious100)  · 
34-
> Natlyn [@natlynp](https://github.com/natlynp)  · 
35-
> Karen [@karenpinilla](https://github.com/karenpinilla)  · 
3646
> Chloe [@HeyItsChloe](https://github.com/HeyItsChloe)  · 
3747
> Cornelius [@corneeltron](https://github.com/corneeltron)  · 
3848
> Dave [@davefranz](https://github.com/davefranz)  · 
49+
> Johnny [@johnny-lim](https://github.com/johnny-lim) <br />
50+
> Julie [@julicious100](https://github.com/julicious100) &nbsp;&middot;&nbsp;
51+
> Karen [@karenpinilla](https://github.com/karenpinilla) &nbsp;&middot;&nbsp;
3952
> Linda [@lcwish](https://github.com/lcwish) &nbsp;&middot;&nbsp;
53+
> Natlyn [@natlynp](https://github.com/natlynp) &nbsp;&middot;&nbsp;
4054
> Rachel [@rachethecreator](https://github.com/rachethecreator)

src/containers/NavBar/Modals/ExportFileModal.jsx

Lines changed: 47 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,36 @@ const ExportFileModal = ({ isExportModalOpen, closeExportModal }) => {
262262
testFileCode += '\n';
263263
};
264264

265+
/* ------------------------------------------ ENDPOINT IMPORT + TEST STATEMENTS ------------------------------------------ */
266+
267+
// Endpoint Import Statements
268+
const addEndpointImportStatements = () => {
269+
endpointTestCase.endpointStatements.forEach(statement => {
270+
switch (statement.type) {
271+
case 'endpoint':
272+
return createPathToServer(statement);
273+
default:
274+
return statement;
275+
}
276+
});
277+
testFileCode += '\n';
278+
};
279+
280+
const addEndpointTestStatements = () => {
281+
testFileCode += `\n test('${endpointTestCase.endpointTestStatement}', async (done) => {`;
282+
endpointTestCase.endpointStatements.forEach(statement => {
283+
switch (statement.type) {
284+
case 'endpoint':
285+
return addEndpoint(statement);
286+
default:
287+
return statement;
288+
}
289+
});
290+
testFileCode += 'done();';
291+
testFileCode += '});';
292+
testFileCode += '\n';
293+
};
294+
265295
/* ------------------------------------------ FILEPATHS ------------------------------------------ */
266296

267297
// Actions Filepath
@@ -306,6 +336,17 @@ const ExportFileModal = ({ isExportModalOpen, closeExportModal }) => {
306336
testFileCode += `import { ${statement.providerComponent}, ${statement.consumerComponent}, ${statement.context} } from '../${filePath}';`;
307337
};
308338

339+
// Endpoint Filepath
340+
const createPathToServer = statement => {
341+
let filePath = path.relative(projectFilePath, statement.serverFilePath);
342+
filePath = filePath.replace(/\\/g, '/');
343+
testFileCode = `const app = require('../${filePath}');
344+
const supertest = require('supertest')
345+
const request = supertest(app)\n`;
346+
347+
testFileCode += '\n';
348+
};
349+
309350
/* ------------------------------------------ MOCK DATA + METHODS ------------------------------------------ */
310351

311352
const addMockData = () => {
@@ -338,6 +379,7 @@ const ExportFileModal = ({ isExportModalOpen, closeExportModal }) => {
338379
};
339380

340381
/* ------------------------------------------ TEST STATEMENTS ------------------------------------------ */
382+
341383
// Action Jest Test Code
342384
const addAction = action => {
343385
if (action.eventValue) {
@@ -491,53 +533,14 @@ const ExportFileModal = ({ isExportModalOpen, closeExportModal }) => {
491533
}
492534
};
493535

494-
/* --------------------------------ENDPOINT FUNCTIONS ------------------------------------------ */
495-
496-
const addEndpointImportStatements = () => {
497-
endpointTestCase.endpointStatements.forEach(statement => {
498-
switch (statement.type) {
499-
case 'endpoint':
500-
return createPathToServer(statement);
501-
default:
502-
return statement;
503-
}
504-
});
505-
testFileCode += '\n';
506-
};
507-
508-
const createPathToServer = statement => {
509-
let filePath = path.relative(projectFilePath, statement.serverFilePath);
510-
filePath = filePath.replace(/\\/g, '/');
511-
testFileCode = `const app = require('../${filePath}');
512-
const supertest = require('supertest')
513-
const request = supertest(app)\n`;
514-
515-
testFileCode += '\n';
516-
};
517-
518-
const addEndpointTestStatements = () => {
519-
testFileCode += `\n test('${endpointTestCase.endpointTestStatement}', async (done) => {`;
520-
endpointTestCase.endpointStatements.forEach(statement => {
521-
switch (statement.type) {
522-
case 'endpoint':
523-
return addEndpoint(statement);
524-
default:
525-
return statement;
526-
}
527-
});
528-
testFileCode += 'done();';
529-
testFileCode += '});';
530-
testFileCode += '\n';
531-
};
532-
536+
// Endpoint Jest Test Code
533537
const addEndpoint = statement => {
534-
testFileCode += `const response = await request.${statement.method}('${statement.route}')`;
535-
536-
testFileCode += '\n';
537-
538-
testFileCode += `expect(response.${statement.expectedResponse}).toBe(${statement.value});`;
538+
testFileCode += `const response = await request.${statement.method}('${statement.route}')
539+
expect(response.${statement.expectedResponse}).toBe(${statement.value});`;
539540
};
540541

542+
/* ------------------------------------------ EXPORT + DISPLAY FILE ------------------------------------------ */
543+
541544
const exportTestFile = async () => {
542545
if (!fs.existsSync(projectFilePath + '/__tests__')) {
543546
fs.mkdirSync(projectFilePath + '/__tests__');

0 commit comments

Comments
 (0)