-
Notifications
You must be signed in to change notification settings - Fork 82
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
[view] AuthorBarChart util test 코드 작성 #746
Changes from all commits
6a58676
63fae82
f50d7d7
30010f4
d763194
1b23726
d16b546
7068d6e
2361f24
319f1da
92f8b2b
6dcbdf0
3f2f967
75b0e35
d3c8814
ec87809
2c1397f
272472c
71707c3
4b41f3e
2faa2f7
8a7b01e
e28dd7f
5f30b9c
5274ff2
d73768f
16f47fd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
import type { ClusterNode } from "types"; | ||
import type { ClusterNode, CommitNode } from "types"; | ||
import type { Commit } from "types/Commit"; | ||
|
||
import { getDataByAuthor } from "./AuthorBarChart.util"; | ||
import { convertNumberFormat, getDataByAuthor, sortDataByAuthor, sortDataByName } from "./AuthorBarChart.util"; | ||
import type { AuthorDataType } from "./AuthorBarChart.type"; | ||
|
||
describe("getDataByAuthor", () => { | ||
it("should return empty array if no data is provided", () => { | ||
|
@@ -87,6 +88,145 @@ describe("getDataByAuthor", () => { | |
insertion: 3, | ||
deletion: 2, | ||
}, | ||
]); | ||
] as AuthorDataType[]); | ||
}); | ||
}); | ||
|
||
describe("sortDataByName", () => { | ||
it("should return 1 when nameA is lexicographically smaller than nameB", () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sortDataByName 함수 테스트 |
||
const result = sortDataByName("apple", "banana"); | ||
expect(result).toBe(1); | ||
}); | ||
|
||
it("should return -1 when nameA is lexicographically larger than nameB", () => { | ||
const result = sortDataByName("banana", "apple"); | ||
expect(result).toBe(-1); | ||
}); | ||
|
||
it("should return 0 when nameA is equal to nameB", () => { | ||
const result = sortDataByName("apple", "APPLE"); | ||
expect(result).toBe(0); | ||
}); | ||
}); | ||
|
||
describe("convertNumberFormat", () => { | ||
it("should return the number as a string if it's between 0 and 1", () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. convertNumberFormat 함수 테스트 |
||
const result = convertNumberFormat(0.5); | ||
expect(result).toBe("0.5"); | ||
}); | ||
|
||
it("should format numbers greater than 1", () => { | ||
const result = convertNumberFormat(1000); | ||
expect(result).toBe("1k"); | ||
}); | ||
Comment on lines
+114
to
+120
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 우왕 심플하지만 세밀한 테스트들 넘 좋습니다!! 👍👍👍👍👍 |
||
}); | ||
|
||
describe("sortDataByAuthor", () => { | ||
it("should filter clusters based on author names", () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sortDataByAuthor 함수 테스트 |
||
const fakeData: ClusterNode[] = [ | ||
{ | ||
nodeTypeName: "CLUSTER", | ||
commitNodeList: [ | ||
{ | ||
nodeTypeName: "COMMIT", | ||
commit: { | ||
id: "1", | ||
parentIds: ["0"], | ||
author: { names: ["author1"] }, | ||
committer: { names: ["author1"] }, | ||
authorDate: "2024-01-01T00:00:00Z", | ||
commitDate: "2024-01-01T00:00:00Z", | ||
diffStatistics: { | ||
insertions: 5, | ||
deletions: 3, | ||
}, | ||
message: "Initial commit", | ||
} as CommitNode["commit"], | ||
seq: 1, | ||
clusterId: 101, | ||
}, | ||
{ | ||
nodeTypeName: "COMMIT", | ||
commit: { | ||
id: "2", | ||
parentIds: ["1"], | ||
author: { names: ["author2"] }, | ||
committer: { names: ["author2"] }, | ||
authorDate: "2024-01-02T00:00:00Z", | ||
commitDate: "2024-01-02T00:00:00Z", | ||
diffStatistics: { | ||
insertions: 2, | ||
deletions: 1, | ||
}, | ||
message: "Second commit", | ||
} as CommitNode["commit"], | ||
seq: 2, | ||
clusterId: 101, | ||
}, | ||
], | ||
}, | ||
]; | ||
|
||
const names = ["author1"]; | ||
const result = sortDataByAuthor(fakeData, names); | ||
|
||
expect(result).toEqual([ | ||
{ | ||
nodeTypeName: "CLUSTER", | ||
commitNodeList: [ | ||
{ | ||
nodeTypeName: "COMMIT", | ||
commit: { | ||
id: "1", | ||
parentIds: ["0"], | ||
author: { names: ["author1"] }, | ||
committer: { names: ["author1"] }, | ||
authorDate: "2024-01-01T00:00:00Z", | ||
commitDate: "2024-01-01T00:00:00Z", | ||
diffStatistics: { | ||
insertions: 5, | ||
deletions: 3, | ||
}, | ||
message: "Initial commit", | ||
}, | ||
seq: 1, | ||
clusterId: 101, | ||
}, | ||
], | ||
}, | ||
Comment on lines
+174
to
+195
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 아래 fakeData를 재활용해도 괜찮을 것 같습니다 : ) |
||
] as ClusterNode[]); | ||
}); | ||
|
||
it("should return an empty array if no author matches", () => { | ||
const fakeData: ClusterNode[] = [ | ||
{ | ||
nodeTypeName: "CLUSTER", | ||
commitNodeList: [ | ||
{ | ||
nodeTypeName: "COMMIT", | ||
commit: { | ||
id: "1", | ||
parentIds: ["0"], | ||
author: { names: ["author1"] }, | ||
committer: { names: ["author1"] }, | ||
authorDate: "2024-01-01T00:00:00Z", | ||
commitDate: "2024-01-01T00:00:00Z", | ||
diffStatistics: { | ||
insertions: 5, | ||
deletions: 3, | ||
}, | ||
message: "Initial commit", | ||
} as CommitNode["commit"], | ||
seq: 1, | ||
clusterId: 101, | ||
}, | ||
], | ||
}, | ||
]; | ||
|
||
const names = ["nonexistentAuthor"]; | ||
const result = sortDataByAuthor(fakeData, names); | ||
|
||
expect(result).toEqual([]); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
요부분이 type 추가했다고 말씀드린 부분입니다.