Skip to content

Commit 5a51012

Browse files
committed
Add lint cmd to client package
1 parent 2888bca commit 5a51012

52 files changed

Lines changed: 364 additions & 326 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

apps/client/.eslintrc.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,12 @@ module.exports = {
2929
'object-curly-spacing': ['error', 'always'],
3030
allowIndentationTabs: 0,
3131
'no-extra-parens': ['off'],
32-
'no-duplicate-imports': ['error'],
32+
'no-duplicate-imports': 'off',
33+
// '@typescript-eslint/no-duplicate-imports': ['error'],
34+
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_', varsIgnorePattern: '^_', caughtErrorsIgnorePattern: '^_' }],
3335
'no-multi-spaces': 'error',
3436
'react/prop-types': ['off'],
37+
'react/react-in-jsx-scope': 'off',
3538
'comma-dangle': 'off',
3639
'no-tabs': 'off',
3740
'no-multiple-empty-lines': 'off',
@@ -59,7 +62,7 @@ module.exports = {
5962
},
6063
settings: {
6164
react: {
62-
version: '19.1.1'
65+
version: '18.3.1'
6366
}
6467
},
6568
ignorePatterns: ['_pluginWebWorkers.ts']

apps/client/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"purge": "npx rimraf node_modules dist dist-workers .turbo",
1717
"watch": "npm run build-assets & npm run build-webpack:dev",
1818
"test": "jest --config=./config/jest.config.js",
19+
"lint": "eslint src --ext .ts,.tsx",
1920
"webpackDev": "webpack serve --config ./webpack.config.js --mode=development",
2021
"webpackProd": "webpack --config ./webpack.config.js --mode=production"
2122
},

