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

Team 12 과제완료 #12

Open
wants to merge 13 commits into
base: team-12
Choose a base branch
from
56 changes: 56 additions & 0 deletions src/__tests__/201701981/todoItem.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import TodoItem from "../vo/TodoItem";

describe("할 일을 등록할 수 있다.", () => {
test("todo item 생성하기", () => {
const todoItem = new TodoItem(1, '오늘은 술 먹는날');
expect(todoItem.task).toEqual('오늘은 술 먹는날');
});
});

describe("할 일을 업데이트 할 수 있다.", () => {
test("todo item 업데이트하기", () => {
const todoItem = new TodoItem(1, '오늘은 술 먹는날');
todoItem.updateTask('오늘은 그냥 안 마실래');
expect(todoItem.task).toEqual('오늘은 그냥 안 마실래');
});
});

describe("할 일을 완료/미완료로 바꿀 수 있다.", () => {
test("todo item 완료로 바꾸기", () => {
const todoItem = new TodoItem(1, '오늘은 술 먹는날');
todoItem.setComplete();
expect(todoItem.completed).toBeTruthy();
});
test("todo item 미완료로 바꾸기", () => {
const todoItem = new TodoItem(1, '오늘은 술 먹는날');
todoItem.unsetComplete();
expect(todoItem.completed).toBeFalsy();
});
});

describe("할 일을 완료/미완료로 생성할 수 있다.", () => {
test("todo item 완료로 만들기", () => {
const todoItem = new TodoItem(1, '오늘은 술 먹는날', new Date(), true);
expect(todoItem.completed).toBeTruthy();
});
test("todo item 미완료로 생성하기", () => {
const todoItem = new TodoItem(1, '오늘은 술 먹는날', new Date(), false);
expect(todoItem.completed).toBeFalsy();
});
});

describe("할 일에 날짜가 들어간다.", () => {
test("todo item이 오늘 생성 => equalsDayOfCreatedAt : true", () => {
const sourceDate = new Date();
const todoItem = new TodoItem(1, '오늘은 술 먹는날', sourceDate);
const targetDate = new Date();
expect(todoItem.equalsDayOfCreatedAt(targetDate)).toBeTruthy();
});

test("todo item을 어제 생성 => equalsDayOfCreatedAt : false", () => {
const sourceDate = new Date('2022-05-08T10:10:10;');
const todoItem = new TodoItem(1, '오늘은 술 먹는날', sourceDate);
const targetDate = new Date('2022-05-09T10:10:10');
expect(todoItem.equalsDayOfCreatedAt(targetDate)).toBeFalsy();
});
});
121 changes: 121 additions & 0 deletions src/__tests__/201701981/todoList.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import TodoItem from "../vo/TodoItem";
import TodoList from "../vo/TodoList";

let todoItem1, todoItem2, todoItem3, todoItem4, todoItem5;
let todoList;

// 테스트 용 리스트 생성
beforeEach(() => {
todoItem1 = new TodoItem(1, '할 일 1', new Date());
todoItem2 = new TodoItem(2, '할 일 2', new Date());
todoItem3 = new TodoItem(3, '할 일 3', new Date());
todoItem4 = new TodoItem(4, '할 일 4', new Date());
todoItem5 = new TodoItem(5, '할 일 5', new Date());
const todoItemList = [todoItem1, todoItem2, todoItem3, todoItem4, todoItem5]
todoList = new TodoList(todoItemList, new Date());
});

describe("할 일 목록을 가지고 있다.", () => {
test("5개를 만들면, 5개가 있다.", () => {
expect(todoList.items).toHaveLength(5);
});
});

describe("할 일 목록에서 삭제를 할 수 있다.", () => {
test("5개의 할 일이 있는데, id가 3인 할 일을 삭제할 수 있다.", () => {
todoList.removeTodoItem(3);
expect(todoList.items).toHaveLength(4);
expect(todoList.items.some((todoItem) => todoItem.id === 3)).toBeFalsy;
});

test("존재하지 않는 id를 입력하면 삭제하지 않는다.", () => {
todoList.removeTodoItem(10); // 존재하지 않는 id
expect(todoList.items).toHaveLength(5);
});
});

describe("할 일 목록에서 할 일을 추가할 수 있다.", () => {
test("5개의 할 일이 있을 때, id가 6인 할 일을 추가할 수 있다.", () => {
const todoItem6 = new TodoItem(6, '할 일 6', new Date());

todoList.pushTodoItem(todoItem6);

expect(todoList.items).toHaveLength(6);
expect(todoList.items.some((todoItem) => todoItem.id === 6)).toBeTruthy;
});
});

