Skip to content
This repository has been archived by the owner on Dec 17, 2021. It is now read-only.

Commit

Permalink
fixup! Add experimental history graph across branches
Browse files Browse the repository at this point in the history
  • Loading branch information
dcermak committed Apr 12, 2021
1 parent ffeea45 commit f5acc1c
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/frontend/draw-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import * as GitgraphJS from "@gitgraph/js";
import {
commitKeyToBranchName,
CommitWithChildrenFromJson,
commitWithChildrenFromJson,
getBranchName,
MessageType,
ReceivedHistoryReceivedMsg,
Expand Down Expand Up @@ -180,11 +180,11 @@ function convertMessagePayload(msg: any): SendHistoryReceivedMsg | undefined {
return {
...rest,
parentlessCommits: parentlessCommits.map((c) =>
CommitWithChildrenFromJson(c)
commitWithChildrenFromJson(c)
),
commitMapInitializer: commitMapInitializer.map(([k, commit]) => [
k,
CommitWithChildrenFromJson(commit)
commitWithChildrenFromJson(commit)
])
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/history-graph-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export interface JsonDumpedCommitWithChildren
* Converts a JSON serialized [[CommitWithChildren]] into a
* [[CommitWithChildren]].
*/
export function CommitWithChildrenFromJson(
export function commitWithChildrenFromJson(
commit: JsonDumpedCommitWithChildren
): CommitWithChildren {
const { commitTime, ...rest } = commit;
Expand Down
122 changes: 122 additions & 0 deletions src/test/suite/history-graph.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,21 @@

import { expect } from "chai";
import { afterEach, beforeEach, Context, describe, it } from "mocha";
import { Commit } from "open-build-service-api";
import { join } from "path";
import { createSandbox } from "sinon";
import { HistoryGraph } from "../../history-graph";
import {
commitKeyToBranchName,
commitToCommitWithHashes,
CommitWithChildren,
commitWithChildrenFromJson,
CommitWithHashes,
getBranchName,
getCommitKey,
isCommitWithChildren,
isCommitWithHashes
} from "../../history-graph-common";
import {
AccountMapInitializer,
createFakeWebviewView,
Expand Down Expand Up @@ -126,3 +138,113 @@ describe("HistoryGraph", () => {
);
});
});

describe("CommitWithHashes", () => {
const commitCommon = {
projectName: "bar",
packageName: "foo",
files: [],
revisionHash: "uiaeasdf",
revision: 1
};
const cmtWithChildren: CommitWithChildren = {
...commitCommon,
parentCommits: ["baz"],
childCommits: ["foo"],
commitTime: new Date(1000)
};
const cmtWithHashes: CommitWithHashes = {
...commitCommon,
parentCommits: ["bar"],
commitTime: new Date(100)
};
const cmt: Commit = {
...commitCommon,
commitTime: new Date(1337),
parentCommits: undefined
};
const cmtWithParent: Commit = {
...commitCommon,
commitTime: new Date(2674),
parentCommits: [cmt]
};

describe("#commitWithChildrenFromJson", () => {
it("reproduces a json dumped commit", () => {
commitWithChildrenFromJson(
JSON.parse(JSON.stringify(cmtWithChildren))
).should.deep.equal(cmtWithChildren);
});
});

describe("#isCommitWithHashes", () => {
it("correctly identifies a CommitWithHashes", () => {
isCommitWithHashes(cmtWithHashes).should.equal(true);
});

it("correctly identifies a CommitWithChildren", () => {
isCommitWithHashes(cmtWithChildren).should.equal(false);
});

it("correctly identifies a Commit", () => {
isCommitWithHashes(cmt).should.equal(false);
});
});

describe("#isCommitWithChildren", () => {
it("correctly identifies a CommitWithHashes", () => {
isCommitWithChildren(cmtWithHashes).should.equal(false);
});

it("correctly identifies a CommitWithChildren", () => {
isCommitWithChildren(cmtWithChildren).should.equal(true);
});

it("correctly identifies a Commit", () => {
isCommitWithChildren(cmt).should.equal(false);
});
});

describe("#commitToCommitWithHashes", () => {
it("leaves a CommitWithHashes untouched", () => {
commitToCommitWithHashes(cmtWithHashes).should.equal(cmtWithHashes);
});

it("leaves a CommitWithChildren untouched", () => {
commitToCommitWithHashes(cmtWithChildren).should.equal(cmtWithChildren);
});

it("converts a Commit", () => {
commitToCommitWithHashes(cmt).should.deep.equal({
...commitCommon,
commitTime: new Date(1337),
parentCommits: []
});
commitToCommitWithHashes(cmtWithParent).should.deep.equal({
...commitCommon,
commitTime: new Date(2674),
parentCommits: [getCommitKey(cmt)]
});
});
});

describe("#getCommitKey", () => {
it("creates a unique commit key", () => {
getCommitKey(cmt).should.deep.equal("bar/foo@uiaeasdf");
});
});

describe("#getBranchName", () => {
it("creates a unique branch name", () => {
getBranchName(cmt).should.deep.equal("bar/foo");
});
});

describe("commitKeyToBranchName", () => {
it("reconstructs the branch name from a commit key", () => {
commitKeyToBranchName(getCommitKey(cmt)).should.deep.equal(
getBranchName(cmt)
);
});
});
});

0 comments on commit f5acc1c

Please sign in to comment.