Skip to content

Commit

Permalink
Clean up errors and warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
shinyichen committed Oct 27, 2023
1 parent 5d0125c commit aec2c99
Show file tree
Hide file tree
Showing 13 changed files with 98 additions and 207 deletions.
1 change: 0 additions & 1 deletion src/components/Libraries/LibrarySelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 10 additions & 6 deletions src/components/Libraries/__tests__/LibrariesLandingTab.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(<LibrariesLandingPane />);
const { user, findByTestId, findByRole, findAllByRole } = render(
<ChakraProvider>
<LibrariesLandingPane />
</ChakraProvider>,
);
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);
});
2 changes: 1 addition & 1 deletion src/components/Pagination/ControlledPaginationControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface IControlledPaginationControlsProps extends FlexProps {
onChangePageIndex: (index: number) => void;
}

export const ControlledPaginationControls = <T extends object>(props: IControlledPaginationControlsProps) => {
export const ControlledPaginationControls = (props: IControlledPaginationControlsProps) => {
const { entries, pageSize, pageIndex, onChangePageIndex, onChangePageSize, ...flexProps } = props;

const pageCount = Math.ceil(entries / pageSize);
Expand Down
2 changes: 1 addition & 1 deletion src/components/ResultList/useHighlights.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
2 changes: 0 additions & 2 deletions src/components/SearchBar/SearchInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -55,7 +54,6 @@ const ClearInputButton = (props: { onClear: () => void } & ButtonProps) => {
export const SearchInput = forwardRef<Partial<HTMLInputElement>, ISearchInputProps>((props, ref) => {
const { query, updateQuery, isClearingQuery, onDoneClearingQuery, queryAddition, onDoneAppendingToQuery } =
useIntermediateQuery();
const latestQuery = useStore((state) => state.latestQuery.q);
const input = useRef<HTMLInputElement>(null);

// allow outside refs to fire focus
Expand Down
95 changes: 50 additions & 45 deletions src/components/__mocks__/libraries.ts
Original file line number Diff line number Diff line change
@@ -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',
},
];
7 changes: 6 additions & 1 deletion src/components/__tests__/LibraryListTable.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(<LibraryListTable />);
render(
<ChakraProvider>
<LibraryListTable />
</ChakraProvider>,
);
});
Loading

0 comments on commit aec2c99

Please sign in to comment.