describe("생성한 할 일들 중에서 오늘 할 일, 지난 할 일 구분하기", () => {
test("5개의 할 일이 있는데, 2번 빼고 오늘 만들 일이다.", () => {
// todoItem2 : equalsDayOfCreatedAt 메서드가 false 를 return 하게됨
// equalsDayItems의 filter에서 equalsDayOfCreatedAt 메서드를 사용하는 것을 알고 있다면
// 아래와 같이 코드를 작성해 수정해줄 수 있다.
jest.spyOn(todoItem2, "equalsDayOfCreatedAt").mockImplementation(() => false);

expect(todoList.equalsDayItems).toHaveLength(4);
expect(todoList.equalsDayItems.some((todoItem) => todoItem.id === 2)).toBeFalsy;
});
test("5개의 할 일이 있는데, id 2번만 지난 할 일이다.", () => {
jest.spyOn(todoItem2, "equalsDayOfCreatedAt").mockImplementation(() => false);

expect(todoList.notEqualsDayItems).toHaveLength(1);
expect(todoList.notEqualsDayItems.some((todoItem) => todoItem.id === 2)).toBeTruthy;
});
});

describe("오늘 할 일 중 완료/미완료 구분하기", () => {
test("5개의 할 일이 있는데, 2번, 3번만 완료다.", () => {
jest.spyOn(todoItem2, "completed", "get").mockReturnValue(true);
jest.spyOn(todoItem3, "completed", "get").mockReturnValue(true);
expect(todoList.equalsDayAndCompletedItems).toHaveLength(2);
expect(todoList.equalsDayAndCompletedItems.some((todoItem) => todoItem.id === 2)).toBeTruthy;
expect(todoList.equalsDayAndCompletedItems.some((todoItem) => todoItem.id === 3)).toBeTruthy;
});
test("5개의 할 일이 있는데, 4번만 미완료다", () => {
jest.spyOn(todoItem1, "completed", "get").mockReturnValue(true);
jest.spyOn(todoItem2, "completed", "get").mockReturnValue(true);
jest.spyOn(todoItem3, "completed", "get").mockReturnValue(true);
jest.spyOn(todoItem5, "completed", "get").mockReturnValue(true);
expect(todoList.equalsDayAndNotCompletedItems).toHaveLength(1);
expect(todoList.equalsDayAndNotCompletedItems.some((todoItem) => todoItem.id === 4)).toBeTruthy;
});
});

// todo

describe("지난 할 일 중 완료/미완료 구분하기", () => {
test("5개의 지난 할 일이 있는데, 2번, 3번만 완료다.", () => {
// 지난 할 일
jest.spyOn(todoItem1, "equalsDayOfCreatedAt").mockImplementation(() => false);
jest.spyOn(todoItem2, "equalsDayOfCreatedAt").mockImplementation(() => false);
jest.spyOn(todoItem3, "equalsDayOfCreatedAt").mockImplementation(() => false);
jest.spyOn(todoItem4, "equalsDayOfCreatedAt").mockImplementation(() => false);
jest.spyOn(todoItem5, "equalsDayOfCreatedAt").mockImplementation(() => false);

// 완료
// 2, 3 번만 완료로.
jest.spyOn(todoItem2, "completed", "get").mockReturnValue(true);
jest.spyOn(todoItem3, "completed", "get").mockReturnValue(true);

expect(todoList.notEqualsDayAndCompletedItems).toHaveLength(2);
expect(todoList.notEqualsDayAndCompletedItems.some((todoItem) => todoItem.id === 2)).toBeTruthy;
expect(todoList.notEqualsDayAndCompletedItems.some((todoItem) => todoItem.id === 3)).toBeTruthy;
});
test("5개의 지난 할 일이 있는데, 2번, 4번만 미완료다", () => {
// 지난 할 일
jest.spyOn(todoItem1, "equalsDayOfCreatedAt").mockImplementation(() => false);
jest.spyOn(todoItem2, "equalsDayOfCreatedAt").mockImplementation(() => false);
jest.spyOn(todoItem3, "equalsDayOfCreatedAt").mockImplementation(() => false);
jest.spyOn(todoItem4, "equalsDayOfCreatedAt").mockImplementation(() => false);
jest.spyOn(todoItem5, "equalsDayOfCreatedAt").mockImplementation(() => false);

// 완료!
// 2, 4 번 빼고 나머지를 완료로.
jest.spyOn(todoItem1, "completed", "get").mockReturnValue(true);
jest.spyOn(todoItem3, "completed", "get").mockReturnValue(true);
jest.spyOn(todoItem5, "completed", "get").mockReturnValue(true);
expect(todoList.notEqualsDayAndNotCompletedItems).toHaveLength(2);
expect(todoList.notEqualsDayAndNotCompletedItems.some((todoItem) => todoItem.id === 2)).toBeTruthy;
expect(todoList.notEqualsDayAndNotCompletedItems.some((todoItem) => todoItem.id === 4)).toBeTruthy;
});
});
53 changes: 53 additions & 0 deletions src/__tests__/202002478/todoItem.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import TodoItem from "../../vo/TodoItem";

