-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Filter class 구현, Filter 관련 컴포넌트 ts 적용
- 기존의 상수화된 FILTER에서 Filter 객체를 갖고 있도록 변경 및 패키지 이전
- Loading branch information
Showing
12 changed files
with
130 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import React from "react"; | ||
import { render } from "@testing-library/react"; | ||
|
||
import TodoFilter, { Props } from "./TodoFilter"; | ||
import Filter, { FILTER } from "../domain/Filter"; | ||
|
||
describe("TodoFilter", () => { | ||
function renderFilter({ selected, onSelect }: Props) { | ||
return render(<TodoFilter selected={selected} onSelect={onSelect} />); | ||
} | ||
|
||
it("render all filterState btn", () => { | ||
const { container } = renderFilter({ | ||
selected: FILTER.ALL, | ||
onSelect: jest.fn(), | ||
}); | ||
|
||
Object.values(FILTER).forEach((filter: Filter) => | ||
expect(container).toHaveTextContent(filter.getText()), | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import React from "react"; | ||
import Filter from "../domain/Filter"; | ||
|
||
export interface Props { | ||
filter: Filter; | ||
isSelected: boolean; | ||
onSelect: Function; | ||
} | ||
|
||
const TodoFilterItem: React.FC<Props> = ({ filter, isSelected, onSelect }) => { | ||
const className = [filter.getState(), isSelected ? "selected" : ""] | ||
.join(" ") | ||
.trim(); | ||
|
||
const handleSelectFilter = () => { | ||
const selected = Filter.findFilter(filter); | ||
onSelect(selected); | ||
}; | ||
|
||
return ( | ||
<li> | ||
<a | ||
className={className} | ||
href={filter.getHref()} | ||
onClick={handleSelectFilter}> | ||
{filter.getText()} | ||
</a> | ||
</li> | ||
); | ||
}; | ||
|
||
export default TodoFilterItem; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
export default class Filter { | ||
constructor( | ||
private state: string, | ||
private text: string, | ||
private href: string, | ||
) {} | ||
|
||
public static findFilter(target: Filter) { | ||
return Object.values(FILTER).find((filter: Filter) => | ||
filter.isSame(target), | ||
); | ||
} | ||
|
||
private isSame(target: Filter) { | ||
return this === target; | ||
} | ||
|
||
public getState() { | ||
return this.state; | ||
} | ||
|
||
public getText() { | ||
return this.text; | ||
} | ||
|
||
public getHref() { | ||
return this.href; | ||
} | ||
} | ||
|
||
const ALL: Filter = new Filter("all", "전체보기", "/#"); | ||
const ACTIVE: Filter = new Filter("active", "해야할 일", "/#active"); | ||
const COMPLETED: Filter = new Filter("completed", "완료한 일", "/#completed"); | ||
|
||
const FILTER = { | ||
ALL, | ||
ACTIVE, | ||
COMPLETED, | ||
}; | ||
|
||
export { FILTER }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.