Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nickakhmetov/HMP-194 Apply fixes from lint config #3143

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
1f2dc00
`npm run lint:fix` autofixes only
NickAkhmetov Jun 27, 2023
57806b6
Fix `react/no-unstable-nested-components` error
NickAkhmetov Jun 27, 2023
e88b8cc
allow use of require in jest tests
NickAkhmetov Jun 27, 2023
b9fb281
fix resolution of `fonts.ts` file asking for the extension
NickAkhmetov Jun 27, 2023
a964374
Fix `react/jsx-no-constructed-context-values` errors
NickAkhmetov Jun 27, 2023
e70f38e
Allow helpers that contain `expect` statements to be used as the only…
NickAkhmetov Jun 27, 2023
b6ad5ea
add tsconfig to dockerfile
NickAkhmetov Jun 27, 2023
a939c7d
Fix `react/no-unstable-nested-components` with `DetailPanel` getting …
NickAkhmetov Jun 27, 2023
189cf51
Fix undefined `test` global in test fixtures
NickAkhmetov Jun 27, 2023
6f5c2d6
Disable `jsx-no-bind` rule
NickAkhmetov Jun 28, 2023
adb0f0b
Must use destructuring `themeContext` assignment (`react/destructurin…
NickAkhmetov Jun 28, 2023
2bf9771
`Default parameters should be last`
NickAkhmetov Jun 28, 2023
3cdd8a4
Reorganized debounced vitessce config setter to avoid using `useCallb…
NickAkhmetov Jun 28, 2023
9572b0c
Name HOC components (`func-names`)
NickAkhmetov Jun 28, 2023
d1c2280
fix `no-unused-vars`; allow unused vars if they start with `_` prefix
NickAkhmetov Jun 28, 2023
72ca7f7
use destructuring props assignment
NickAkhmetov Jun 28, 2023
4463fca
`react/jsx-no-constructed-context-values`
NickAkhmetov Jun 28, 2023
44c6a77
allow empty function placeholders in test files
NickAkhmetov Jun 28, 2023
0a5402a
add assertions to accordion list filter tests
NickAkhmetov Jun 28, 2023
653b8aa
Avoid destructuring queries from `render` result, use `screen.getByTe…
NickAkhmetov Jun 28, 2023
630c50a
another "screen" fix
NickAkhmetov Jun 28, 2023
7938dd4
allow "redundant" story names pending further investigation
NickAkhmetov Jun 28, 2023
a50b498
reorganize to make sure components are only referenced after they're …
NickAkhmetov Jun 28, 2023
a0b57ff
uncomment test for the time being, will troubleshoot
NickAkhmetov Jun 28, 2023
f4db659
prepend unused var with `_`
NickAkhmetov Jun 28, 2023
36856b2
fix describe block name
NickAkhmetov Jun 28, 2023
6424105
remove `as default`, make it an explicit default export
NickAkhmetov Jun 28, 2023
0ca12d9
allow variables to remain unused if spreading object to remove those …
NickAkhmetov Jun 28, 2023
778bd2c
Add explicit explanation for empty effect cleanup function
NickAkhmetov Jun 28, 2023
1ec2929
Use `getBy*` queries rather than `queryBy*` for checking element is p…
NickAkhmetov Jun 28, 2023
65ed652
explicitly use default export instead of `as default`
NickAkhmetov Jun 28, 2023
989fc08
use `useMemo` to manage SearchKitManager instance to fix `useEffect` …
NickAkhmetov Jun 28, 2023
4933ef1
add swc helpers package to dev dependencies to make jest test suites …
NickAkhmetov Jun 28, 2023
2254352
Fix ProvVis test
NickAkhmetov Jun 28, 2023
d29339f
fix accordion filter tests
NickAkhmetov Jun 28, 2023
a772eb2
Add `buffer` polyfill to make docker image build correctly
NickAkhmetov Jun 28, 2023
88497f5
Fix maintenance cypress test
NickAkhmetov Jun 28, 2023
617a402
Merge branch 'nickakhmetov/hmp-194-lint-config' into nickakhmetov/hmp…
NickAkhmetov Jun 29, 2023
fb70724
remove unnecessary usecallbacks
NickAkhmetov Jun 30, 2023
af27648
Update context/app/static/js/components/entity-search/SearchWrapper/u…
NickAkhmetov Jun 30, 2023
fd177b7
Fix Jest test-utils resolution
NickAkhmetov Jun 30, 2023
02a4743
remove unnecessary import
NickAkhmetov Jun 30, 2023
639673a
Change ProvData constructor to an object
NickAkhmetov Jul 5, 2023
f7f6779
Merge branch 'nickakhmetov/hmp-194-lint-config' into nickakhmetov/hmp…
NickAkhmetov Jul 5, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions context/.babelrc

This file was deleted.

4 changes: 4 additions & 0 deletions context/.eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ overrides:
- plugin:jest/recommended
- plugin:jest-dom/recommended
- plugin:testing-library/react
settings:
'import/resolver':
jest:
jestConfigFile: ./jest.config.js
env:
jest: true
jest/globals: true
Expand Down
2 changes: 1 addition & 1 deletion context/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ COPY .npmrc .

RUN npm ci

COPY .babelrc .babelrc
COPY tsconfig.json tsconfig.json
COPY .swcrc .swcrc
COPY build-utils build-utils
COPY app app
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable import/no-unresolved */
import React from 'react';
import { render, screen } from 'test-utils/functions';
import { fireEvent } from '@testing-library/react';
Expand All @@ -12,7 +11,7 @@ test('should be "User Profile" when not authenticated', () => {
// In drop-down:
expect(screen.getByText('My Lists')).toBeInTheDocument();
expect(screen.getByText('Log In')).toBeInTheDocument();
expect(screen.queryByText('Log Out')).toBeNull();
expect(screen.queryByText('Log Out')).not.toBeInTheDocument();
});

test('should be logout button when authenticated', () => {
Expand All @@ -22,7 +21,7 @@ test('should be logout button when authenticated', () => {
// In drop-down:
expect(screen.getByText('My Lists')).toBeInTheDocument();
expect(screen.getByText('Log Out')).toBeInTheDocument();
expect(screen.queryByText('Log In')).toBeNull();
expect(screen.queryByText('Log In')).not.toBeInTheDocument();
});

test('should display User when userEmail is empty', () => {
Expand Down
20 changes: 15 additions & 5 deletions context/app/static/js/components/Providers.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useMemo } from 'react';
import { FlaskDataContext, AppContext } from 'js/components/Contexts';
import { ThemeProvider } from 'styled-components';
import PropTypes from 'prop-types';
Expand All @@ -23,15 +23,25 @@ function Providers({
isWorkspacesUser,
flaskData,
}) {
// injectFirst ensures styled-components takes priority over mui for styling
const appContext = useMemo(
() => ({
groupsToken,
workspacesToken,
isWorkspacesUser,
isAuthenticated,
userEmail,
...endpoints,
}),
[groupsToken, workspacesToken, isWorkspacesUser, isAuthenticated, userEmail, endpoints],
);

return (
// injectFirst ensures styled-components takes priority over mui for styling
<StylesProvider generateClassName={generateClassName} injectFirst>
<GlobalFonts />
<MuiThemeProvider theme={theme}>
<ThemeProvider theme={theme}>
<AppContext.Provider
value={{ groupsToken, workspacesToken, isWorkspacesUser, isAuthenticated, userEmail, ...endpoints }}
>
<AppContext.Provider value={appContext}>
<FlaskDataContext.Provider value={flaskData}>
<CssBaseline />
<GlobalStyles />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ test.each([
expect(removeUUIDFromOption(option, 'UUID')).toEqual(expected);
});

test('should ', () => {
test('should', () => {
expect(getOptionLabels(['123-UUID-xyz', 'abc-456-UUID'], 'UUID')).toStrictEqual({
'123-UUID-xyz': '123-xyz',
'abc-456-UUID': 'abc-456',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable import/no-unresolved */
import React from 'react';
import { render, screen } from 'test-utils/functions';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ function CellsTutorial({ setParametersButtonRef, runQueryButtonRef }) {
setOpenStepIndex(1);
}
};
const {
palette: {
info: { dark: arrowColor },
},
zIndex: { tutorial: zIndex },
} = themeContext;

return (
<>
Expand All @@ -84,8 +90,8 @@ function CellsTutorial({ setParametersButtonRef, runQueryButtonRef }) {
tooltipComponent={TutorialTooltip}
styles={{
options: {
arrowColor: themeContext.palette.info.dark,
zIndex: themeContext.zIndex.tutorial,
arrowColor,
zIndex,
overlayColor: 'rgba(0, 0, 0, 0)',
},
}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
/* eslint-disable import/no-unresolved */
import React from 'react';
import { render } from 'test-utils/functions';
import { render, screen } from 'test-utils/functions';
import Attribution from './Attribution';

test('text displays properly', () => {
const group_name = 'Fake TMC';
const created_by_user_displayname = 'Fake Name';
const created_by_user_email = '[email protected]';
const { getByText } = render(
render(
<Attribution
group_name={group_name}
created_by_user_displayname={created_by_user_displayname}
created_by_user_email={created_by_user_email}
/>,
);
const textToTest = ['Attribution', 'Group', 'Fake TMC', 'Registered by', 'Fake Name', '[email protected]'];
textToTest.forEach((text) => expect(getByText(text)).toBeInTheDocument());
textToTest.forEach((text) => expect(screen.getByText(text)).toBeInTheDocument());
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable import/no-unresolved */
import React from 'react';
import { render, screen } from 'test-utils/functions';
import { composeStories } from '@storybook/testing-react';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ export default {
component: CitationComponent,
};

export const Citation = (args) => <CitationComponent {...args} />;
export function Citation(args) {
return <CitationComponent {...args} />;
}
Citation.args = {
contributors: [
{ last_name: 'Aanders', first_name: 'Aanne' },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable import/no-unresolved */

import { tableDataToRows, getDescription } from './MetadataTable';

test('should handle plain fields', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable import/no-unresolved */
import React from 'react';
import { render, screen } from 'test-utils/functions';
import SampleTissue from './SampleTissue';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable import/no-unresolved */
import React from 'react';
import { render, screen } from 'test-utils/functions';
import StatusIcon from './StatusIcon';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable import/no-unresolved */
import React from 'react';
import { render, screen } from 'test-utils/functions';
import SupportAlert from './SupportAlert';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable import/no-unresolved */
import React from 'react';
import userEvent from '@testing-library/user-event';
import { render, screen } from 'test-utils/functions';
Expand All @@ -12,20 +11,23 @@ const fakeOpenDUA = jest.fn();

const uuid = 'fakeuuid';

const FilesProviders = ({ children }) => {
const detailContext = { uuid };
const filesContext = { openDUA: fakeOpenDUA, hasAgreedToDUA: 'fakedua' };
const flaskDataContext = { entity: { entity_type: 'Dataset' } };

function FilesProviders({ children }) {
return (
<FlaskDataContext.Provider value={{ entity: { entity_type: 'Dataset' } }}>
<DetailContext.Provider value={{ uuid }}>
<FilesContext.Provider value={{ openDUA: fakeOpenDUA, hasAgreedToDUA: 'fakedua' }}>
{children}
</FilesContext.Provider>
<FlaskDataContext.Provider value={flaskDataContext}>
<DetailContext.Provider value={detailContext}>
<FilesContext.Provider value={filesContext}>{children}</FilesContext.Provider>
</DetailContext.Provider>
</FlaskDataContext.Provider>
);
};
}

const expectArrayOfStringsToExist = (arr) => arr.forEach((text) => expect(screen.getByText(text)).toBeInTheDocument());
const expectArrayOfStringsToNotExist = (arr) => arr.forEach((text) => expect(screen.queryByText(text)).toBeNull());
const expectArrayOfStringsToNotExist = (arr) =>
arr.forEach((text) => expect(screen.queryByText(text)).not.toBeInTheDocument());

test('displays files and directories', () => {
const sharedEntries = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable import/no-unresolved */
import React from 'react';
import userEvent from '@testing-library/user-event';

Expand Down Expand Up @@ -33,7 +32,7 @@ test('does not display when isOpen prop is false', () => {
/>,
);

expect(screen.queryByRole('dialog')).toBeNull();
expect(screen.queryByRole('dialog')).not.toBeInTheDocument();
});

test('displays correct text for protected access level', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable import/no-unresolved */
import React from 'react';
import userEvent from '@testing-library/user-event';

Expand All @@ -23,7 +22,7 @@ test('handles click', () => {
</FileBrowserDirectory>,
);

expect(screen.queryByText('directory child')).toBeNull();
expect(screen.queryByText('directory child')).not.toBeInTheDocument();
userEvent.click(screen.getByRole('button'));
expect(screen.getByText('directory child')).toBeInTheDocument();
});
Expand All @@ -35,7 +34,7 @@ test('handles key down', () => {
</FileBrowserDirectory>,
);

expect(screen.queryByText('directory child')).toBeNull();
expect(screen.queryByText('directory child')).not.toBeInTheDocument();
fireEvent.keyDown(screen.getByRole('button'), { key: 'Enter', code: 'Enter', keyCode: 13 });
expect(screen.getByText('directory child')).toBeInTheDocument();
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable import/no-unresolved */
import React from 'react';
import { render, screen, appProviderEndpoints, appProviderToken } from 'test-utils/functions';
// import userEvent from '@testing-library/user-event';
Expand All @@ -11,15 +10,16 @@ const fakeOpenDUA = jest.fn();

const uuid = 'fakeuuid';

const FilesProviders = ({ children }) => {
const detailContext = { uuid };
const filesContext = { openDUA: fakeOpenDUA, hasAgreedToDUA: 'fakedua' };

function FilesProviders({ children }) {
return (
<DetailContext.Provider value={{ uuid }}>
<FilesContext.Provider value={{ openDUA: fakeOpenDUA, hasAgreedToDUA: 'fakedua' }}>
{children}
</FilesContext.Provider>
<DetailContext.Provider value={detailContext}>
<FilesContext.Provider value={filesContext}>{children}</FilesContext.Provider>
</DetailContext.Provider>
);
};
}

test('displays a link with correct href when dua is agreed to', () => {
const fileObj = {
Expand Down Expand Up @@ -104,7 +104,7 @@ test('does not display QA chip when is_qa_qc is not provided', () => {
</FilesProviders>,
);

expect(screen.queryByText('QA')).toBeNull();
expect(screen.queryByText('QA')).not.toBeInTheDocument();
});

test('does not display QA chip when is_qa_qc is false', () => {
Expand All @@ -125,5 +125,5 @@ test('does not display QA chip when is_qa_qc is false', () => {
</FilesProviders>,
);

expect(screen.queryByText('QA')).toBeNull();
expect(screen.queryByText('QA')).not.toBeInTheDocument();
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable import/no-unresolved */
import React from 'react';
import { render, screen } from 'test-utils/functions';

Expand All @@ -10,15 +9,16 @@ const fakeOpenDUA = jest.fn();

const uuid = 'fakeuuid';

const FilesProviders = ({ children }) => {
const detailContext = { uuid };
const filesContext = { openDUA: fakeOpenDUA, hasAgreedToDUA: 'fakedua' };

function FilesProviders({ children }) {
return (
<DetailContext.Provider value={{ uuid }}>
<FilesContext.Provider value={{ openDUA: fakeOpenDUA, hasAgreedToDUA: 'fakedua' }}>
{children}
</FilesContext.Provider>
<DetailContext.Provider value={detailContext}>
<FilesContext.Provider value={filesContext}>{children}</FilesContext.Provider>
</DetailContext.Provider>
);
};
}

function FakeFileObject(i) {
this.rel_path = `fakepath${i}`;
Expand Down
18 changes: 10 additions & 8 deletions context/app/static/js/components/detailPage/files/Files/Files.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useContext } from 'react';
import React, { useState, useContext, useCallback, useMemo } from 'react';
import PropTypes from 'prop-types';

import DetailContext from 'js/components/detailPage/context';
Expand All @@ -18,24 +18,26 @@ function Files({ files, uuid, hubmap_id, visLiftedUUID }) {
const [isDialogOpen, setDialogOpen] = useState(false);
const [urlClickedBeforeDUA, setUrlClickedBeforeDUA] = useState('');

function handleDUAAgree() {
const handleDUAAgree = useCallback(() => {
agreeToDUA(true);
localStorage.setItem(localStorageKey, true);
setDialogOpen(false);
window.open(urlClickedBeforeDUA, '_blank');
}
}, [agreeToDUA, localStorageKey, setDialogOpen, urlClickedBeforeDUA]);

function handleDUAClose() {
const handleDUAClose = useCallback(() => {
setDialogOpen(false);
}
}, []);

function openDUA(linkUrl) {
const openDUA = useCallback((linkUrl) => {
setDialogOpen(true);
setUrlClickedBeforeDUA(linkUrl);
}
}, []);

const filesContext = useMemo(() => ({ openDUA, hasAgreedToDUA }), [openDUA, hasAgreedToDUA]);

return (
<FilesContext.Provider value={{ openDUA, hasAgreedToDUA }}>
<FilesContext.Provider value={filesContext}>
<DetailPageSection id="files">
<SectionHeader>Files</SectionHeader>
{files.length > 0 && (
Expand Down
Loading