describe("할 일을 만들 수 있다", () => {
test("todo Item 생성하기", () => {
const todoItem = new TodoItem(1, '오늘은 술 먹는날');
expect(todoItem.task).toEqual('오늘은 술 먹는날');
});
});

describe("할 일을 업데이트 할 수 있다", () => {
test("todo Item 업데이트 하기", () => {
const todoItem = new TodoItem(1, '오늘은 술 먹는날');
todoItem.updateTask('오늘은 그냥 안마실래')
expect(todoItem.task).toEqual('오늘은 그냥 안마실래');
});
});

describe("할 일을 완료/미완료로 바꿀 수 있다", () => {
test("todo Item 완료로 바꾸기", () => {
const todoItem = new TodoItem(1, '오늘은 술 먹는날');
todoItem.setComplete();
expect(todoItem.completed).toBeTruthy();
});
test("todo Item 미완료로 바꾸기", () => {
const todoItem = new TodoItem(1, '오늘은 술 먹는날');
todoItem.unsetComplete();
expect(todoItem.completed).toBeFalsy();
});
});

describe("할 일에 날짜가 들어간다", () => {
test("todo Item이 오늘 만들었으면 isToday가 true이다", () => {
const sourceDate = new Date();
const targetDate = new Date();

const todoItem = new TodoItem(1, '오늘은 술 먹는날', sourceDate);
expect(todoItem.equalsDayOfCreatedAt(targetDate)).toBeTruthy();
});
test("todo Item이 어제 만들었으면 isToday가 false이다", () => {
const sourceDate = new Date('2022-05-08T10:00:00');
const targetDate = new Date('2022-05-09T10:00:00');
const todoItem = new TodoItem(1, '오늘은 술 먹는날', sourceDate);
expect(todoItem.equalsDayOfCreatedAt(targetDate)).toBeFalsy();
});
});

describe("할 일을 완료로 생성할 수 있다", () => {
test("todo Item 완료로 만들기", () => {
const todoItem = new TodoItem(1, '오늘은 술 먹는날', new Date(), true);
expect(todoItem.completed).toBeTruthy();
});
});

113 changes: 113 additions & 0 deletions src/__tests__/202002478/todoList.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import TodoItem from "../../vo/TodoItem";
import TodoList from "../../vo/TodoList";

let todoItem1, todoItem2, todoItem3, todoItem4, todoItem5;
let todoList;

beforeEach(() => {
todoItem1 = new TodoItem(1, '할 일 1', new Date());
todoItem2 = new TodoItem(2, '할 일 2', new Date());
todoItem3 = new TodoItem(3, '할 일 3', new Date());
todoItem4 = new TodoItem(4, '할 일 4', new Date());
todoItem5 = new TodoItem(5, '할 일 5', new Date());
const todoItemList = [todoItem1, todoItem2, todoItem3, todoItem4, todoItem5]
todoList = new TodoList(todoItemList, new Date());
});

describe("할 일 목록을 가지고 있다", () => {
test("5개를 만들면 5개가 있다", () => {

expect(todoList.items).toHaveLength(5);
});
});

describe("할 일 목록에서 삭제할 수 있다", () => {
test("5개의 할 일이 있는데 id가 3인 파일을 삭제할 수 있다", () => {

todoList.removeTodoItem(3);
expect(todoList.items).toHaveLength(4);
expect(todoList.items.some((todoItem) => todoItem.id === 3)).toBeFalsy();
});
});

describe("할 일 목록에서 할 일을 추가할 수 있다", () => {
test("5개의 할 일에서 id가 6인 할일을 추가할 수 있다", () => {


const todoItem6 = new TodoItem(6, '할 일 6', new Date());

todoList.pushTodoItem(todoItem6);

expect(todoList.items).toHaveLength(6);
expect(todoList.items.some((todoItem) => todoItem.id === 6)).toBeTruthy();
});
});

