diff --git a/src/Components/Buttonbar/__tests__/index.test.jsx b/src/Components/Buttonbar/__tests__/index.test.jsx
index 762b5eaf0..e00fe558b 100644
--- a/src/Components/Buttonbar/__tests__/index.test.jsx
+++ b/src/Components/Buttonbar/__tests__/index.test.jsx
@@ -10,7 +10,6 @@ import { Provider } from 'react-redux';
import escsReducer, { setIndividual } from '../../../Containers/App/escsSlice';
import melodiesReducer, { updateAll } from '../../MelodyEditor/melodiesSlice';
-import logReducer, { add } from '../../Log/logSlice';
import stateReducer, { setWriting } from '../../../Containers/App/stateSlice';
import Buttonbar from '../';
@@ -24,7 +23,6 @@ function setupTestStore() {
const store = configureStore({
reducer: {
escs: escsReducer,
- log: logReducer,
melodies: melodiesReducer,
state: stateReducer,
},
@@ -74,26 +72,9 @@ describe('Buttonbar', () => {
expect(screen.getByText(/escButtonRead/i)).toBeInTheDocument();
expect(screen.getByText(/escButtonWrite/i)).toBeInTheDocument();
expect(screen.getByText(/escButtonFlashAll/i)).toBeInTheDocument();
- expect(screen.getByText(/escButtonSaveLog/i)).toBeInTheDocument();
expect(screen.getAllByText(/escButtonOpenMelodyEditor/i).length).toEqual(2);
});
- it('should always trigger log save', () => {
- global.URL.createObjectURL = jest.fn();
-
- render(
- ,
- { wrapper: storeRef.wrapper }
- );
-
- userEvent.click(screen.getByText(/escButtonSaveLog/i));
- expect(global.URL.createObjectURL).toHaveBeenCalled();
- });
-
it('should not trigger handlers when disabled', () => {
storeRef.store.dispatch(setWriting(true));
@@ -182,32 +163,4 @@ describe('Buttonbar', () => {
expect(melodies.show).toBeTruthy();
});
- it('should clear log', () => {
- const onWriteSetup = jest.fn();
- const onReadSetup = jest.fn();
- const onResetDefaults = jest.fn();
- const onSeletFirmwareForAll = jest.fn();
-
- storeRef.store.dispatch(add('line1'));
-
- let log = storeRef.store.getState().log;
- expect(log.log.length).toEqual(1);
-
- render(
- ,
- { wrapper: storeRef.wrapper }
- );
-
- expect(screen.getByText(/escButtonClearLog/i)).toBeInTheDocument();
-
- userEvent.click(screen.getByText(/escButtonClearLog/i));
-
- log = storeRef.store.getState().log;
- expect(log.log.length).toEqual(0);
- });
});
diff --git a/src/Components/Buttonbar/index.jsx b/src/Components/Buttonbar/index.jsx
index 3832aa426..106a878b6 100644
--- a/src/Components/Buttonbar/index.jsx
+++ b/src/Components/Buttonbar/index.jsx
@@ -13,10 +13,6 @@ import {
show,
selectSupported,
} from '../MelodyEditor/melodiesSlice';
-import {
- clear as clearLog,
- selectLog,
-} from '../Log/logSlice';
import {
selectCanFlash,
selectCanRead,
@@ -39,7 +35,6 @@ function Buttonbar({
const dispatch = useDispatch();
const showMelodyEditor = useSelector(selectSupported);
- const log = useSelector(selectLog);
const canFlash = useSelector(selectCanFlash);
const canRead = useSelector(selectCanRead);
@@ -63,21 +58,6 @@ function Buttonbar({
dispatch(show());
}, [dispatch]);
- const handleSaveLog = useCallback(() => {
- const element = document.createElement("a");
- const file = new Blob([log.join("\n")], { type: 'text/plain' });
- element.href = URL.createObjectURL(file);
- element.download = "esc-configurator-log.txt";
- document.body.appendChild(element);
- element.click();
-
- dispatch(clearLog());
- }, [dispatch, log]);
-
- const handleClearLog = useCallback(() => {
- dispatch(clearLog());
- }, [dispatch]);
-
return (
@@ -90,16 +70,6 @@ function Buttonbar({
-
-
-
-
{
expect(screen.queryByText(/showLog/i)).not.toBeInTheDocument();
expect(screen.getByText(/hideLog/i)).toBeInTheDocument();
});
+
+ it('should save debug log', () => {
+ global.URL.createObjectURL = jest.fn();
+
+ storeRef.store.dispatch(add('line1'));
+
+ render(
+ ,
+ { wrapper: storeRef.wrapper }
+ );
+
+ userEvent.click(screen.getByText(/escButtonSaveLog/i));
+ expect(global.URL.createObjectURL).toHaveBeenCalled();
+
+ const log = storeRef.store.getState().log;
+ expect(log.log.length).toEqual(0);
+ });
+
+ it('should clear debug log', () => {
+ storeRef.store.dispatch(add('line1'));
+
+ let log = storeRef.store.getState().log;
+ expect(log.log.length).toEqual(1);
+
+ render(
+ ,
+ { wrapper: storeRef.wrapper }
+ );
+
+ userEvent.click(screen.getByText(/escButtonClearLog/i));
+
+ log = storeRef.store.getState().log;
+ expect(log.log.length).toEqual(0);
+ });
});
describe('logSlice', () => {
diff --git a/src/Components/Log/index.jsx b/src/Components/Log/index.jsx
index fdf79cdf1..cfb95b30e 100644
--- a/src/Components/Log/index.jsx
+++ b/src/Components/Log/index.jsx
@@ -2,16 +2,25 @@ import React, {
useCallback,
useState,
} from 'react';
-import { useSelector } from 'react-redux';
+import {
+ useDispatch,
+ useSelector,
+} from 'react-redux';
import { useTranslation } from 'react-i18next';
-import { selectLogTimestamped } from './logSlice';
+import {
+ clear as clearLog,
+ selectLog,
+ selectLogTimestamped,
+} from './logSlice';
import './style.scss';
function Log() {
const { t } = useTranslation('common');
+ const dispatch = useDispatch();
const messages = useSelector(selectLogTimestamped);
+ const log = useSelector(selectLog);
const [ expanded, setExpanded] = useState(false);
const messageElements = messages.slice(0).reverse()
@@ -37,12 +46,41 @@ function Log() {
setExpanded(!expanded);
}, [expanded]);
+ const handleSaveLog = useCallback(() => {
+ const element = document.createElement("a");
+ const file = new Blob([log.join("\n")], { type: 'text/plain' });
+ element.href = URL.createObjectURL(file);
+ element.download = "esc-configurator-log.txt";
+ document.body.appendChild(element);
+ element.click();
+
+ dispatch(clearLog());
+ }, [dispatch, log]);
+
+ const handleClearLog = useCallback(() => {
+ dispatch(clearLog());
+ }, [dispatch]);
+
return (
+
+
+
+