Skip to content

Commit cfc6268

Browse files
committed
test: git history viewer and username/email config integ tests
1 parent d8b42da commit cfc6268

File tree

2 files changed

+96
-1
lines changed

2 files changed

+96
-1
lines changed

src/extensions/default/Git/main.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ define(function (require, exports, module) {
1818
Events = require("src/Events"),
1919
Main = require("src/Main"),
2020
Preferences = require("src/Preferences"),
21+
Git = require("src/git/Git"),
2122
BracketsEvents = require("src/BracketsEvents");
2223

2324
// Load extension modules that are not included by core
@@ -49,7 +50,8 @@ define(function (require, exports, module) {
4950
if (typeof window === "object") {
5051
window.phoenixGitEvents = {
5152
EventEmitter: EventEmitter,
52-
Events: Events
53+
Events: Events,
54+
Git
5355
};
5456
}
5557
});

test/spec/Extn-Git-integ-test.js

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,29 @@ define(function (require, exports, module) {
7878
$gitIcon = $("#git-toolbar-icon");
7979
});
8080

81+
it("should git username and email be valid", async function () {
82+
const tempUser = "phcodeTestGitUser";
83+
const tempEmail = "[email protected]";
84+
// username validate
85+
let currentVal = await testWindow.phoenixGitEvents.Git.getConfig("user.name");
86+
if(!currentVal) {
87+
await testWindow.phoenixGitEvents.Git.setConfig("user.name", tempUser, true);
88+
currentVal = await testWindow.phoenixGitEvents.Git.getConfig("user.name");
89+
expect(currentVal).toBe(tempUser);
90+
} else {
91+
expect(currentVal).toBeDefined();
92+
}
93+
// email validate
94+
currentVal = await testWindow.phoenixGitEvents.Git.getConfig("user.email");
95+
if(!currentVal) {
96+
await testWindow.phoenixGitEvents.Git.setConfig("user.email", tempEmail, true);
97+
currentVal = await testWindow.phoenixGitEvents.Git.getConfig("user.email");
98+
expect(currentVal).toBe(tempEmail);
99+
} else {
100+
expect(currentVal).toBeDefined();
101+
}
102+
});
103+
81104
it("should only git settings, init and clone commands be enabled in non-git repos", async function () {
82105
await forCommandEnabled(Commands.CMD_GIT_INIT);
83106
await forCommandEnabled(Commands.CMD_GIT_CLONE);
@@ -255,6 +278,76 @@ define(function (require, exports, module) {
255278
return $(".git-edited-list tr").length === 0;
256279
}, "no files to be commited", 10000);
257280
});
281+
282+
async function waitForHistoryVisible(visible) {
283+
await awaitsFor(() => {
284+
return $gitPanel.find("#git-history-list").is(":visible") === visible;
285+
}, `History list to be visible: ${visible}`);
286+
}
287+
288+
async function testHistoryToggle(whichHistory) {
289+
const $historyToggleButton = $gitPanel.find(whichHistory);
290+
291+
$historyToggleButton.trigger("click");
292+
await waitForHistoryVisible(true);
293+
294+
const $historyList = $gitPanel.find("#git-history-list");
295+
296+
// Check if the first and second commits are displayed
297+
const $historyCommits = $historyList.find(".commit-subject");
298+
expect($historyCommits.length).toBeGreaterThanOrEqual(2);
299+
300+
// Verify the content of the first and second commits
301+
expect($historyCommits.eq(0).text().trim()).toBe("second commit");
302+
expect($historyCommits.eq(1).text().trim()).toBe("first commit");
303+
304+
$historyToggleButton.trigger("click");
305+
await waitForHistoryVisible(false);
306+
}
307+
308+
it("should show history with first and second commit on clicking global history", async () => {
309+
await testHistoryToggle(".git-history-toggle");
310+
});
311+
312+
it("should show history with first and second commit on clicking global history", async () => {
313+
await testHistoryToggle(".git-file-history");
314+
});
315+
316+
async function waitForHistoryViewerVisible(visible) {
317+
await awaitsFor(() => {
318+
return $("#history-viewer").is(":visible") === visible;
319+
}, `History viewer to be visible: ${visible}`);
320+
}
321+
322+
async function testHistoryViewerToggle(commitIndex) {
323+
const $historyList = $gitPanel.find("#git-history-list");
324+
const $commitRow = $historyList.find(".history-commit").eq(commitIndex);
325+
326+
// Ensure the commit row exists
327+
expect($commitRow.length).toBe(1);
328+
329+
// Click the row to show the history viewer
330+
$commitRow.trigger("click");
331+
await waitForHistoryViewerVisible(true);
332+
333+
// Verify that the history viewer shows the correct commit
334+
const $historyViewer = $("#editor-holder .git");
335+
await awaitsFor(() => {
336+
return $historyViewer.find(".commit-title").text().trim().includes("first commit");
337+
}, `History viewer to have commit detail`);
338+
339+
// Click the row again to dismiss the history viewer
340+
$commitRow.trigger("click");
341+
await waitForHistoryViewerVisible(false);
342+
}
343+
344+
it("should show the history viewer when clicking the first commit row and dismiss it on clicking again", async () => {
345+
const $historyToggleButton = $gitPanel.find(".git-history-toggle");
346+
$historyToggleButton.trigger("click");
347+
await waitForHistoryVisible(true); // Ensure the history list is visible
348+
await testHistoryViewerToggle(1); // Test for the first commit row
349+
});
350+
258351
});
259352

260353
});

0 commit comments

Comments
 (0)