Skip to content

Commit

Permalink
Merge branch 'main' into 55-feat-main-component-개발
Browse files Browse the repository at this point in the history
- ESLint 변경사항 적용
  • Loading branch information
kumsil1006 committed Nov 24, 2022
2 parents 5734f7e + cbec9ab commit 562fbc2
Show file tree
Hide file tree
Showing 9 changed files with 223 additions and 119 deletions.
13 changes: 3 additions & 10 deletions client/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@
module.exports = {
root: true,
env: {
browser: true,
es2021: true,
},
extends: [
'airbnb',
'airbnb-typescript',
'airbnb/hooks',
'plugin:react/recommended',
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
],
extends: ['plugin:react/recommended', 'standard-with-typescript', 'plugin:prettier/recommended'],
overrides: [],
parser: '@typescript-eslint/parser',
parserOptions: {
project: './tsconfig.json',
tsconfigRootDir: __dirname,
ecmaVersion: 'latest',
sourceType: 'module',
},
plugins: ['react', '@typescript-eslint', 'prettier'],
plugins: ['react', 'prettier'],
rules: {
indent: ['error', 2],
'linebreak-style': 'off',
Expand Down
11 changes: 7 additions & 4 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,20 @@
"@types/jest": "^29.2.3",
"@types/react": "^18.0.24",
"@types/react-dom": "^18.0.8",
"@typescript-eslint/eslint-plugin": "^5.43.0",
"@typescript-eslint/eslint-plugin": "^5.0.0",
"@typescript-eslint/parser": "^5.43.0",
"@vitejs/plugin-react": "^2.2.0",
"eslint": "^8.2.0",
"eslint": "^8.0.1",
"eslint-config-airbnb": "19.0.4",
"eslint-config-airbnb-typescript": "^17.0.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.25.3",
"eslint-config-standard-with-typescript": "^23.0.0",
"eslint-plugin-import": "^2.25.2",
"eslint-plugin-jsx-a11y": "^6.5.1",
"eslint-plugin-n": "^15.0.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-react": "^7.31.10",
"eslint-plugin-promise": "^6.0.0",
"eslint-plugin-react": "^7.31.11",
"eslint-plugin-react-hooks": "^4.3.0",
"jest": "^29.3.1",
"prettier": "^2.7.1",
Expand Down
8 changes: 2 additions & 6 deletions client/src/core/todo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export interface Todo {
importance: number; // INT or ENUM, 할일의 우선순위 레벨
until: Date; // DATE, 할일의 마감기한
from: Date; // DATE, 할일의 시작기한
prev: Array<string>; // or Array<string>, 이전에 반드시 완료되어야 하는 할일 id 배열
next: Array<string>; // or Array<string>, 본 할일 이후에 실행되어야 하는 할일 id 배열
prev: string[]; // or string[], 이전에 반드시 완료되어야 하는 할일 id 배열
next: string[]; // or string[], 본 할일 이후에 실행되어야 하는 할일 id 배열

// (필수) 할일의 상태값
state: 'READY' | 'DONE' | 'WAIT';
Expand All @@ -26,7 +26,3 @@ export interface RawData {
until: string; // string, 할일의 마감기한
from: string; // string, 할일의 시작기한
}

export const testFun = (num: number) => {
return num + 1;
};
43 changes: 20 additions & 23 deletions client/src/core/todo/test/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ const testToday = new Date();
const DAY = 24 * 60 * 60 * 1000;
const WEEK = 7 * DAY;

type TestData = { today: Date; tag: string; data: Array<TestTodo> };
interface TestData {
today: Date;
tag: string;
data: TestTodo[];
}

const generateTodoForSortTest = (): TestTodo =>
toTestTodo({
Expand All @@ -15,7 +19,7 @@ const generateTodoForSortTest = (): TestTodo =>
from: new Date(1994, 10, 5),
});

const generateTodoListForSortTest = (length: number): Array<TestTodo> =>
const generateTodoListForSortTest = (length: number): TestTodo[] =>
Array.from({ length }, () => generateTodoForSortTest());

// update
Expand Down Expand Up @@ -49,8 +53,8 @@ const getTodoIdFromNextElement = (
length: number,
index: number,
numNext: number,
arr: Array<TestTodo>,
): { idx: Array<number>; next: Array<string> } => {
arr: TestTodo[],
): { idx: number[]; next: string[] } => {
if (index + numNext >= length) return { next: [], idx: [] };

const idx = Array.from({ length: numNext }, () => getRandomIndex(length, index, numNext))
Expand All @@ -61,9 +65,9 @@ const getTodoIdFromNextElement = (
return { idx, next };
};

const generateRandomNumber = (p: number, max: number) => {
const generateRandomNumber = (p: number, max: number): number => {
let num = 0;
const addNextNum = () => {
const addNextNum = (): void => {
if (num < max && Math.random() > p) {
num += 1;
addNextNum();
Expand All @@ -73,8 +77,8 @@ const generateRandomNumber = (p: number, max: number) => {
return num;
};

const generateTodoListForUpdateTest = (length: number): Array<TestTodo> => {
const todos: Array<TestTodo> = Array.from({ length }, (el, i) => generateRandomTodo(i.toString()));
const generateTodoListForUpdateTest = (length: number): TestTodo[] => {
const todos: TestTodo[] = Array.from({ length }, (el, i) => generateRandomTodo(i.toString()));
todos.forEach((el, i) => {
const { idx, next } = getTodoIdFromNextElement(
length,
Expand All @@ -91,47 +95,40 @@ const generateTodoListForUpdateTest = (length: number): Array<TestTodo> => {
return todos;
};

const generateSortTestProblem = (answer: Array<TestTodo>) => {
const generateSortTestProblem = (answer: TestTodo[]): TestTodo[] => {
const problem = JSON.parse(JSON.stringify(answer)).map((el: any) => toTestTodo(el));
problem.sort(() => Math.random() - 0.5);
return problem;
};

const changeTodoStateRandomly = (todo: TestTodo, p: number) => {
const changeTodoStateRandomly = (todo: TestTodo, p: number): TestTodo => {
if (todo.state === 'DONE' || Math.random() < p) return todo;
if (todo.state === 'READY') return { ...todo, state: 'WAIT' };
return { ...todo, state: 'READY' };
};

const generateUpdateTestProblem = (answer: Array<TestTodo>) => {
const generateUpdateTestProblem = (answer: TestTodo[]): TestTodo[] => {
const problem = JSON.parse(JSON.stringify(answer))
.map((el: any) => toTestTodo(el))
.map((el: TestTodo) => changeTodoStateRandomly(el, 0.8));
return problem;
};

const generateTestCases = (
answerObject: TestData,
generator: (answer: Array<TestTodo>) => Array<TestTodo>,
num: number,
) =>
const generateTestCases = (answerObject: TestData, generator: (answer: TestTodo[]) => TestTodo[], num: number): any[] =>
new Array(num).fill(0).map((el, i) => ({
today: answerObject.today,
tag: `answer: ${answerObject.tag}, problem:${i}`,
problem: generator(answerObject.data),
answer: answerObject.data,
}));

const generateTestSet = (
data: Array<TestData>,
generator: (answer: Array<TestTodo>) => Array<TestTodo>,
multiplier: number,
) => data.flatMap((el) => generateTestCases(el, generator, multiplier));
const generateTestSet = (data: TestData[], generator: (answer: TestTodo[]) => TestTodo[], multiplier: number): any[] =>
data.flatMap((el) => generateTestCases(el, generator, multiplier));

const generateSortTestSet = (data: Array<TestData>, multiplier: number) =>
const generateSortTestSet = (data: TestData[], multiplier: number): any[] =>
generateTestSet(data, generateSortTestProblem, multiplier);

const generateUpdateTestSet = (data: Array<TestData>, multiplier: number) =>
const generateUpdateTestSet = (data: TestData[], multiplier: number): any[] =>
generateTestSet(data, generateUpdateTestProblem, multiplier);

export {
Expand Down
4 changes: 2 additions & 2 deletions client/src/core/todo/test/sort.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const sortTestCase = sortRawTestCase.map((el) => ({
data: el.data.map((todo) => toTestTodo(todo)),
}));

const sort = (todoList: Array<TestTodo>, today: Date): Array<TestTodo> => {
const sort = (todoList: TestTodo[], today: Date): TestTodo[] => {
return [...todoList];
};

Expand Down Expand Up @@ -40,7 +40,7 @@ describe('정렬 대단위 테스트', () => {
describe.each(macroUnitTestCases)('$tag', ({ problem, today, answer }) => {
it('Ready Todo List의 기본적인 정렬을 할 수 있다.', () => {
expect(sort(problem, today).map((el) => toComparableTestTodo(el))).toEqual(
answer.map((el) => toComparableTestTodo(el)),
answer.map((el: any) => toComparableTestTodo(el)),
);
});
});
Expand Down
32 changes: 16 additions & 16 deletions client/src/core/todo/test/type.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
import { uuid } from 'uuidv4';

export type TestTodo = {
export interface TestTodo {
id: string; // UUIDv4, 할일의 고유 id
title: string; // VARCHAR(255), 할일의 이름
content: string; // TEXT, 할일의 상세 내용
owner: string; // UUIDv4, 할일 소유자의 id
importance: number; // INT or ENUM, 할일의 우선순위 레벨
until: Date; // DATE, 할일의 마감기한
from: Date; // DATE, 할일의 시작기한
prev: Array<string>; // or Array<string>, 이전에 반드시 완료되어야 하는 할일 id 배열
next: Array<string>; // or Array<string>, 본 할일 이후에 실행되어야 하는 할일 id 배열
prev: string[]; // or string[], 이전에 반드시 완료되어야 하는 할일 id 배열
next: string[]; // or string[], 본 할일 이후에 실행되어야 하는 할일 id 배열
lastPostponed: Date;
state: 'READY' | 'DONE' | 'WAIT';
};
}

const toTestTodo = (todo: any): TestTodo => ({
id: (todo.id as string) || uuid(),
title: (todo.title as string) || 'default title',
content: (todo.content as string) || 'default content',
owner: (todo.owner as string) || 'default user',
importance: (todo.importance as number) || 1,
until: todo.until ? new Date(todo.until) : new Date(2077, 1, 1),
from: todo.from ? new Date(todo.from) : new Date(1994, 1, 1),
prev: todo.prev || [],
next: todo.next || [],
lastPostponed: todo.lastPostponed ? new Date(todo.lastPostponed) : new Date(),
state: todo.state || 'READY',
id: todo.id ?? uuid(),
title: todo.title ?? 'default title',
content: todo.content ?? 'default content',
owner: todo.owner ?? 'default user',
importance: todo.importance ?? 1,
until: new Date(todo.until ?? new Date(2077, 1, 1)),
from: new Date(todo.from ?? new Date(1994, 1, 1)),
prev: todo.prev ?? [],
next: todo.next ?? [],
lastPostponed: new Date(todo.lastPostponed ?? new Date()),
state: todo.state ?? 'READY',
});

const toComparableTestTodo = (todo: TestTodo) => ({
const toComparableTestTodo = (todo: TestTodo): any => ({
...todo,
until: todo.until.toString(),
from: todo.from.toString(),
Expand Down
4 changes: 2 additions & 2 deletions client/src/core/todo/test/update.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const updateTestCase = updateRawTestCase.map((el) => ({
data: el.data.map((todo) => toTestTodo(todo)),
}));

const update = (todoList: Array<TestTodo>, today: Date): Array<TestTodo> => {
const update = (todoList: TestTodo[], today: Date): TestTodo[] => {
return [...todoList];
};

Expand All @@ -36,7 +36,7 @@ describe('업데이트 대단위 테스트', () => {
describe.each(macroUnitTestCases)('$tag', ({ problem, today, answer }) => {
it('Todo List의 선후관계 및 날짜 비교를 통해 Todo들의 상태를 업데이트 할 수 있다.', () => {
expect(update(problem, today).map((el) => toComparableTestTodo(el))).toEqual(
answer.map((el) => toComparableTestTodo(el)),
answer.map((el: any) => toComparableTestTodo(el)),
);
});
});
Expand Down
16 changes: 8 additions & 8 deletions client/src/core/todo/test/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { TestTodo } from './type';
const onlyDate = (date: Date): Date => new Date(date.getFullYear(), date.getMonth(), date.getDate());
const isEqualDate = (d1: Date, d2: Date): boolean => onlyDate(d1).getTime() === onlyDate(d2).getTime();

const validateImminenceSort = (todoList: Array<TestTodo>, testToday: Date): boolean => {
const validateImminenceSort = (todoList: TestTodo[], testToday: Date): boolean => {
return todoList
.map((el, i) => ({ index: i, todo: el }))
.filter((el) => isEqualDate(testToday, el.todo.until))
Expand All @@ -12,10 +12,10 @@ const validateImminenceSort = (todoList: Array<TestTodo>, testToday: Date): bool
}, true);
};

const validateImportance = (todoList: Array<TestTodo>): boolean =>
const validateImportance = (todoList: TestTodo[]): boolean =>
todoList.reduce((acc, el, i, arr) => acc && (i === 0 || el.importance <= arr[i - 1].importance), true);

const validateImportanceSort = (todoList: Array<TestTodo>, testToday: Date): boolean => {
const validateImportanceSort = (todoList: TestTodo[], testToday: Date): boolean => {
if (!validateImminenceSort(todoList, testToday)) return false;
const divider = todoList.filter((el) => isEqualDate(testToday, el.until)).length;
return validateImportance(todoList.slice(0, divider)) && validateImportance(todoList.slice(divider));
Expand All @@ -25,7 +25,7 @@ const equalForImportanceSort = (todo1: TestTodo, todo2: TestTodo): boolean => {
return todo1.importance === todo2.importance;
};

const validateDeadlineSort = (todoList: Array<TestTodo>, testToday: Date): boolean => {
const validateDeadlineSort = (todoList: TestTodo[], testToday: Date): boolean => {
if (!validateImportanceSort(todoList, testToday)) return false;
todoList.reduce(
(acc, el, i, arr) => i === 0 || (acc && (equalForImportanceSort(el, arr[i - 1]) || el.until >= arr[i - 1].until)),
Expand All @@ -38,7 +38,7 @@ const equalForDeadlineSort = (todo1: TestTodo, todo2: TestTodo): boolean => {
return todo1.importance === todo2.importance && todo1.until.getTime() === todo2.until.getTime();
};

const validateLastPostponedSort = (todoList: Array<TestTodo>, testToday: Date): boolean => {
const validateLastPostponedSort = (todoList: TestTodo[], testToday: Date): boolean => {
if (!validateDeadlineSort(todoList, testToday)) return false;
todoList.reduce(
(acc, el, i, arr) =>
Expand All @@ -49,15 +49,15 @@ const validateLastPostponedSort = (todoList: Array<TestTodo>, testToday: Date):
};

const isFromBeforeToday = (testToday: Date, from: Date): boolean => from.getTime() <= testToday.getTime();
const isAllPrevDone = (todo: TestTodo, todoList: Array<TestTodo>): boolean =>
const isAllPrevDone = (todo: TestTodo, todoList: TestTodo[]): boolean =>
todo.prev.reduce((acc, id) => acc && todoList.find((el) => el.id === id)?.state === 'DONE', true);

const validateRTL = (todoList: Array<TestTodo>, testToday: Date): boolean =>
const validateRTL = (todoList: TestTodo[], testToday: Date): boolean =>
todoList
.filter((el) => el.state === 'READY')
.reduce((acc, el) => acc && isFromBeforeToday(testToday, el.from) && isAllPrevDone(el, todoList), true);

const validateWTL = (todoList: Array<TestTodo>, testToday: Date): boolean =>
const validateWTL = (todoList: TestTodo[], testToday: Date): boolean =>
todoList
.filter((el) => el.state === 'WAIT')
.reduce((acc, el) => acc && (!isFromBeforeToday(testToday, el.from) || !isAllPrevDone(el, todoList)), true);
Expand Down
Loading

0 comments on commit 562fbc2

Please sign in to comment.