Skip to content

Commit

Permalink
[view] AuthorBarChart util test 코드 작성 (#746)
Browse files Browse the repository at this point in the history
* style: edit author bar chart width (200 to 250)

* style: edit select-box styling

* feat: change select box from select tag to mui select

* style: edit style branch select dropdown (add marginTop)

* feat: edit branch-list fake-assets for branch name length test

* feat: add BranchSelector.const file for branch name slice length

* feat: add suffix (...) to branch name

* refactor(view): edit branch-list fake-assets

* test(view): AuthorBarChart util test - return empty data

* test(view): AuthorBarChart util test- correctly provide commit information

* refactor(view): AuthorBarChart util test expect에 type 추가

* test(view): AuthorBarChart util - sortDataByName test

* test(view): AuthorBarChart util - convertNumberFormat test

* test(view): AuthorBarChart util - sortDataByAuthor test

* test(view): AuthorBarChart util - convertNumberFormat delete tc
  • Loading branch information
xxxjinn authored Oct 8, 2024
1 parent 6608496 commit ec87027
Showing 1 changed file with 143 additions and 3 deletions.
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[]);
});
});

describe("sortDataByName", () => {
it("should return 1 when nameA is lexicographically smaller than nameB", () => {
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", () => {
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");
});
});

describe("sortDataByAuthor", () => {
it("should filter clusters based on author names", () => {
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,
},
],
},
] 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([]);
});
});

0 comments on commit ec87027

Please sign in to comment.