merchant-backoffice

ZZZ: Inactive/Deprecated
Log | Files | Refs | Submodules | README

commit a275341ee45123f067c5e14165046dabd51f6e3a
parent 740866142fed3a3af0a7db535eb85bc49098a4e3
Author: Sebastian <sebasjm@gmail.com>
Date:   Tue, 18 May 2021 17:17:16 -0300

fix lint

Diffstat:
Mpackages/frontend/src/components/exception/AsyncButton.tsx | 21+++++++++++++++++++++
Mpackages/frontend/src/hooks/async.ts | 2+-
Mpackages/frontend/src/hooks/backend.ts | 11++++++++++-
Mpackages/frontend/src/hooks/index.ts | 3++-
Mpackages/frontend/src/paths/instance/transfers/list/Table.tsx | 4++--
Mpackages/frontend/tests/hooks/swr/order-create.test.tsx | 2++
Mpackages/frontend/tests/hooks/swr/order-pagination.test.tsx | 2++
Mpackages/frontend/tests/hooks/swr/product-create.test.tsx | 2++
Mpackages/frontend/tests/hooks/swr/product-delete.test.tsx | 3+++
Mpackages/frontend/tests/hooks/swr/product-details-update.test.tsx | 2++
Mpackages/frontend/tests/hooks/swr/product-update.test.tsx | 2++
11 files changed, 49 insertions(+), 5 deletions(-)

