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

[view] AuthorBarChart util test 코드 작성 #746

Merged
merged 27 commits into from
Oct 8, 2024
Merged
Changes from 26 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
6a58676
style: edit author bar chart width (200 to 250)
xxxjinn Sep 8, 2024
63fae82
style: edit select-box styling
xxxjinn Sep 8, 2024
f50d7d7
feat: change select box from select tag to mui select
xxxjinn Sep 8, 2024
30010f4
style: edit style branch select dropdown (add marginTop)
xxxjinn Sep 8, 2024
d763194
Merge branch 'main' of https://github.com/githru/githru-vscode-ext
xxxjinn Sep 10, 2024
1b23726
Merge branch 'main' of https://github.com/githru/githru-vscode-ext
xxxjinn Sep 10, 2024
d16b546
feat: edit branch-list fake-assets for branch name length test
xxxjinn Sep 10, 2024
7068d6e
feat: add BranchSelector.const file for branch name slice length
xxxjinn Sep 10, 2024
2361f24
feat: add suffix (...) to branch name
xxxjinn Sep 10, 2024
319f1da
Merge branch 'main' of https://github.com/githru/githru-vscode-ext
xxxjinn Sep 11, 2024
92f8b2b
refactor(view): edit branch-list fake-assets
xxxjinn Sep 11, 2024
6dcbdf0
Merge branch 'main' of https://github.com/githru/githru-vscode-ext
xxxjinn Sep 12, 2024
3f2f967
Merge branch 'main' of https://github.com/githru/githru-vscode-ext
xxxjinn Sep 13, 2024
75b0e35
Merge branch 'main' of https://github.com/githru/githru-vscode-ext
xxxjinn Sep 24, 2024
d3c8814
Merge branch 'main' of https://github.com/githru/githru-vscode-ext
xxxjinn Sep 27, 2024
ec87809
Merge branch 'main' of https://github.com/githru/githru-vscode-ext
xxxjinn Sep 29, 2024
2c1397f
test(view): AuthorBarChart util test - return empty data
xxxjinn Sep 29, 2024
272472c
test(view): AuthorBarChart util test- correctly provide commit inform…
xxxjinn Sep 29, 2024
71707c3
Merge branch 'main' of https://github.com/githru/githru-vscode-ext
xxxjinn Sep 30, 2024
4b41f3e
Merge branch 'main' of https://github.com/githru/githru-vscode-ext
xxxjinn Sep 30, 2024
2faa2f7
Merge branch 'main' of https://github.com/githru/githru-vscode-ext
xxxjinn Oct 3, 2024
8a7b01e
refactor(view): AuthorBarChart util test expect에 type 추가
xxxjinn Oct 3, 2024
e28dd7f
test(view): AuthorBarChart util - sortDataByName test
xxxjinn Oct 3, 2024
5f30b9c
test(view): AuthorBarChart util - convertNumberFormat test
xxxjinn Oct 3, 2024
5274ff2
test(view): AuthorBarChart util - sortDataByAuthor test
xxxjinn Oct 3, 2024
d73768f
test(view): AuthorBarChart util - convertNumberFormat delete tc
xxxjinn Oct 3, 2024
16f47fd
Merge branch 'main' of https://github.com/githru/githru-vscode-ext
xxxjinn Oct 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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", () => {
Expand Down Expand Up @@ -87,6 +88,145 @@ describe("getDataByAuthor", () => {
insertion: 3,
deletion: 2,
},
]);
] as AuthorDataType[]);
});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

요부분이 type 추가했다고 말씀드린 부분입니다.

});

describe("sortDataByName", () => {
it("should return 1 when nameA is lexicographically smaller than nameB", () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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", () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

우왕 심플하지만 세밀한 테스트들 넘 좋습니다!! 👍👍👍👍👍

});

describe("sortDataByAuthor", () => {
it("should filter clusters based on author names", () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
Copy link
Contributor

Choose a reason for hiding this comment

The 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([]);
});
});
Loading