Skip to content

Commit

Permalink
Fixed merge conflict, updated tests and fixed linting errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
stylesuxx committed Feb 5, 2022
2 parents 7e22d8a + 6c03033 commit 46912e0
Show file tree
Hide file tree
Showing 112 changed files with 8,123 additions and 8,769 deletions.
65 changes: 31 additions & 34 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,40 @@
{
"extends": ["eslint:recommended", "plugin:react/all", "plugin:jest/recommended"],
"ignorePatterns": ["service-worker.js"],
"plugins": [
"react"
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module",
"ecmaFeatures": { "jsx": true }
},
"env": {
"es2021": true,
"browser": true,
"node": true
},
"extends": [
"eslint:recommended",
"plugin:react/all",
"plugin:jest/recommended",
"react-app",
"react-app/jest"
],
"ignorePatterns": ["service-worker.js"],
"plugins": ["react", "jest"],
"rules": {
"react/jsx-max-depth": ["warn", { "max": 5 }],
"indent": ["warn", 2, { "SwitchCase": 1 }],
"react/jsx-indent": ["warn", 2],
"react/jsx-indent-props": ["warn", 2],
"react/jsx-no-literals": "off",
"react/no-multi-comp": "off",
"react/no-set-state": "off",
"react/forbid-component-props": "off",
"no-unreachable": "off",
"react/no-array-index-key": "warn",
"react/no-danger": "warn",
"react/forbid-component-props": "off",
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "error",
"testing-library/no-container": "error",
"testing-library/no-node-access": "error",
"indent": ["warn", 2, { "SwitchCase": 1 }],
"no-lone-blocks": "off",
"no-mixed-operators": "error",
"no-unused-vars": "warn",
"new-cap": [
"error", {
Expand Down Expand Up @@ -43,36 +62,14 @@
"exports": "always-multiline",
"functions": "never"
}],
"object-property-newline": "error"
"object-property-newline": "error",
"default-case": "warn",
"no-template-curly-in-string": "off",
"no-unreachable": "warn"
},
"settings": {
"react": {
"version": "detect"
}
},
"globals": {
"document": false,
"process": false,
"navigator": false,
"console": false,
"fetch": false,
"URL": false,
"window": false,
"setInterval": false,
"clearInterval": false,
"Uint8Array": false,
"ArrayBuffer": false,
"DataView": false,
"setTimeout": false,
"clearTimeout": false,
"Promise": false,
"FileReader": false,
"Blob": false,
"localStorage": false,
"__dirname": false,
"require": false,
"Set": false,
"Event": false
},
"parser": "babel-eslint"
}
}
21 changes: 21 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Coverage

on: [push, pull_request]

jobs:
coverage:
name: Coverage
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Setup Node
run: yarn install --immutable --immutable-cache --check-cache

- name: Generate coverage report
run: yarn test:coverage

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
with:
directory: ./coverage
verbose: true
17 changes: 17 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Test

on:
push:
branches: [master, develop]
pull_request:
branches: [master, develop]

jobs:
test:
name: Test
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- run: yarn install --immutable --immutable-cache --check-cache
- run: yarn lint
- run: yarn test
9 changes: 0 additions & 9 deletions .travis.yml

This file was deleted.

