From ec870274efe6ccc39c5f1b146bdaf1e1c3c05b2c Mon Sep 17 00:00:00 2001 From: HyunJin <102955516+xxxjinn@users.noreply.github.com> Date: Tue, 8 Oct 2024 10:36:56 +0900 Subject: [PATCH] =?UTF-8?q?[view]=20AuthorBarChart=20util=20test=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=9E=91=EC=84=B1=20(#746)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 --- .../AuthorBarChart.util.test.ts | 146 +++++++++++++++++- 1 file changed, 143 insertions(+), 3 deletions(-) diff --git a/packages/view/src/components/Statistics/AuthorBarChart/AuthorBarChart.util.test.ts b/packages/view/src/components/Statistics/AuthorBarChart/AuthorBarChart.util.test.ts index 57bec39f..37f60ef7 100644 --- a/packages/view/src/components/Statistics/AuthorBarChart/AuthorBarChart.util.test.ts +++ b/packages/view/src/components/Statistics/AuthorBarChart/AuthorBarChart.util.test.ts @@ -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", () => { + 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([]); }); });