From 639dcf0f07043c92d1d422f4a93ca7b2789214a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cboz=E2=80=9D?= Date: Tue, 22 Mar 2022 15:41:47 +0800 Subject: [PATCH 1/5] fix switching page causes setting to crash --- ui/src/Pages/SettingsPage/ScannerConcurrentWorkers.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ui/src/Pages/SettingsPage/ScannerConcurrentWorkers.tsx b/ui/src/Pages/SettingsPage/ScannerConcurrentWorkers.tsx index 01e8d477..717d1603 100644 --- a/ui/src/Pages/SettingsPage/ScannerConcurrentWorkers.tsx +++ b/ui/src/Pages/SettingsPage/ScannerConcurrentWorkers.tsx @@ -26,6 +26,9 @@ const SET_CONCURRENT_WORKERS_MUTATION = gql` const ScannerConcurrentWorkers = () => { const { t } = useTranslation() + const workerAmountServerValue = useRef(null) + const [workerAmount, setWorkerAmount] = useState(0) + const workerAmountQuery = useQuery( CONCURRENT_WORKERS_QUERY, { @@ -41,9 +44,6 @@ const ScannerConcurrentWorkers = () => { setConcurrentWorkersVariables >(SET_CONCURRENT_WORKERS_MUTATION) - const workerAmountServerValue = useRef(null) - const [workerAmount, setWorkerAmount] = useState(0) - const updateWorkerAmount = (workerAmount: number) => { if (workerAmountServerValue.current != workerAmount) { workerAmountServerValue.current = workerAmount From cb5eb0e24c852361139058a4bf8f01a6c2eb2cd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cboz=E2=80=9D?= Date: Wed, 23 Mar 2022 15:56:13 +0800 Subject: [PATCH 2/5] add eject --- ui/package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/ui/package.json b/ui/package.json index 5cf8801b..219ca83f 100644 --- a/ui/package.json +++ b/ui/package.json @@ -59,6 +59,7 @@ "scripts": { "start": "BROWSER=none PORT=1234 craco start", "build": "craco build", + "eject": "react-scripts eject", "test": "npm run lint && npm run jest -- --watchAll=false", "test:ci": "npm run lint && npm run jest:ci", "lint": "npm run lint:types & npm run lint:eslint", From ec77bc7fb15d2f3cb7ee161e0050e576e5efe00b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cboz=E2=80=9D?= Date: Thu, 24 Mar 2022 16:42:16 +0800 Subject: [PATCH 3/5] add ScannerConcurrentWorkers.test --- .../ScannerConcurrentWorkers.test.js | 54 +++++++++++++++++++ .../SettingsPage/ScannerConcurrentWorkers.tsx | 8 ++- ui/src/Pages/SettingsPage/ScannerSection.tsx | 2 +- 3 files changed, 58 insertions(+), 6 deletions(-) create mode 100644 ui/src/Pages/SettingsPage/ScannerConcurrentWorkers.test.js diff --git a/ui/src/Pages/SettingsPage/ScannerConcurrentWorkers.test.js b/ui/src/Pages/SettingsPage/ScannerConcurrentWorkers.test.js new file mode 100644 index 00000000..06614c15 --- /dev/null +++ b/ui/src/Pages/SettingsPage/ScannerConcurrentWorkers.test.js @@ -0,0 +1,54 @@ +import React from 'react' +import { MockedProvider } from '@apollo/client/testing' + +import { render, screen } from '@testing-library/react' + +import { + CONCURRENT_WORKERS_QUERY, + SET_CONCURRENT_WORKERS_MUTATION, + ScannerConcurrentWorkers, +} from './ScannerConcurrentWorkers' + +describe('load correct share page, based on graphql query', () => { + const graphqlMocks = [ + { + request: { + query: CONCURRENT_WORKERS_QUERY, + }, + result: { + data: { + siteInfo: { concurrentWorkers: 3 }, + }, + }, + }, + { + request: { + query: SET_CONCURRENT_WORKERS_MUTATION, + variables: { + workers: '1', + }, + }, + result: { + data: {}, + }, + }, + ] + + test('load media share page', async () => { + render( + + + + ) + + expect(screen.getByText('Scanner concurrent workers')).toBeInTheDocument() + }) +}) diff --git a/ui/src/Pages/SettingsPage/ScannerConcurrentWorkers.tsx b/ui/src/Pages/SettingsPage/ScannerConcurrentWorkers.tsx index 717d1603..8a10dcb5 100644 --- a/ui/src/Pages/SettingsPage/ScannerConcurrentWorkers.tsx +++ b/ui/src/Pages/SettingsPage/ScannerConcurrentWorkers.tsx @@ -9,7 +9,7 @@ import { } from './__generated__/setConcurrentWorkers' import { TextField } from '../../primitives/form/Input' -const CONCURRENT_WORKERS_QUERY = gql` +export const CONCURRENT_WORKERS_QUERY = gql` query concurrentWorkersQuery { siteInfo { concurrentWorkers @@ -17,13 +17,13 @@ const CONCURRENT_WORKERS_QUERY = gql` } ` -const SET_CONCURRENT_WORKERS_MUTATION = gql` +export const SET_CONCURRENT_WORKERS_MUTATION = gql` mutation setConcurrentWorkers($workers: Int!) { setScannerConcurrentWorkers(workers: $workers) } ` -const ScannerConcurrentWorkers = () => { +export const ScannerConcurrentWorkers = () => { const { t } = useTranslation() const workerAmountServerValue = useRef(null) @@ -86,5 +86,3 @@ const ScannerConcurrentWorkers = () => { ) } - -export default ScannerConcurrentWorkers diff --git a/ui/src/Pages/SettingsPage/ScannerSection.tsx b/ui/src/Pages/SettingsPage/ScannerSection.tsx index cced4376..733b0077 100644 --- a/ui/src/Pages/SettingsPage/ScannerSection.tsx +++ b/ui/src/Pages/SettingsPage/ScannerSection.tsx @@ -1,7 +1,7 @@ import React from 'react' import { useMutation, gql } from '@apollo/client' import PeriodicScanner from './PeriodicScanner' -import ScannerConcurrentWorkers from './ScannerConcurrentWorkers' +import { ScannerConcurrentWorkers } from './ScannerConcurrentWorkers' import { SectionTitle, InputLabelDescription } from './SettingsPage' import { useTranslation } from 'react-i18next' import { scanAllMutation } from './__generated__/scanAllMutation' From 23b02e65bdcf6388eb0f2fa420139f4653e060ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cboz=E2=80=9D?= Date: Thu, 24 Mar 2022 16:45:42 +0800 Subject: [PATCH 4/5] delete eject --- ui/package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/ui/package.json b/ui/package.json index 219ca83f..5cf8801b 100644 --- a/ui/package.json +++ b/ui/package.json @@ -59,7 +59,6 @@ "scripts": { "start": "BROWSER=none PORT=1234 craco start", "build": "craco build", - "eject": "react-scripts eject", "test": "npm run lint && npm run jest -- --watchAll=false", "test:ci": "npm run lint && npm run jest:ci", "lint": "npm run lint:types & npm run lint:eslint", From 4aca022b38a7854e57f873bff03f00e406cef547 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cboz=E2=80=9D?= Date: Thu, 24 Mar 2022 16:51:19 +0800 Subject: [PATCH 5/5] update ScannerConcurrentWorkers.test --- .../ScannerConcurrentWorkers.test.js | 33 +++++++++---------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/ui/src/Pages/SettingsPage/ScannerConcurrentWorkers.test.js b/ui/src/Pages/SettingsPage/ScannerConcurrentWorkers.test.js index 06614c15..1207e1e0 100644 --- a/ui/src/Pages/SettingsPage/ScannerConcurrentWorkers.test.js +++ b/ui/src/Pages/SettingsPage/ScannerConcurrentWorkers.test.js @@ -9,7 +9,7 @@ import { ScannerConcurrentWorkers, } from './ScannerConcurrentWorkers' -describe('load correct share page, based on graphql query', () => { +test('load ScannerConcurrentWorkers', async () => { const graphqlMocks = [ { request: { @@ -33,22 +33,19 @@ describe('load correct share page, based on graphql query', () => { }, }, ] + render( + + + + ) - test('load media share page', async () => { - render( - - - - ) - - expect(screen.getByText('Scanner concurrent workers')).toBeInTheDocument() - }) + expect(screen.getByText('Scanner concurrent workers')).toBeInTheDocument() })