diff --git a/packages/frontend/src/components/exception/AsyncButton.tsx b/packages/frontend/src/components/exception/AsyncButton.tsx @@ -1,3 +1,24 @@ +/* + This file is part of GNU Taler + (C) 2021 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + +/** +* +* @author Sebastian Javier Marchano (sebasjm) +*/ + import { ComponentChildren, h } from "preact"; import { LoadingModal } from "../modal"; import { useAsync } from "../../hooks/async"; diff --git a/packages/frontend/src/hooks/async.ts b/packages/frontend/src/hooks/async.ts @@ -73,4 +73,4 @@ export function useAsync<T>(fn?: (...args: any) => Promise<T>, { slowTolerance: isLoading, error }; -}; +} diff --git a/packages/frontend/src/hooks/backend.ts b/packages/frontend/src/hooks/backend.ts @@ -192,6 +192,15 @@ export function cancelPendingRequest() { source = CancelToken.source() } +let allowAxiosCancellation = false +/** + * Jest mocking seems to break when using the cancelToken property. + * Using this workaround when testing while finding the correct solution + */ +export function setAxiosRequestAsTestingEnvironment() { + allowAxiosCancellation = true +} + export async function request<T>(url: string, options: RequestOptions = {}): Promise<HttpResponseOk<T>> { const headers = options.token ? { Authorization: `Bearer ${options.token}` } : undefined @@ -200,7 +209,7 @@ export async function request<T>(url: string, options: RequestOptions = {}): Pro url, responseType: 'json', headers, - cancelToken: source.token, + cancelToken: !allowAxiosCancellation? source.token : undefined, method: options.method || 'get', data: options.data, params: options.params, diff --git a/packages/frontend/src/hooks/index.ts b/packages/frontend/src/hooks/index.ts @@ -116,7 +116,8 @@ export function useNotNullLocalStorage(key: string, initialValue: string): [stri * @returns activator and subscriber, undefined activator means that there is not subscriber */ export function useListener<T, R = any>(action: (r: T) => Promise<R>): [undefined | (() => Promise<R>), (listener?: () => T) => void] { - const [state, setState] = useState<{ toBeRan?: () => Promise<R> }>({}) + type RunnerHandler = { toBeRan?: () => Promise<R> } + const [state, setState] = useState<RunnerHandler>({}) /** * subscriber will receive a method that will be call when the activator runs diff --git a/packages/frontend/src/paths/instance/transfers/list/Table.tsx b/packages/frontend/src/paths/instance/transfers/list/Table.tsx @@ -126,7 +126,7 @@ function Table({ instances, onLoadMoreAfter, onDelete, onLoadMoreBefore, hasMore <th><Translate>Confirmed</Translate></th> <th><Translate>Verified</Translate></th> <th><Translate>Executed at</Translate></th> - <th></th> + <th /> </tr> </thead> <tbody> @@ -140,7 +140,7 @@ function Table({ instances, onLoadMoreAfter, onDelete, onLoadMoreBefore, hasMore <td>{i.verified ? i18n`yes` : i18n`no`}</td> <td>{i.execution_time ? (i.execution_time.t_ms == 'never' ? i18n`never` : format(i.execution_time.t_ms, 'yyyy/MM/dd HH:mm:ss')) : i18n`unknown`}</td> <td> - {i.verified === undefined ? <button class="button is-danger is-small" onClick={() => onDelete(i) }>Delete</button> : undefined } + {i.verified === undefined ? <button class="button is-danger is-small" onClick={() => onDelete(i)}>Delete</button> : undefined} </td> </tr> })} diff --git a/packages/frontend/tests/hooks/swr/order-create.test.tsx b/packages/frontend/tests/hooks/swr/order-create.test.tsx @@ -24,9 +24,11 @@ import * as axios from 'axios'; import * as backend from '../../../src/context/backend'; import * as instance from '../../../src/context/instance'; import { MerchantBackend } from '../../../src/declaration'; +import { setAxiosRequestAsTestingEnvironment } from '../../../src/hooks/backend'; import { useInstanceOrders, useOrderAPI } from '../../../src/hooks/order'; import { simulateBackendResponse } from '../../util' +setAxiosRequestAsTestingEnvironment() jest.mock('axios'); diff --git a/packages/frontend/tests/hooks/swr/order-pagination.test.tsx b/packages/frontend/tests/hooks/swr/order-pagination.test.tsx @@ -24,9 +24,11 @@ import * as axios from 'axios'; import * as backend from '../../../src/context/backend'; import * as instance from '../../../src/context/instance'; import { MerchantBackend } from '../../../src/declaration'; +import { setAxiosRequestAsTestingEnvironment } from '../../../src/hooks/backend'; import { useInstanceOrders } from '../../../src/hooks/order'; import { simulateBackendResponse } from '../../util' +setAxiosRequestAsTestingEnvironment() jest.mock('axios'); diff --git a/packages/frontend/tests/hooks/swr/product-create.test.tsx b/packages/frontend/tests/hooks/swr/product-create.test.tsx @@ -24,9 +24,11 @@ import * as axios from 'axios'; import * as backend from '../../../src/context/backend'; import * as instance from '../../../src/context/instance'; import { MerchantBackend } from '../../../src/declaration'; +import { setAxiosRequestAsTestingEnvironment } from '../../../src/hooks/backend'; import { useInstanceProducts, useProductAPI } from '../../../src/hooks/product'; import { simulateBackendResponse } from '../../util' +setAxiosRequestAsTestingEnvironment() jest.mock('axios'); diff --git a/packages/frontend/tests/hooks/swr/product-delete.test.tsx b/packages/frontend/tests/hooks/swr/product-delete.test.tsx @@ -28,6 +28,9 @@ import { simulateBackendResponse } from '../../util' // eslint-disable-next-line @typescript-eslint/no-unused-vars import * as axios from 'axios'; +import { setAxiosRequestAsTestingEnvironment } from '../../../src/hooks/backend'; + +setAxiosRequestAsTestingEnvironment() jest.mock('axios'); axios.default diff --git a/packages/frontend/tests/hooks/swr/product-details-update.test.tsx b/packages/frontend/tests/hooks/swr/product-details-update.test.tsx @@ -24,9 +24,11 @@ import * as axios from 'axios'; import * as backend from '../../../src/context/backend'; import * as instance from '../../../src/context/instance'; import { MerchantBackend } from '../../../src/declaration'; +import { setAxiosRequestAsTestingEnvironment } from '../../../src/hooks/backend'; import { useProductAPI, useProductDetails } from '../../../src/hooks/product'; import { simulateBackendResponse } from '../../util' +setAxiosRequestAsTestingEnvironment() jest.mock('axios'); diff --git a/packages/frontend/tests/hooks/swr/product-update.test.tsx b/packages/frontend/tests/hooks/swr/product-update.test.tsx @@ -24,9 +24,11 @@ import * as axios from 'axios'; import * as backend from '../../../src/context/backend'; import * as instance from '../../../src/context/instance'; import { MerchantBackend } from '../../../src/declaration'; +import { setAxiosRequestAsTestingEnvironment } from '../../../src/hooks/backend'; import { useInstanceProducts, useProductAPI } from '../../../src/hooks/product'; import { simulateBackendResponse } from '../../util' +setAxiosRequestAsTestingEnvironment() jest.mock('axios');