Skip to content

Commit

Permalink
Merge pull request #92 from saseungmin/refactor/eslint
Browse files Browse the repository at this point in the history
refactor: ๋ชจ๋“  ํŒŒ์ผ์— ๋ณ€๊ฒฝ๋œ eslint ๋ฃฐ ์ ์šฉ
  • Loading branch information
saseungmin committed Dec 24, 2023
2 parents 81aece3 + ef7deae commit 5b771c0
Show file tree
Hide file tree
Showing 63 changed files with 368 additions and 341 deletions.
14 changes: 11 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ module.exports = {
browser: true,
jest: true,
},
globals: {
context: 'readonly',
given: 'readonly',
cy: 'readonly',
},
ignorePatterns: [
'build/',
'node_modules/',
Expand Down Expand Up @@ -55,14 +60,17 @@ module.exports = {
},
},
{
files: ['**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[jt]s?(x)'],
files: ['**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(test).[jt]s?(x)'],
extends: ['plugin:testing-library/react', 'plugin:jest/recommended'],
rules: {
// set your test eslint rules
'jest/no-identical-title': 'off',
'testing-library/no-unnecessary-act': 'off',
},
},
],
rules: {
// set your rules
'react/prop-types': 'off',
'no-underscore-dangle': ['error', { allow: ['_id'] }],
camelcase: ['error', { allow: ['snapshot_UNSTABLE', 'access_token', 'drop_console'] }],
},
};
4 changes: 2 additions & 2 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npm run lint
npm run coverage
yarn run lint
yarn run coverage
4 changes: 4 additions & 0 deletions @types/jest.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare const given: {
<T = never>(key: string, callback: () => T): T
[key: string]: never
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"start": "webpack-dev-server --progress",
"test": "jest",
"test:watch": "yarn run test -- --watch-all",
"test:watch": "yarn run test --watch-all",
"coverage": "yarn run test --coverage",
"lint": "eslint --ext js,jsx .",
"build": "cross-env NODE_ENV=production webpack",
Expand Down
72 changes: 34 additions & 38 deletions src/App.test.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';

import { act } from 'react-dom/test-utils';
import { render, fireEvent } from '@testing-library/react';
import { render, fireEvent, screen } from '@testing-library/react';

import { RecoilRoot } from 'recoil';

Expand Down Expand Up @@ -54,33 +54,33 @@ describe('App', () => {
todos,
}));

const { getByTestId, container } = renderApp({});
const { container } = renderApp({});

expect(container).toHaveTextContent('What are your plans for today?');
expect(container).toHaveTextContent('ALL');
expect(container).toHaveTextContent('ํ•  ์ผ1');
expect(container).toHaveTextContent('CLEAR COMPLETED');
expect(getByTestId('theme-toggle')).toHaveAttribute('title', 'light');
expect(screen.getByTestId('theme-toggle')).toHaveAttribute('title', 'light');
});

describe('Render App with Theme', () => {
given('todos', () => todoResultState);

context('When theme is Light', () => {
it('renders light theme css attribute and light toggle', () => {
const { getByText, getByTestId } = renderApp({ theme: lightTheme });
renderApp({ theme: lightTheme });

expect(getByText('What are your plans for today?')).toHaveStyle('color: #6A7BA2;');
expect(getByTestId('theme-toggle')).toHaveAttribute('title', 'light');
expect(screen.getByText('What are your plans for today?')).toHaveStyle('color: #6A7BA2;');
expect(screen.getByTestId('theme-toggle')).toHaveAttribute('title', 'light');
});
});

context('When theme is Dark', () => {
it('renders dark theme css attribute and dark toggle', () => {
const { getByText, getByTestId } = renderApp({ theme: darkTheme, themState: true });
renderApp({ theme: darkTheme, themState: true });

expect(getByText('What are your plans for today?')).toHaveStyle('color: #FFDFDE;');
expect(getByTestId('theme-toggle')).toHaveAttribute('title', 'dark');
expect(screen.getByText('What are your plans for today?')).toHaveStyle('color: #FFDFDE;');
expect(screen.getByTestId('theme-toggle')).toHaveAttribute('title', 'dark');
});
});
});
Expand All @@ -97,27 +97,27 @@ describe('App', () => {
}));

it('When the filter is ALL', () => {
const { container, getByText } = renderApp({});
const { container } = renderApp({});

fireEvent.click(getByText('ALL'));
fireEvent.click(screen.getByText('ALL'));

expect(container).toHaveTextContent('some task');
expect(container).toHaveTextContent('ํ•  ์ผ2');
});