apps/client/src/app.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export const useRouteListener = () => {
4444

4545
const routes = getRoutes();
4646

47-
const LocalizationWrapper = (args: any) => {
47+
const LocalizationWrapper = () => {
4848
// this rewrites any routes that include a valid (known) lang path root folder so the routing
4949
// works as expected. Note: the actual loading of the locale file will have taken place prior to here. It either
5050
// occurs on first boot and <Page> handles waiting to show the whole application until it's ready, or when
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import React from 'react';
21
import AccountContainer from '../Account.container';
32
import { renderWithStoreAndRouter } from '../../../../tests/testHelpers';
43

54
describe('Account Container', () => {
6-
it('renders', () => {
7-
const { baseElement } = renderWithStoreAndRouter(<AccountContainer />);
5+
it('renders', () => {
6+
const { baseElement } = renderWithStoreAndRouter(<AccountContainer />);
87

9-
expect(baseElement.querySelector('div')).toBeTruthy();
10-
});
8+
expect(baseElement.querySelector('div')).toBeTruthy();
9+
});
1110
});
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import { render, fireEvent } from '@testing-library/react';
2+
import ChangePassword from '../ChangePassword.component';
3+
import { getTestI18n } from '../../../../../tests/testHelpers';
4+
5+
const i18n = getTestI18n();
6+
7+
describe('ChangePassword container', () => {
8+
it('submitting form does not work when fields empty', () => {
9+
const onSave = jest.fn();
10+
const { container } = render(<ChangePassword className="the-class" onSave={onSave} i18n={i18n} oneTimePassword="" throttle={false} />);
11+
12+
const submitButton = container.querySelector('button[type=submit]') as HTMLButtonElement;
13+
fireEvent.click(submitButton);
14+
15+
expect(onSave).not.toHaveBeenCalled();
16+
});
17+
18+
it('submitting form still does not works when fields non-empty but new passwords are not identical', () => {
19+
const onSave = jest.fn();
20+
const { container } = render(<ChangePassword className="the-class" onSave={onSave} i18n={i18n} oneTimePassword="" throttle={false} />);
21+
22+
const currentPasswordField = container.querySelector('input[name=currentPassword]') as HTMLInputElement;
23+
fireEvent.change(currentPasswordField, {
24+
target: {
25+
value: 'current-password'
26+
}
27+
});
28+
29+
const newPasswordField1 = container.querySelector('input[name=password]') as HTMLInputElement;
30+
fireEvent.change(newPasswordField1, {
31+
target: {
32+
value: 'password'
33+
}
34+
});
35+
36+
const newPasswordField2 = container.querySelector('input[name=password2]') as HTMLInputElement;
37+
fireEvent.change(newPasswordField2, {
38+
target: {
39+
value: 'passwordX'
40+
}
41+
});
42+
43+
const submitButton = container.querySelector('button[type=submit]') as HTMLButtonElement;
44+
fireEvent.click(submitButton);
45+
46+
expect(onSave).not.toHaveBeenCalled();
47+
});
48+
49+
it('submitting form works when fields non-empty and new passwords are identical', () => {
50+
const onSave = jest.fn();
51+
const { container } = render(<ChangePassword className="the-class" onSave={onSave} i18n={i18n} oneTimePassword="" throttle={false} />);
52+
53+
const currentPasswordField = container.querySelector('input[name=currentPassword]') as HTMLInputElement;
54+
fireEvent.change(currentPasswordField, {
55+
target: {
56+
value: 'current-password'
57+
}
58+
});
59+
60+
const newPasswordField1 = container.querySelector('input[name=password]') as HTMLInputElement;
61+
fireEvent.change(newPasswordField1, {
62+
target: {
63+
value: 'password'
64+
}
65+
});
66+
67+
const newPasswordField2 = container.querySelector('input[name=password2]') as HTMLInputElement;
68+
fireEvent.change(newPasswordField2, {
69+
target: {
70+
value: 'password'
71+
}
72+
});
73+
74+
const submitButton = container.querySelector('button[type=submit]') as HTMLButtonElement;
75+
fireEvent.click(submitButton);
76+
77+
expect(onSave).toHaveBeenCalled();
78+
});
79+
});

apps/client/src/core/account/changePassword/__tests__/ChangePassword.component.tsx

Lines changed: 0 additions & 85 deletions
This file was deleted.
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import React from 'react';
21
import ChangePassword from '../ChangePassword.container';
32
import { renderWithStoreAndRouter } from '../../../../../tests/testHelpers';
43

54
describe('ChangePassword container', () => {
6-
it('renders', () => {
7-
const { baseElement } = renderWithStoreAndRouter(<ChangePassword />);
5+
it('renders', () => {
6+
const { baseElement } = renderWithStoreAndRouter(<ChangePassword />);
87

9-
expect(baseElement.querySelector('div')).toBeTruthy();
10-
});
8+
expect(baseElement.querySelector('div')).toBeTruthy();
9+
});
1110
});
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
import React from 'react';
21
import DataSets from '../DataSets.container';
32
import { renderWithStoreAndRouter } from '../../../../../tests/testHelpers';
43

54
describe('DataSets', () => {
6-
// need to finish deciding exactly what the header will contain before adding these tests
5+
// need to finish deciding exactly what the header will contain before adding these tests
76

8-
it('renders', () => {
9-
const { baseElement } = renderWithStoreAndRouter(<DataSets />);
7+
it('renders', () => {
8+
const { baseElement } = renderWithStoreAndRouter(<DataSets />);
109

11-
expect(baseElement.querySelector('div')).toBeTruthy();
12-
});
10+
expect(baseElement.querySelector('div')).toBeTruthy();
11+
});
1312
});

apps/client/src/core/accounts/Accounts.container.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ import { Store } from '~types/general';
99
import { withAuth } from '~core/auth/withAuth';
1010

1111
const mapStateToProps = (state: Store): Pick<AccountsPageProps, 'i18n' | 'selectedTab'> => ({
12-
i18n: selectors.getCoreI18n(state),
13-
selectedTab: accountSelectors.getSelectedAccountsPageTab(state)
12+
i18n: selectors.getCoreI18n(state),
13+
selectedTab: accountSelectors.getSelectedAccountsPageTab(state)
1414
});
1515

1616
const mapDispatchToProps = (dispatch: Dispatch): Pick<AccountsPageProps, 'onChangeTab' | 'onDestroy'> => ({
17-
onChangeTab: (tab: SelectedAccountsTab): any => dispatch(accountActions.onChangeAccountsTab(tab)),
18-
onDestroy: (): any => dispatch(accountActions.onCleanupAccountsPage())
17+
onChangeTab: (tab: SelectedAccountsTab): any => dispatch(accountActions.onChangeAccountsTab(tab)),
18+
onDestroy: (): any => dispatch(accountActions.onCleanupAccountsPage())
1919
});
2020

2121
const container: any = connect(mapStateToProps, mapDispatchToProps)(AccountsPage);

apps/client/src/core/accounts/accountsList/AccountsList.component.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { useMutation, useQuery } from '@apollo/client/react';
22
import C from '@generatedata/config/constants';
33
import { Dropdown, DropdownOption, SecondaryButton, SmallSpinner, useSharedClasses } from '@generatedata/shared';
44
import HighlightOffIcon from '@mui/icons-material/HighlightOff';
5-
import Button from '@mui/material/Button';
65
import { format, fromUnixTime } from 'date-fns';
76
import { useEffect, useState } from 'react';
87
import AccountStatusPill from '~components/accounts/accountStatusPill/AccountStatusPill.component';
@@ -40,12 +39,12 @@ const Row = ({ i18n, firstName, lastName, onEdit, onDelete, accountStatus, lastL
4039
if (expiryDate) {
4140
expiryDateVal = format(fromUnixTime(expiryDate / 1000), C.DATE_FORMAT);
4241
}
43-
} catch (e) {}
42+
} catch (_e) {}
4443

4544
let lastLoggedInVal: any = <span className={sharedClasses.blank}>&#8212;</span>;
4645
try {
4746
lastLoggedInVal = format(fromUnixTime(lastLoggedIn), C.DATE_FORMAT);
48-
} catch (lastLoggedInVal) {}
47+
} catch (_e) {}
4948

5049
return (
5150
<div className={classNames.row}>

0 commit comments

Comments
 (0)