2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ Translations are managed via [crowdin](https://crowdin.com/project/esc-configura
## Contributing
Contributions are very welcome. Feel free to submit PR's and discuss feature requests - I am open for all suggestions. If you submit a PR please also **provide tests** where it makes sense. Some tests can not (yet) be easily automated, like playing music or the actual flashing process without having to heavily mock those components.

If you do submit a PR, please do so against the **develop** branch. Also make sure that your code matches the linting rules. If you get warnings, try to adapt your code accordingly. If the rule makes no sense or can't really be satisfied it's OK to submit your PR anyway.

### Dev Setup
Simply clone the repository, install dependencies and run the dev server. Pull requests are more than welcome.

Expand Down
77 changes: 43 additions & 34 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "esc-configurator",
"version": "0.21.0",
"version": "0.22.0",
"private": false,
"license": "AGPL-3.0",
"dependencies": {
Expand All @@ -9,35 +9,43 @@
"@fontsource/roboto": "^4.5.1",
"@mui/icons-material": "^5.2.5",
"@mui/material": "^5.2.7",
"@babel/plugin-transform-react-jsx": "^7.16.7",
"@palmabit/react-cookie-law": "^0.6.2",
"autoprefixer": "^10.4.2",
"bluejay-rtttl-parse": "^2.0.2",
"compare-versions": "^3.6.0",
"dateformat": "^4.5.1",
"i18next": "^19.9.0",
"compare-versions": "^4.1.3",
"dateformat": "^5.0.2",
"draft-js": "^0.11.7",
"i18next": "^21.6.7",
"prop-types": "^15.8.1",
"rc-slider": "^9.7.2",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-gtm-module": "^2.0.11",
"react-highlight-within-textarea": "^1.0.1",
"react-highlight-within-textarea": "^2.1.3",
"react-i18next": "^11.8.8",
"react-scripts": "4.0.3",
"react-toastify": "^7.0.3",
"scheduler": "0.14.0",
"react-input-range": "^1.3.0",
"react-markdown": "^8.0.0",
"react-scripts": "^5.0.0",
"react-toastify": "^8.1.0",
"react-tooltip": "^4.2.21",
"scheduler": "^0.20.2",
"sleep": "^6.3.0",
"ua-parser-js": "^1.0.2",
"web-serial-polyfill": "stylesuxx/web-serial-polyfill#temporary-fix",
"web-vitals": "^0.2.4",
"workbox-background-sync": "^5.1.3",
"workbox-broadcast-update": "^5.1.3",
"workbox-cacheable-response": "^5.1.3",
"workbox-core": "^5.1.3",
"workbox-expiration": "^5.1.3",
"workbox-google-analytics": "^5.1.3",
"workbox-navigation-preload": "^5.1.3",
"workbox-precaching": "^5.1.3",
"workbox-range-requests": "^5.1.3",
"workbox-routing": "^5.1.3",
"workbox-strategies": "^5.1.3",
"workbox-streams": "^5.1.3"
"web-vitals": "^2.1.4",
"workbox-background-sync": "^6.4.2",
"workbox-broadcast-update": "^6.4.2",
"workbox-cacheable-response": "^6.4.2",
"workbox-core": "^6.4.2",
"workbox-expiration": "^6.4.2",
"workbox-google-analytics": "^6.4.2",
"workbox-navigation-preload": "^6.4.2",
"workbox-precaching": "^6.4.2",
"workbox-range-requests": "^6.4.2",
"workbox-routing": "^6.4.2",
"workbox-strategies": "^6.4.2",
"workbox-streams": "^6.4.2"
},
"scripts": {
"start": "react-scripts start",
Expand Down Expand Up @@ -69,24 +77,25 @@
]
},
"devDependencies": {
"@babel/core": "^7.16.10",
"@babel/plugin-syntax-flow": "^7.16.7",
"@babel/preset-react": "^7.16.7",
"@testing-library/dom": "^8.11.2",
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"@typescript-eslint/eslint-plugin": "^4.0.0",
"@typescript-eslint/parser": "^4.0.0",
"babel-eslint": "^10.0.0",
"@testing-library/react": "^12.1.2",
"@testing-library/user-event": "^13.5.0",
"@typescript-eslint/eslint-plugin": "^5.10.0",
"@typescript-eslint/parser": "^5.10.0",
"codecov": "^3.8.3",
"eslint": "^7.5.0",
"eslint-config-react-app": "^6.0.0",
"eslint-plugin-flowtype": "^5.2.0",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-jest": "^24.3.2",
"eslint-plugin-jsx-a11y": "^6.3.1",
"eslint-plugin-react": "^7.20.3",
"eslint-plugin-react-hooks": "^4.0.8",
"eslint": "^8.7.0",
"eslint-config-react-app": "^7.0.0",
"eslint-plugin-jest": "^25.7.0",
"eslint-plugin-react": "^7.28.0",
"postcss": "^8.4.5",
"pre-commit": "^1.2.2",
"pre-push": "^0.1.1",
"sass": "^1.32.8",
"typescript": "^4.5.5",
"with-staged": "^1.0.2"
},
"jest": {
Expand Down
3 changes: 3 additions & 0 deletions src/Components/App/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ function App({
melodies,
msp,
onAllMotorSpeed,
onClearLog,
onCookieAccept,
onSaveLog,
onSingleMotorSpeed,
Expand Down Expand Up @@ -106,6 +107,7 @@ function App({
mspFeatures={msp.features}
onAllMotorSpeed={onAllMotorSpeed}
onCancelFirmwareSelection={escs.actions.handleCancelFirmwareSelection}
onClearLog={onClearLog}
onCommonSettingsUpdate={escs.actions.handleCommonSettingsUpdate}
onFirmwareDump={escs.actions.handleFirmwareDump}
onFlashUrl={escs.actions.handleFlashUrl}
Expand Down Expand Up @@ -226,6 +228,7 @@ App.propTypes = {
}).isRequired,
msp: PropTypes.shape({ features: PropTypes.shape({}).isRequired }).isRequired,
onAllMotorSpeed: PropTypes.func.isRequired,
onClearLog: PropTypes.func.isRequired,
onCookieAccept: PropTypes.func.isRequired,
onSaveLog: PropTypes.func.isRequired,
onSingleMotorSpeed: PropTypes.func.isRequired,
Expand Down
23 changes: 23 additions & 0 deletions src/Components/AppSettings/__tests__/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,27 @@ describe('AppSettings', () => {
userEvent.click(screen.getByTestId('CloseIcon'));
expect(onClose).toHaveBeenCalled();
});

it('should handle invalid setting type', () => {
const settings = {
testSetting: {
type: "string",
value: "something",
},
};

const onClose = jest.fn();
const onUpdate = jest.fn();

render(
<AppSettings
onClose={onClose}
onUpdate={onUpdate}
open
settings={settings}
/>
);

expect(screen.getByText(/settingsHeader/i)).toBeInTheDocument();
});
});
12 changes: 9 additions & 3 deletions src/Components/AppSettings/index.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useTranslation } from 'react-i18next';
import PropTypes from 'prop-types';
import React from 'react';
import React, { useCallback } from 'react';

import FormControl from '@mui/material/FormControl';
import Stack from '@mui/material/Stack';
Expand All @@ -16,12 +16,12 @@ function AppSettings({
}) {
const { t } = useTranslation('settings');

function handleCheckboxChange(e) {
const handleCheckboxChange = useCallback((e) => {
const name = e.target.name;
const value = e.target.checked;

onUpdate(name, value);
}
}, [onUpdate]);

const settingKeys = Object.keys(settings);
const settingElements = settingKeys.map((key) => {
Expand All @@ -40,7 +40,13 @@ function AppSettings({
/>
);
}

default: {
return null;
}
}

return null;
});

return (
Expand Down
8 changes: 4 additions & 4 deletions src/Components/Buttonbar/__tests__/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,16 @@ describe('Buttonbar', () => {
/>
);

userEvent.click(screen.queryAllByText(/resetDefaults/i)[1]);
expect(screen.queryAllByText(/resetDefaults/i)[1]).toHaveAttribute('disabled');
expect(onResetDefaults).not.toHaveBeenCalled();

userEvent.click(screen.getByText(/escButtonRead/i));
expect(screen.getByText(/escButtonRead/i)).toHaveAttribute('disabled');
expect(onReadSetup).not.toHaveBeenCalled();

userEvent.click(screen.getByText(/escButtonWrite/i));
expect(screen.getByText(/escButtonWrite/i)).toHaveAttribute('disabled');
expect(onWriteSetup).not.toHaveBeenCalled();

userEvent.click(screen.getByText(/escButtonFlashAll/i));
expect(screen.getByText(/escButtonFlashAll/i)).toHaveAttribute('disabled');
expect(onSelectFirmwareForAll).not.toHaveBeenCalled();
});

Expand Down
Loading

0 comments on commit 46912e0

Please sign in to comment.