it('When the filter is ACTIVE', () => {
const { container, getByText } = renderApp({});
const { container } = renderApp({});

fireEvent.click(getByText('ACTIVE'));
fireEvent.click(screen.getByText('ACTIVE'));

expect(container).toHaveTextContent('some task');
expect(container).not.toHaveTextContent('ํ•  ์ผ2');
});

it('When the filter is COMPLETED', () => {
const { container, getByText } = renderApp({});
const { container } = renderApp({});

fireEvent.click(getByText('COMPLETED'));
fireEvent.click(screen.getByText('COMPLETED'));

expect(container).not.toHaveTextContent('some task');
expect(container).toHaveTextContent('ํ•  ์ผ2');
Expand All @@ -136,24 +136,24 @@ describe('App', () => {

context('Is Sign in Modal', () => {
it('When you click the "Sign in" button, the Sign in modal is shown.', async () => {
const { getByPlaceholderText, getByText } = renderApp({});
renderApp({});

fireEvent.click(getByText('Sign in'));
fireEvent.click(screen.getByText('Sign in'));

expect(getByPlaceholderText('์•„์ด๋””')).not.toBeNull();
expect(getByPlaceholderText('๋น„๋ฐ€๋ฒˆํ˜ธ')).not.toBeNull();
expect(screen.getByPlaceholderText('์•„์ด๋””')).not.toBeNull();
expect(screen.getByPlaceholderText('๋น„๋ฐ€๋ฒˆํ˜ธ')).not.toBeNull();
});
});

context('Is Sign up Modal', () => {
it('When you click the "Sing in" button, the Sign in modal is shown.', async () => {
const { getByPlaceholderText, getByText } = renderApp({});
renderApp({});

fireEvent.click(getByText('Sign up'));
fireEvent.click(screen.getByText('Sign up'));

expect(getByPlaceholderText('์•„์ด๋””')).not.toBeNull();
expect(getByPlaceholderText('๋น„๋ฐ€๋ฒˆํ˜ธ')).not.toBeNull();
expect(getByPlaceholderText('๋น„๋ฐ€๋ฒˆํ˜ธ ํ™•์ธ')).not.toBeNull();
expect(screen.getByPlaceholderText('์•„์ด๋””')).not.toBeNull();
expect(screen.getByPlaceholderText('๋น„๋ฐ€๋ฒˆํ˜ธ')).not.toBeNull();
expect(screen.getByPlaceholderText('๋น„๋ฐ€๋ฒˆํ˜ธ ํ™•์ธ')).not.toBeNull();
});
});
});
Expand Down Expand Up @@ -186,12 +186,12 @@ describe('App', () => {
todos,
}));

const { container, getByText } = renderApp({});
const { container } = renderApp({});

expect(container).toHaveTextContent('ํ•  ์ผ1');

await act(async () => {
fireEvent.click(getByText('CLEAR COMPLETED'));
fireEvent.click(screen.getByText('CLEAR COMPLETED'));
});

expect(container).toHaveTextContent('ํ•  ์ผ์ด ์—†์–ด์š”!');
Expand All @@ -211,18 +211,16 @@ describe('App', () => {
{ placeholder: '๋น„๋ฐ€๋ฒˆํ˜ธ', value: 'test' },
];

const {
container, getByTestId, getByPlaceholderText,
} = renderApp(props);
const { container } = renderApp(props);

await act(async () => {
input.forEach(({ placeholder, value }) => {
fireEvent.change(getByPlaceholderText(placeholder), { target: { value } });
fireEvent.change(screen.getByPlaceholderText(placeholder), { target: { value } });
});
});

await act(async () => {
fireEvent.submit(getByTestId('auth-submit-button'));
fireEvent.submit(screen.getByTestId('auth-submit-button'));
});

expect(container).toHaveTextContent('Successful Sign in!');
Expand Down Expand Up @@ -271,9 +269,9 @@ describe('App', () => {
it('Render success message "Success in entering To-Do!"', async () => {
mockPostApi(mockData);

const { container, getByPlaceholderText } = renderApp({ user: mockUserState });
const { container } = renderApp({ user: mockUserState });

const input = getByPlaceholderText('์˜ค๋Š˜์˜ ํ•  ์ผ์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”!');
const input = screen.getByPlaceholderText('์˜ค๋Š˜์˜ ํ•  ์ผ์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”!');

await act(async () => {
fireEvent.change(input, { target: { value } });
Expand Down Expand Up @@ -309,18 +307,16 @@ describe('App', () => {
{ placeholder: '๋น„๋ฐ€๋ฒˆํ˜ธ ํ™•์ธ', value: 'test' },
];

const {
container, getByTestId, getByPlaceholderText,
} = renderApp(props);
const { container } = renderApp(props);

await act(async () => {
input.forEach(({ placeholder, value }) => {
fireEvent.change(getByPlaceholderText(placeholder), { target: { value } });
fireEvent.change(screen.getByPlaceholderText(placeholder), { target: { value } });
});
});

await act(async () => {
fireEvent.submit(getByTestId('auth-submit-button'));
fireEvent.submit(screen.getByTestId('auth-submit-button'));
});

expect(container).toHaveTextContent('Successful Sign up!');
Expand Down
4 changes: 2 additions & 2 deletions src/components/auth/AuthInput.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const authFieldsProperty = {
},
};

const AuthInput = ({ inputRef, inputName }) => {
function AuthInput({ inputRef, inputName }) {
const { inputType, placeholder, autoComplete } = authFieldsProperty[inputName];

return (
Expand All @@ -60,6 +60,6 @@ const AuthInput = ({ inputRef, inputName }) => {
autoComplete={autoComplete}
/>
);
};
}

export default AuthInput;
6 changes: 3 additions & 3 deletions src/components/auth/AuthInput.test.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

import { render } from '@testing-library/react';
import { render, screen } from '@testing-library/react';

import AuthInput from './AuthInput';

Expand All @@ -13,8 +13,8 @@ describe('AuthInput', () => {
));

it('renders auth input', () => {
const { getByPlaceholderText } = renderAuthInput();
renderAuthInput();

expect(getByPlaceholderText('์•„์ด๋””')).not.toBeNull();
expect(screen.getByPlaceholderText('์•„์ด๋””')).not.toBeNull();
});
});
4 changes: 2 additions & 2 deletions src/components/auth/AuthModalForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ const SubmitButton = styled.button`
}
`;

const AuthModalForm = ({ onSubmit }) => {
function AuthModalForm({ onSubmit }) {
const { register, handleSubmit } = useForm();

const { type, visible } = useRecoilValue(authFormStatusAtom);
Expand Down Expand Up @@ -145,6 +145,6 @@ const AuthModalForm = ({ onSubmit }) => {
</AuthModalBoxWrapper>
</AuthModalFormWrapper>
);
};
}

export default AuthModalForm;
16 changes: 8 additions & 8 deletions src/components/auth/AuthModalForm.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';

import { RecoilRoot } from 'recoil';

import { render } from '@testing-library/react';
import { render, screen } from '@testing-library/react';

import { SnackbarProvider } from 'notistack';

Expand Down Expand Up @@ -31,11 +31,11 @@ describe('AuthModalForm', () => {
visible: true,
}));
it('renders register contents', () => {
const { getByPlaceholderText } = renderAuthModalForm();
renderAuthModalForm();

expect(getByPlaceholderText('์•„์ด๋””')).not.toBeNull();
expect(getByPlaceholderText('๋น„๋ฐ€๋ฒˆํ˜ธ')).not.toBeNull();
expect(getByPlaceholderText('๋น„๋ฐ€๋ฒˆํ˜ธ ํ™•์ธ')).not.toBeNull();
expect(screen.getByPlaceholderText('์•„์ด๋””')).not.toBeNull();
expect(screen.getByPlaceholderText('๋น„๋ฐ€๋ฒˆํ˜ธ')).not.toBeNull();
expect(screen.getByPlaceholderText('๋น„๋ฐ€๋ฒˆํ˜ธ ํ™•์ธ')).not.toBeNull();
});
});

Expand All @@ -45,10 +45,10 @@ describe('AuthModalForm', () => {
visible: true,
}));
it('renders register contents', () => {
const { getByPlaceholderText } = renderAuthModalForm();
renderAuthModalForm();

expect(getByPlaceholderText('์•„์ด๋””')).not.toBeNull();
expect(getByPlaceholderText('๋น„๋ฐ€๋ฒˆํ˜ธ')).not.toBeNull();
expect(screen.getByPlaceholderText('์•„์ด๋””')).not.toBeNull();
expect(screen.getByPlaceholderText('๋น„๋ฐ€๋ฒˆํ˜ธ')).not.toBeNull();
});
});
});
4 changes: 2 additions & 2 deletions src/components/auth/AuthStatus.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { authFormStatusAtom } from '../../recoil/auth';
import RegisterForm from './RegisterForm';
import LoginForm from './LoginForm';

const AuthStatus = () => {
function AuthStatus() {
const { type, visible } = useRecoilValue(authFormStatusAtom);

if (!visible) {
Expand All @@ -23,6 +23,6 @@ const AuthStatus = () => {
return (
<LoginForm />
);
};
}

export default AuthStatus;

0 comments on commit 5b771c0

Please sign in to comment.