From 741f6a16fcc16cce2b68bf5fb78893c0c6b4e6a2 Mon Sep 17 00:00:00 2001 From: Jennifer Chen Date: Fri, 27 Oct 2023 12:15:04 -0700 Subject: [PATCH] Clean up errors and warnings --- src/components/Libraries/LibrarySelector.tsx | 1 - .../__tests__/LibrariesLandingTab.test.tsx | 16 +- .../ControlledPaginationControls.tsx | 2 +- src/components/ResultList/useHighlights.ts | 2 +- src/components/SearchBar/SearchInput.tsx | 2 - src/components/__mocks__/libraries.ts | 95 +++++----- .../__tests__/LibraryListTable.test.tsx | 7 +- .../responses/library/all-libraries.json | 164 +++--------------- src/pages/user/settings/application.tsx | 4 +- src/pages/user/settings/email.tsx | 2 +- src/pages/user/settings/export.tsx | 4 +- src/pages/user/settings/librarylink.tsx | 4 +- src/pages/user/settings/password.tsx | 2 +- 13 files changed, 98 insertions(+), 207 deletions(-) diff --git a/src/components/Libraries/LibrarySelector.tsx b/src/components/Libraries/LibrarySelector.tsx index 68482614e..82b7aca90 100644 --- a/src/components/Libraries/LibrarySelector.tsx +++ b/src/components/Libraries/LibrarySelector.tsx @@ -5,7 +5,6 @@ import { LoadingMessage } from '@components'; import { NumPerPageType } from '@types'; import { useState, useMemo } from 'react'; import { ILibraryListTableSort, LibraryListTable } from './LibraryListTable'; -import { TableSkeleton } from './TableSkeleton'; export const LibrarySelector = ({ isMultiple, diff --git a/src/components/Libraries/__tests__/LibrariesLandingTab.test.tsx b/src/components/Libraries/__tests__/LibrariesLandingTab.test.tsx index b767a4e61..80aa6d0f8 100644 --- a/src/components/Libraries/__tests__/LibrariesLandingTab.test.tsx +++ b/src/components/Libraries/__tests__/LibrariesLandingTab.test.tsx @@ -3,24 +3,28 @@ import { expect, test, TestContext } from 'vitest'; import allLibsResponse from '@mocks/responses/library/all-libraries.json'; import { rest } from 'msw'; import { ApiTargets } from '@api'; -import { LibraryListTable } from '../LibraryListTable'; import { LibrariesLandingPane } from '../LibrariesLandingPane'; +import { ChakraProvider } from '@chakra-ui/react'; test('renders without issue', async ({ server }: TestContext) => { const { onRequest } = createServerListenerMocks(server); server.use(rest.get(apiHandlerRoute(ApiTargets.LIBRARIES), (req, res, ctx) => res(ctx.json(allLibsResponse)))); - const { user, findByTestId, findByRole, findAllByRole } = render(); + const { user, findByTestId, findByRole, findAllByRole } = render( + + + , + ); const table = await findByTestId('libraries-table'); - expect(table.querySelectorAll('tr').length).toBe(16); // incl. header + expect(table.querySelectorAll('tr').length).toBe(6); // incl. header const pageSizeSelector = await findByTestId('page-size-selector'); expect(pageSizeSelector.querySelectorAll('option')[0].selected).toBeTruthy(); const paginationString = await findByTestId('pagination-string'); - expect(paginationString.textContent).toEqual('Showing 1 to 10 of 15 results'); + expect(paginationString.textContent).toEqual('Showing 1 to 5 of 5 results'); fireEvent.change(pageSizeSelector, { target: { value: 25 } }); - expect((await findByTestId('pagination-string')).textContent).toEqual('Showing 1 to 15 of 15 results'); - expect((await findByTestId('libraries-table')).querySelectorAll('tr').length).toBe(16); + expect((await findByTestId('pagination-string')).textContent).toEqual('Showing 1 to 5 of 5 results'); + expect((await findByTestId('libraries-table')).querySelectorAll('tr').length).toBe(6); }); diff --git a/src/components/Pagination/ControlledPaginationControls.tsx b/src/components/Pagination/ControlledPaginationControls.tsx index 742e5486c..0dcbf8735 100644 --- a/src/components/Pagination/ControlledPaginationControls.tsx +++ b/src/components/Pagination/ControlledPaginationControls.tsx @@ -12,7 +12,7 @@ export interface IControlledPaginationControlsProps extends FlexProps { onChangePageIndex: (index: number) => void; } -export const ControlledPaginationControls = (props: IControlledPaginationControlsProps) => { +export const ControlledPaginationControls = (props: IControlledPaginationControlsProps) => { const { entries, pageSize, pageIndex, onChangePageIndex, onChangePageSize, ...flexProps } = props; const pageCount = Math.ceil(entries / pageSize); diff --git a/src/components/ResultList/useHighlights.ts b/src/components/ResultList/useHighlights.ts index 983b6b461..cc095bbdb 100644 --- a/src/components/ResultList/useHighlights.ts +++ b/src/components/ResultList/useHighlights.ts @@ -1,4 +1,4 @@ -import { IADSApiSearchResponse, useGetHighlights } from '@api'; +import { useGetHighlights } from '@api'; import { useToast } from '@chakra-ui/react'; import { AppState, useStore } from '@store'; import { decode } from 'he'; diff --git a/src/components/SearchBar/SearchInput.tsx b/src/components/SearchBar/SearchInput.tsx index e90b381ee..934aca759 100644 --- a/src/components/SearchBar/SearchInput.tsx +++ b/src/components/SearchBar/SearchInput.tsx @@ -24,7 +24,6 @@ import { useIntermediateQuery } from '@lib/useIntermediateQuery'; import { isNilOrEmpty } from 'ramda-adjunct'; import { filterItems } from '@components/SearchBar/helpers'; import { TypeaheadOption } from '@components/SearchBar/types'; -import { useStore } from '@store'; export interface ISearchInputProps { isLoading?: boolean; @@ -55,7 +54,6 @@ const ClearInputButton = (props: { onClear: () => void } & ButtonProps) => { export const SearchInput = forwardRef, ISearchInputProps>((props, ref) => { const { query, updateQuery, isClearingQuery, onDoneClearingQuery, queryAddition, onDoneAppendingToQuery } = useIntermediateQuery(); - const latestQuery = useStore((state) => state.latestQuery.q); const input = useRef(null); // allow outside refs to fire focus diff --git a/src/components/__mocks__/libraries.ts b/src/components/__mocks__/libraries.ts index c750a1c03..6bea07fdf 100644 --- a/src/components/__mocks__/libraries.ts +++ b/src/components/__mocks__/libraries.ts @@ -1,59 +1,64 @@ -import { LibraryMeta } from '@components'; +import { ILibraryMetadata } from '@api'; -export const libraries: LibraryMeta[] = [ +export const libraries: ILibraryMetadata[] = [ { - id: '1', - visibility: 'public', - collaborators: 0, - name: 'My Shared Public Library', - description: 'my first library', - papers: 200, - owner: 'JC', + name: 'lib-1', + id: '111', + description: 'My ADS library', + num_documents: 0, + date_created: '2023-09-05T22:12:05.511383', + date_last_modified: '2023-09-05T22:12:05.511393', permission: 'owner', - lastModified: '', + public: false, + num_users: 1, + owner: 'ads', }, { - id: '2', - visibility: 'private', - collaborators: 2, - name: 'My Public Library', - description: 'some public library', - papers: 500, - owner: 'JC', + name: 'lib-2', + id: '222', + description: 'My ADS library', + num_documents: 0, + date_created: '2023-09-05T22:12:29.460672', + date_last_modified: '2023-09-05T22:12:29.460680', permission: 'owner', - lastModified: '', + public: false, + num_users: 1, + owner: 'ads', }, { - id: '3', - visibility: 'private', - collaborators: 1, - name: 'My Shared Private Library', - description: 'some private library', - papers: 100, - owner: 'JC', - permission: 'owner', - lastModified: '', + name: 'lib-3', + id: '333', + description: 'silly library', + num_documents: 3, + date_created: '2023-09-18T17:46:02.068300', + date_last_modified: '2023-09-18T18:16:33.668957', + permission: 'read', + public: true, + num_users: 2, + owner: 'johnny', }, { - id: '4', - visibility: 'private', - collaborators: 0, - name: "ABC's Library", - description: 'a library', - papers: 200, - owner: 'ABC', - permission: 'admin', - lastModified: '', + name: 'lib-4', + id: '444', + description: 'another silly library', + num_documents: 505, + date_created: '2023-09-18T18:24:06.510578', + date_last_modified: '2023-10-25T16:59:44.352260', + permission: 'write', + public: true, + num_users: 2, + owner: 'tracy', }, { - id: '1', - visibility: 'private', - collaborators: 5, - name: "ABC's Library", - description: 'another library', - papers: 300, - owner: 'ABC', - permission: 'read', - lastModified: '', + name: 'lib-5', + id: '555', + description: 'An ADS library', + num_documents: 0, + date_created: '2023-09-22T14:05:34.650827', + date_last_modified: '2023-09-22T14:05:34.650837', + permission: 'admin', + public: false, + num_users: 2, + owner: 'amy', }, ]; diff --git a/src/components/__tests__/LibraryListTable.test.tsx b/src/components/__tests__/LibraryListTable.test.tsx index 943dc98bc..ea4e05dd0 100644 --- a/src/components/__tests__/LibraryListTable.test.tsx +++ b/src/components/__tests__/LibraryListTable.test.tsx @@ -2,9 +2,14 @@ import { render } from '@test-utils'; import { test } from 'vitest'; import { composeStories } from '@storybook/testing-react'; import * as stories from '../__stories__/LibraryListTable.stories'; +import { ChakraProvider } from '@chakra-ui/react'; const { Default: LibraryListTable } = composeStories(stories); test('renders without crashing', () => { - render(); + render( + + + , + ); }); diff --git a/src/mocks/responses/library/all-libraries.json b/src/mocks/responses/library/all-libraries.json index 7c765ddc5..a00d52eda 100644 --- a/src/mocks/responses/library/all-libraries.json +++ b/src/mocks/responses/library/all-libraries.json @@ -1,68 +1,8 @@ { "libraries": [ { - "name": "Test_Admin", - "id": "RpZcWt0SRRmDT7q29U6AUw", - "description": "Union of 6f7d1571-c427-4a6a-942b-326d72369c1c with []", - "num_documents": 4, - "date_created": "2019-04-15T19:03:15.345389", - "date_last_modified": "2021-04-01T15:11:10.995740", - "permission": "admin", - "public": false, - "num_users": 2, - "owner": "misc+scix" - }, - { - "name": "Test_Write/Read", - "id": "PWk7fXxbSS2U6jo_lWHawQ", - "description": "Union of 6f7d1571-c427-4a6a-942b-326d72369c1c with []", - "num_documents": 5, - "date_created": "2019-04-15T19:03:56.246891", - "date_last_modified": "2021-08-28T05:03:27.780969", - "permission": "write", - "public": true, - "num_users": 2, - "owner": "misc+scix" - }, - { - "name": "Test_Read", - "id": "eWf42mSBSdigxtGhmKe3Mg", - "description": "Union of libraries Untitled 2019-04-15T19:03:15.312809+00:00., pooooo (IDs: RpZcWt0SRRmDT7q29U6AUw, ZsqgYsCdRB-mL-aIa4Mylg)", - "num_documents": 4, - "date_created": "2019-04-30T17:37:54.052677", - "date_last_modified": "2021-04-01T15:08:25.317810", - "permission": "read", - "public": false, - "num_users": 0, - "owner": "misc+scix" - }, - { - "name": "test1", - "id": "G4MOEjynQFCRK_QRWlK0EQ", - "description": "My ADS library", - "num_documents": 1998, - "date_created": "2022-02-23T21:25:13.500854", - "date_last_modified": "2022-03-31T20:27:22.080563", - "permission": "owner", - "public": false, - "num_users": 1, - "owner": "ads" - }, - { - "name": "test2", - "id": "sdlUxwk8T6SNlw0NOXelxQ", - "description": "My ADS library", - "num_documents": 503, - "date_created": "2022-02-23T21:44:10.593087", - "date_last_modified": "2022-03-31T20:27:27.948129", - "permission": "owner", - "public": true, - "num_users": 1, - "owner": "ads" - }, - { - "name": "test - jennifer", - "id": "0alXsBucQRa1mygeHfp2KA", + "name": "lib-1", + "id": "111", "description": "My ADS library", "num_documents": 0, "date_created": "2023-09-05T22:12:05.511383", @@ -73,8 +13,8 @@ "owner": "ads" }, { - "name": "Untitled Library 1", - "id": "t3zVuueCRfu0Q1vg_1iKrw", + "name": "lib-2", + "id": "222", "description": "My ADS library", "num_documents": 0, "date_created": "2023-09-05T22:12:29.460672", @@ -85,100 +25,40 @@ "owner": "ads" }, { - "name": "silly library", - "id": "YCLtN1U1SGOHW4EgSbhDIg", + "name": "lib-3", + "id": "333", "description": "silly library", "num_documents": 3, "date_created": "2023-09-18T17:46:02.068300", "date_last_modified": "2023-09-18T18:16:33.668957", - "permission": "owner", + "permission": "read", "public": true, - "num_users": 1, - "owner": "ads" + "num_users": 2, + "owner": "johnny" }, { - "name": "silly 2", - "id": "XTkEXFtiTLug4mfelLGtOQ", + "name": "lib-4", + "id": "444", "description": "another silly library", - "num_documents": 506, + "num_documents": 505, "date_created": "2023-09-18T18:24:06.510578", - "date_last_modified": "2023-09-18T18:24:06.510585", - "permission": "owner", + "date_last_modified": "2023-10-25T16:59:44.352260", + "permission": "write", "public": true, - "num_users": 1, - "owner": "ads" + "num_users": 2, + "owner": "tracy" }, { - "name": "10", - "id": "4b4LpubeTLinpCYguezg6A", - "description": "My ADS library", + "name": "lib-5", + "id": "555", + "description": "An ADS library", "num_documents": 0, "date_created": "2023-09-22T14:05:34.650827", "date_last_modified": "2023-09-22T14:05:34.650837", - "permission": "owner", - "public": false, - "num_users": 1, - "owner": "ads" - }, - { - "name": "11", - "id": "7DLp9zRxRCmS-zWQAPGCkg", - "description": "My ADS library", - "num_documents": 0, - "date_created": "2023-09-22T14:05:43.462906", - "date_last_modified": "2023-09-22T14:05:43.462912", - "permission": "owner", - "public": false, - "num_users": 1, - "owner": "ads" - }, - { - "name": "2rqefe", - "id": "2HHuLDJ1SWmbZ8JMOlESaw", - "description": "sadasdf", - "num_documents": 0, - "date_created": "2023-09-22T14:18:43.694109", - "date_last_modified": "2023-09-22T14:18:43.694115", - "permission": "owner", - "public": false, - "num_users": 1, - "owner": "ads" - }, - { - "name": "34234", - "id": "hPpr-05VRW2wT7cXCEisUA", - "description": "My ADS library", - "num_documents": 0, - "date_created": "2023-09-22T14:19:00.722135", - "date_last_modified": "2023-09-22T14:19:00.722140", - "permission": "owner", - "public": false, - "num_users": 1, - "owner": "ads" - }, - { - "name": "abc", - "id": "JlzmnuucSLO-OjPn9IhOvw", - "description": "My ADS library", - "num_documents": 0, - "date_created": "2023-09-22T14:23:30.150520", - "date_last_modified": "2023-09-22T14:23:30.150528", - "permission": "owner", - "public": false, - "num_users": 1, - "owner": "ads" - }, - { - "name": "wewae", - "id": "fJWfjchhS7ipKRdjw2JGXA", - "description": "My ADS library", - "num_documents": 0, - "date_created": "2023-09-22T14:24:17.783704", - "date_last_modified": "2023-09-22T14:24:17.783711", - "permission": "owner", + "permission": "admin", "public": false, - "num_users": 1, - "owner": "ads" + "num_users": 2, + "owner": "amy" } ] } diff --git a/src/pages/user/settings/application.tsx b/src/pages/user/settings/application.tsx index 9ce7e0836..9be5ed748 100644 --- a/src/pages/user/settings/application.tsx +++ b/src/pages/user/settings/application.tsx @@ -18,7 +18,7 @@ import { SettingsLayout, } from '@components'; import { composeNextGSSP } from '@ssr-utils'; -import { GetServerSideProps, GetServerSidePropsContext } from 'next'; +import { GetServerSideProps } from 'next'; import { Suspense, useEffect, useMemo, useState } from 'react'; import { dehydrate, QueryClient, QueryErrorResetBoundary } from '@tanstack/react-query'; import { ErrorBoundary } from 'react-error-boundary'; @@ -175,7 +175,7 @@ const AppSettingsPage = () => { export default Page; -export const getServerSideProps: GetServerSideProps = composeNextGSSP(async (ctx: GetServerSidePropsContext) => { +export const getServerSideProps: GetServerSideProps = composeNextGSSP(async () => { const queryClient = new QueryClient(); await queryClient.prefetchQuery({ queryKey: userKeys.getUserSettings(), diff --git a/src/pages/user/settings/email.tsx b/src/pages/user/settings/email.tsx index db91eb0ce..60272fdd4 100644 --- a/src/pages/user/settings/email.tsx +++ b/src/pages/user/settings/email.tsx @@ -16,7 +16,7 @@ const UpdateEmailPage = () => { const { mutate: submit, error, isError, isLoading, data } = useChangeUserEmail(); const [mainInputRef] = useFocus(); - const onFormSubmit: SubmitHandler = (params, e) => { + const onFormSubmit: SubmitHandler = (params) => { submit(params); }; diff --git a/src/pages/user/settings/export.tsx b/src/pages/user/settings/export.tsx index 24820da7d..969d21a1c 100644 --- a/src/pages/user/settings/export.tsx +++ b/src/pages/user/settings/export.tsx @@ -14,7 +14,7 @@ import { import { Spinner, Tab, TabList, TabPanel, TabPanels, Tabs } from '@chakra-ui/react'; import { BibtexTabPanel, CustomFormatsTabPanel, exportFormats, GeneralTabPanel, SettingsLayout } from '@components'; import { useSettings } from '@lib/useSettings'; -import { GetServerSideProps, GetServerSidePropsContext, NextPage } from 'next'; +import { GetServerSideProps, NextPage } from 'next'; import { Reducer, Suspense, useEffect, useMemo, useReducer } from 'react'; import { v4 as uuidv4 } from 'uuid'; import { dehydrate, QueryClient, QueryErrorResetBoundary } from '@tanstack/react-query'; @@ -185,7 +185,7 @@ const ExportSettings = () => { }; export default Page; -export const getServerSideProps: GetServerSideProps = composeNextGSSP(async (ctx: GetServerSidePropsContext) => { +export const getServerSideProps: GetServerSideProps = composeNextGSSP(async () => { // get a sample doc const params = getSearchParams({ q: 'bibstem:ApJ author_count:[10 TO 20]', rows: 1 }); const queryClient = new QueryClient(); diff --git a/src/pages/user/settings/librarylink.tsx b/src/pages/user/settings/librarylink.tsx index a60dd2203..64e9d35e2 100644 --- a/src/pages/user/settings/librarylink.tsx +++ b/src/pages/user/settings/librarylink.tsx @@ -4,7 +4,7 @@ import { useMemo } from 'react'; import { useSettings } from '@lib/useSettings'; import { chakra, Heading, Icon, Text, VStack } from '@chakra-ui/react'; import { AcademicCapIcon } from '@heroicons/react/20/solid'; -import { GetServerSideProps, GetServerSidePropsContext } from 'next'; +import { GetServerSideProps } from 'next'; import { composeNextGSSP } from '@ssr-utils'; import { dehydrate, QueryClient } from '@tanstack/react-query'; @@ -93,7 +93,7 @@ const MyInstitution = () => { export default LibraryLinkServerPage; -export const getServerSideProps: GetServerSideProps = composeNextGSSP(async (ctx: GetServerSidePropsContext) => { +export const getServerSideProps: GetServerSideProps = composeNextGSSP(async () => { const queryClient = new QueryClient(); // prefetch link servers diff --git a/src/pages/user/settings/password.tsx b/src/pages/user/settings/password.tsx index 086189abe..f974bbbd5 100644 --- a/src/pages/user/settings/password.tsx +++ b/src/pages/user/settings/password.tsx @@ -26,7 +26,7 @@ const ChangePasswordPage = () => { const { ref, ...registerProps } = register('currentPassword', { required: true }); const [currentPasswordRef] = useFocus(); - const onFormSubmit: SubmitHandler = (params, e) => { + const onFormSubmit: SubmitHandler = (params) => { submit(params); };