Skip to content

Commit 4a705fd

Browse files
committed
Add some tests on the filtering method
1 parent 7be7cfa commit 4a705fd

File tree

4 files changed

+1574
-40
lines changed

4 files changed

+1574
-40
lines changed

README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Showing a list of settings on the `/settings` route.
55
## Requirements
66

77
### Global
8-
* [NodeJS](https://nodejs.org/en/download/)
8+
* [NodeJS](https://nodejs.org/en/download/) (only tested with `v11.6.0`).
99
* [Yarn](https://yarnpkg.com/en/docs/install)
1010

1111
### Environment file
@@ -33,6 +33,11 @@ You can display the settings on http://localhost:8042/settings.
3333
yarn lint
3434
```
3535

36+
* Run tests
37+
```bash
38+
yarn test
39+
```
40+
3641
* Build for production
3742
```bash
3843
yarn build

package.json

+9-3
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@
1111
"start": "nodemon src/main.js",
1212
"build": "babel src -d dist",
1313
"serve": "node dist/main.js",
14-
"lint": "eslint src/"
14+
"lint": "eslint src/",
15+
"test": "jest --coverage"
1516
},
1617
"devDependencies": {
1718
"babel-cli": "^6.26.0",
1819
"babel-preset-env": "^1.7.0",
1920
"eslint": "^5.12.0",
2021
"eslint-config-airbnb-base": "^13.1.0",
2122
"eslint-plugin-import": "^2.14.0",
23+
"jest": "^23.6.0",
2224
"nodemon": "^1.18.9"
2325
},
2426
"dependencies": {
@@ -31,10 +33,14 @@
3133
"extends": "eslint-config-airbnb-base",
3234
"env": {
3335
"node": true,
34-
"es6": true
36+
"es6": true,
37+
"jest": true
3538
},
3639
"rules": {
37-
"arrow-parens": ["error", "as-needed"],
40+
"arrow-parens": [
41+
"error",
42+
"as-needed"
43+
],
3844
"no-console": "off"
3945
}
4046
}

src/modules/SettingsRouter.test.js

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import SettingsRouter from './SettingsRouter';
2+
3+
describe('SettingsRouter', () => {
4+
describe('filterSettingsList', () => {
5+
const settingList = [
6+
{
7+
name: 'Mixer',
8+
requires: ['audio', 'pcb'],
9+
}, {
10+
name: 'AttractLoop',
11+
requires: [],
12+
}, {
13+
name: 'Volume',
14+
requires: ['audio'],
15+
}, {
16+
name: 'Dummy with no requires key',
17+
}, {
18+
name: 'Dummy with no listed components',
19+
requires: ['component1', 'component2', 'component3'],
20+
},
21+
];
22+
23+
const componentList = [
24+
{
25+
name: 'audio',
26+
},
27+
{
28+
name: 'LED array',
29+
},
30+
];
31+
32+
test('Should return an empty array with empty inputs', () => {
33+
expect(SettingsRouter.filterSettingsList([], [])).toEqual([]);
34+
});
35+
36+
test('Should only return the setting with no requirements if no component listed', () => {
37+
expect(SettingsRouter.filterSettingsList(settingList, [])).toEqual([{
38+
name: 'AttractLoop',
39+
requires: [],
40+
}]);
41+
});
42+
43+
test('Should return the right filtered settings', () => {
44+
expect(SettingsRouter.filterSettingsList(settingList, componentList)).toEqual([
45+
{
46+
name: 'Mixer',
47+
requires: ['audio', 'pcb'],
48+
}, {
49+
name: 'AttractLoop',
50+
requires: [],
51+
}, {
52+
name: 'Volume',
53+
requires: ['audio'],
54+
},
55+
]);
56+
});
57+
});
58+
});

0 commit comments

Comments
 (0)