describe("생성한 한 일들 중에서 오늘 할 일, 지난 할 일 구분하기", () => {
test("5개의 할 일이 있는데, 2번 빼고 오늘 만들 일이다.", () => {


jest.spyOn(todoItem2, "equalsDayOfCreatedAt").mockImplementation(() => false);

expect(todoList.equalsDayItems).toHaveLength(4);
expect(todoList.equalsDayItems.some((todoItem) => todoItem.id === 2)).toBeFalsy();
});

test("5개의 할 일이 있는데, id 2번만 지난 할 일이다.", () => {

jest.spyOn(todoItem2, "equalsDayOfCreatedAt").mockImplementation(() => false);

expect(todoList.notEqualsDayItems).toHaveLength(1);
expect(todoList.notEqualsDayItems.some((todoItem) => todoItem.id === 2)).toBeTruthy();
});
});

describe("오늘 할 일 중 완료/미완료 구분하기", () => {
test("5개의 할 일이 있는데, 2번, 3번만 완료다", () => {
jest.spyOn(todoItem2, "completed", "get").mockReturnValue(true);
jest.spyOn(todoItem3, "completed", "get").mockReturnValue(true);
expect(todoList.equalsDayAndCompletedItems).toHaveLength(2);
expect(todoList.equalsDayAndCompletedItems.some((todoItem) => todoItem.id === 2)).toBeTruthy();
expect(todoList.equalsDayAndCompletedItems.some((todoItem) => todoItem.id === 3)).toBeTruthy();
});

test("5개의 할 일이 있는데, 2번, 4번만 미완료다", () => {
jest.spyOn(todoItem1,"completed","get").mockReturnValue(true);
jest.spyOn(todoItem3,"completed","get").mockReturnValue(true);
jest.spyOn(todoItem5,"completed","get").mockReturnValue(true);

expect(todoList.equalsDayAndNotCompletedItems).toHaveLength(2);
expect(todoList.equalsDayAndNotCompletedItems.some((todoItem) => todoItem.id === 2)).toBeTruthy();
expect(todoList.equalsDayAndNotCompletedItems.some((todoItem) => todoItem.id === 4)).toBeTruthy();
});
});

describe("지난 할 일 중 완료/미완료 구분하기", () => {
test("5개의 지난 할 일이 있는데, 2번, 3번만 완료이다.", () => {
jest.spyOn(todoItem1,"equalsDayOfCreatedAt").mockImplementation(() => false);
jest.spyOn(todoItem2,"equalsDayOfCreatedAt").mockImplementation(() => false);
jest.spyOn(todoItem3,"equalsDayOfCreatedAt").mockImplementation(() => false);
jest.spyOn(todoItem4,"equalsDayOfCreatedAt").mockImplementation(() => false);
jest.spyOn(todoItem5,"equalsDayOfCreatedAt").mockImplementation(() => false);
jest.spyOn(todoItem2,"completed","get").mockReturnValue(true);
jest.spyOn(todoItem3,"completed","get").mockReturnValue(true);

expect(todoList.notEqualsDayAndCompletedItems).toHaveLength(2);
expect(todoList.notEqualsDayAndCompletedItems.some((todoItem) => todoItem.id === 2)).toBeTruthy();
expect(todoList.notEqualsDayAndCompletedItems.some((todoItem) => todoItem.id === 3)).toBeTruthy();
});
test("5개의 지난 할 일이 있는데, 2번, 4번만 미완료이다.", () => {
jest.spyOn(todoItem1,"equalsDayOfCreatedAt").mockImplementation(() => false);
jest.spyOn(todoItem2,"equalsDayOfCreatedAt").mockImplementation(() => false);
jest.spyOn(todoItem3,"equalsDayOfCreatedAt").mockImplementation(() => false);
jest.spyOn(todoItem4,"equalsDayOfCreatedAt").mockImplementation(() => false);
jest.spyOn(todoItem5,"equalsDayOfCreatedAt").mockImplementation(() => false);
jest.spyOn(todoItem1,"completed","get").mockReturnValue(true);
jest.spyOn(todoItem3,"completed","get").mockReturnValue(true);
jest.spyOn(todoItem5,"completed","get").mockReturnValue(true);

expect(todoList.notEqualsDayAndNotCompletedItems).toHaveLength(2);
expect(todoList.notEqualsDayAndNotCompletedItems.some((todoItem) => todoItem.id === 2)).toBeTruthy();
expect(todoList.notEqualsDayAndNotCompletedItems.some((todoItem) => todoItem.id === 4)).toBeTruthy();
});
});
Loading