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

test: git integ tests scaffolding and initial test #2063

Merged
merged 3 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
82 changes: 82 additions & 0 deletions src/command/Commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,88 @@ define(function (require, exports, module) {
/** Shows the sidebar */
exports.SHOW_SIDEBAR = "view.showSidebar"; // SidebarView.js show()

// commands
/** Initializes a new git repository */
exports.CMD_GIT_INIT = "git-init";

/** Clones a git repository */
exports.CMD_GIT_CLONE = "git-clone";

/** Clones a git repository with a specific URL */
exports.CMD_GIT_CLONE_WITH_URL = "git-clone-url";

/** Opens git settings */
exports.CMD_GIT_SETTINGS_COMMAND_ID = "git-settings";

/** Closes unmodified files */
exports.CMD_GIT_CLOSE_UNMODIFIED = "git-close-unmodified-files";

/** Checks out a branch or commit */
exports.CMD_GIT_CHECKOUT = "git-checkout";

/** Performs a hard reset */
exports.CMD_GIT_RESET_HARD = "git-reset-hard";

/** Performs a soft reset */
exports.CMD_GIT_RESET_SOFT = "git-reset-soft";

/** Performs a mixed reset */
exports.CMD_GIT_RESET_MIXED = "git-reset-mixed";

/** Toggles the git panel */
exports.CMD_GIT_TOGGLE_PANEL = "git-toggle-panel";

/** Goes to next git change */
exports.CMD_GIT_GOTO_NEXT_CHANGE = "git-gotoNextChange";

/** Goes to previous git change */
exports.CMD_GIT_GOTO_PREVIOUS_CHANGE = "git-gotoPrevChange";

/** Commits current file changes */
exports.CMD_GIT_COMMIT_CURRENT = "git-commitCurrent";

/** Commits all changes */
exports.CMD_GIT_COMMIT_ALL = "git-commitAll";

/** Fetches from remote */
exports.CMD_GIT_FETCH = "git-fetch";

/** Pulls from remote */
exports.CMD_GIT_PULL = "git-pull";

/** Pushes to remote */
exports.CMD_GIT_PUSH = "git-push";

/** Refreshes git status */
exports.CMD_GIT_REFRESH = "git-refresh";

/** Creates a git tag */
exports.CMD_GIT_TAG = "git-tag";

/** Discards all changes */
exports.CMD_GIT_DISCARD_ALL_CHANGES = "git-discard-all-changes";

/** Undoes the last commit */
exports.CMD_GIT_UNDO_LAST_COMMIT = "git-undo-last-commit";

/** Changes git username */
exports.CMD_GIT_CHANGE_USERNAME = "git-change-username";

/** Changes git email */
exports.CMD_GIT_CHANGE_EMAIL = "git-change-email";

/** Pushes to Gerrit code review */
exports.CMD_GIT_GERRIT_PUSH_REF = "git-gerrit-push_ref";

/** Shows authors of selected code */
exports.CMD_GIT_AUTHORS_OF_SELECTION = "git-authors-of-selection";

/** Shows authors of current file */
exports.CMD_GIT_AUTHORS_OF_FILE = "git-authors-of-file";

/** Toggles display of untracked files */
exports.CMD_GIT_TOGGLE_UNTRACKED = "git-toggle-untracked";

// DEPRECATED: Working Set Commands
DeprecationWarning.deprecateConstant(exports, "SORT_WORKINGSET_BY_ADDED", "CMD_WORKINGSET_SORT_BY_ADDED");
DeprecationWarning.deprecateConstant(exports, "SORT_WORKINGSET_BY_NAME", "CMD_WORKINGSET_SORT_BY_NAME");
Expand Down
19 changes: 19 additions & 0 deletions src/command/Menus.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ define(function (require, exports, module) {
SPLITVIEW_MENU: "splitview-menu"
};

/**
* Brackets well known submenus
* @enum {string}
*/
let SubMenuIds = {
GIT_SUB_MENU: "git-submenu"
};

/**
* Event triggered before the context menu opens.
* @event EVENT_BEFORE_CONTEXT_MENU_OPEN
Expand Down Expand Up @@ -254,6 +262,15 @@ define(function (require, exports, module) {
return menuMap[id];
}

/**
* Retrieves the subMenu object for the corresponding id if present.
* @param {string} id
* @return {Menu}
*/
function getSubMenu(id) {
return getContextMenu(id);
}

/**
* retruns a set containing all commands that has a menu item registered
* @returns {Set<string>}
Expand Down Expand Up @@ -1755,6 +1772,7 @@ define(function (require, exports, module) {
exports.LAST_IN_SECTION = LAST_IN_SECTION;
exports.DIVIDER = DIVIDER;
exports.getMenu = getMenu;
exports.getSubMenu = getSubMenu;
exports.getAllMenus = getAllMenus;
exports.getMenuItem = getMenuItem;
exports.getContextMenu = getContextMenu;
Expand All @@ -1768,6 +1786,7 @@ define(function (require, exports, module) {
exports.Menu = Menu;
exports.MenuItem = MenuItem;
exports.ContextMenu = ContextMenu;
exports.SubMenuIds = SubMenuIds;
// public events
exports.EVENT_BEFORE_CONTEXT_MENU_OPEN = EVENT_BEFORE_CONTEXT_MENU_OPEN;
exports.EVENT_BEFORE_CONTEXT_MENU_CLOSE = EVENT_BEFORE_CONTEXT_MENU_CLOSE;
Expand Down
59 changes: 31 additions & 28 deletions src/extensions/default/Git/src/Constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,40 +19,43 @@
*/

define(function (require, exports) {
const Commands = brackets.getModule("command/Commands"),
Menus = brackets.getModule("command/Menus");

exports.GIT_STRING_UNIVERSAL = "Git";
exports.GIT_SUB_MENU = "git-submenu";
exports.GIT_SUB_MENU = Menus.SubMenuIds.GIT_SUB_MENU;

// Menus
exports.GIT_PANEL_CHANGES_CMENU = "git-panel-changes-cmenu";
exports.GIT_PANEL_HISTORY_CMENU = "git-panel-history-cmenu";
exports.GIT_PANEL_OPTIONS_CMENU = "git-panel-options-cmenu";

// commands
exports.CMD_GIT_INIT = "git-init";
exports.CMD_GIT_CLONE = "git-clone";
exports.CMD_GIT_CLONE_WITH_URL = "git-clone-url";
exports.CMD_GIT_SETTINGS_COMMAND_ID = "git-settings";
exports.CMD_GIT_CLOSE_UNMODIFIED = "git-close-unmodified-files";
exports.CMD_GIT_CHECKOUT = "git-checkout";
exports.CMD_GIT_RESET_HARD = "git-reset-hard";
exports.CMD_GIT_RESET_SOFT = "git-reset-soft";
exports.CMD_GIT_RESET_MIXED = "git-reset-mixed";
exports.CMD_GIT_TOGGLE_PANEL = "git-toggle-panel";
exports.CMD_GIT_GOTO_NEXT_CHANGE = "git-gotoNextChange";
exports.CMD_GIT_GOTO_PREVIOUS_CHANGE = "git-gotoPrevChange";
exports.CMD_GIT_COMMIT_CURRENT = "git-commitCurrent";
exports.CMD_GIT_COMMIT_ALL = "git-commitAll";
exports.CMD_GIT_FETCH = "git-fetch";
exports.CMD_GIT_PULL = "git-pull";
exports.CMD_GIT_PUSH = "git-push";
exports.CMD_GIT_REFRESH = "git-refresh";
exports.CMD_GIT_TAG = "git-tag";
exports.CMD_GIT_DISCARD_ALL_CHANGES = "git-discard-all-changes";
exports.CMD_GIT_UNDO_LAST_COMMIT = "git-undo-last-commit";
exports.CMD_GIT_CHANGE_USERNAME = "git-change-username";
exports.CMD_GIT_CHANGE_EMAIL = "git-change-email";
exports.CMD_GIT_GERRIT_PUSH_REF = "git-gerrit-push_ref";
exports.CMD_GIT_AUTHORS_OF_SELECTION = "git-authors-of-selection";
exports.CMD_GIT_AUTHORS_OF_FILE = "git-authors-of-file";
exports.CMD_GIT_TOGGLE_UNTRACKED = "git-toggle-untracked";
exports.CMD_GIT_INIT = Commands.CMD_GIT_INIT;
exports.CMD_GIT_CLONE = Commands.CMD_GIT_CLONE;
exports.CMD_GIT_CLONE_WITH_URL = Commands.CMD_GIT_CLONE_WITH_URL;
exports.CMD_GIT_SETTINGS_COMMAND_ID = Commands.CMD_GIT_SETTINGS_COMMAND_ID;
exports.CMD_GIT_CLOSE_UNMODIFIED = Commands.CMD_GIT_CLOSE_UNMODIFIED;
exports.CMD_GIT_CHECKOUT = Commands.CMD_GIT_CHECKOUT;
exports.CMD_GIT_RESET_HARD = Commands.CMD_GIT_RESET_HARD;
exports.CMD_GIT_RESET_SOFT = Commands.CMD_GIT_RESET_SOFT;
exports.CMD_GIT_RESET_MIXED = Commands.CMD_GIT_RESET_MIXED;
exports.CMD_GIT_TOGGLE_PANEL = Commands.CMD_GIT_TOGGLE_PANEL;
exports.CMD_GIT_GOTO_NEXT_CHANGE = Commands.CMD_GIT_GOTO_NEXT_CHANGE;
exports.CMD_GIT_GOTO_PREVIOUS_CHANGE = Commands.CMD_GIT_GOTO_PREVIOUS_CHANGE;
exports.CMD_GIT_COMMIT_CURRENT = Commands.CMD_GIT_COMMIT_CURRENT;
exports.CMD_GIT_COMMIT_ALL = Commands.CMD_GIT_COMMIT_ALL;
exports.CMD_GIT_FETCH = Commands.CMD_GIT_FETCH;
exports.CMD_GIT_PULL = Commands.CMD_GIT_PULL;
exports.CMD_GIT_PUSH = Commands.CMD_GIT_PUSH;
exports.CMD_GIT_REFRESH = Commands.CMD_GIT_REFRESH;
exports.CMD_GIT_TAG = Commands.CMD_GIT_TAG;
exports.CMD_GIT_DISCARD_ALL_CHANGES = Commands.CMD_GIT_DISCARD_ALL_CHANGES;
exports.CMD_GIT_UNDO_LAST_COMMIT = Commands.CMD_GIT_UNDO_LAST_COMMIT;
exports.CMD_GIT_CHANGE_USERNAME = Commands.CMD_GIT_CHANGE_USERNAME;
exports.CMD_GIT_CHANGE_EMAIL = Commands.CMD_GIT_CHANGE_EMAIL;
exports.CMD_GIT_GERRIT_PUSH_REF = Commands.CMD_GIT_GERRIT_PUSH_REF;
exports.CMD_GIT_AUTHORS_OF_SELECTION = Commands.CMD_GIT_AUTHORS_OF_SELECTION;
exports.CMD_GIT_AUTHORS_OF_FILE = Commands.CMD_GIT_AUTHORS_OF_FILE;
exports.CMD_GIT_TOGGLE_UNTRACKED = Commands.CMD_GIT_TOGGLE_UNTRACKED;
});
24 changes: 22 additions & 2 deletions src/utils/ExtensionLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,23 @@ define(function (require, exports, module) {

}

/**
* Loads the default extension located at given extensions/default/extensionFolderName . used for tests
*
* @private
* @param {string} extensionFolderName
* @return {!$.Promise} A promise object that is resolved when all extensions complete loading.
*/
function _loadDefaultExtension(extensionFolderName) {
const extensionPath = getDefaultExtensionPath();

logger.leaveTrail("loading default extension: " + extensionFolderName);
var extConfig = {
baseUrl: extensionPath + "/" + extensionFolderName
};
return loadExtension(extensionFolderName, extConfig, 'main');
}

/**
* Loads the extension that lives at baseUrl into its own Require.js context
*
Expand Down Expand Up @@ -906,8 +923,11 @@ define(function (require, exports, module) {
EventDispatcher.makeEventDispatcher(exports);

// unit tests
exports._setInitExtensionTimeout = _setInitExtensionTimeout;
exports._getInitExtensionTimeout = _getInitExtensionTimeout;
if(Phoenix.isTestWindow) {
exports._loadDefaultExtension = _loadDefaultExtension;
exports._setInitExtensionTimeout = _setInitExtensionTimeout;
exports._getInitExtensionTimeout = _getInitExtensionTimeout;
}

// private internal usage
exports._DELETED_EXTENSION_FILE_MARKER = _DELETED_EXTENSION_FILE_MARKER;
Expand Down
1 change: 1 addition & 0 deletions test/UnitTestSuite.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ define(function (require, exports, module) {
require("spec/Extn-CSSCodeHints-integ-test");
require("spec/Extn-HTMLCodeHints-Lint-integ-test");
require("spec/Extn-HtmlTagSyncEdit-integ-test");
require("spec/Extn-Git-integ-test");
// Node Tests
require("spec/NodeConnection-test");
// todo TEST_MODERN
Expand Down
132 changes: 132 additions & 0 deletions test/spec/Extn-Git-integ-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/*
* GNU AGPL-3.0 License
*
* Copyright (c) 2021 - present core.ai . All rights reserved.
* Original work Copyright (c) 2012 - 2021 Adobe Systems Incorporated. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
* for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see https://opensource.org/licenses/AGPL-3.0.
*
*/

/*global describe, it, expect, beforeEach, afterEach, awaitsForDone,beforeAll, awaitsFor */

define(function (require, exports, module) {

if(!Phoenix.isNativeApp) {
return;
}

let $, __PR, testWindow, ExtensionLoader, Menus, Commands, CommandManager,
SpecRunnerUtils = require("spec/SpecRunnerUtils"),
anotherTestFolder = SpecRunnerUtils.getTestPath("/spec/LowLevelFileIO-test-files");

let testPathGit;

function forCommandEnabled(commandID, enabled = true) {
const command = CommandManager.get(commandID);
if(!commandID){
throw new Error(`no such command ${commandID}`);
}
return awaitsFor(()=>{
return command && command.getEnabled() === enabled;
}, `Git ${commandID} to be ${enabled? "enabled" : "disabled"}`);
}

async function showGitPanel() {
if(!$("#git-panel").is(":visible")) {
await __PR.execCommand(Commands.CMD_GIT_TOGGLE_PANEL);
}
}

describe("LegacyInteg:Git Workflows test", function () {

beforeAll(async function () {
testWindow = await SpecRunnerUtils.createTestWindowAndRun({forceReload: true});
// Load module instances from brackets.test
$ = testWindow.$;
__PR = testWindow.__PR;
Menus = testWindow.brackets.test.Menus;
ExtensionLoader = testWindow.brackets.test.ExtensionLoader;
Commands = testWindow.brackets.test.Commands;
CommandManager = testWindow.brackets.test.CommandManager;
testPathGit = await SpecRunnerUtils.getTempTestDirectory("/spec/EditorCommandHandlers-test-files");

await SpecRunnerUtils.loadProjectInTestWindow(testPathGit);
await ExtensionLoader._loadDefaultExtension("Git");
await awaitsFor(()=>{
return !!Menus.getSubMenu(Menus.SubMenuIds.GIT_SUB_MENU);
}, "Git menus to be present", 10000);
}, 30000);

describe("Init repo and do all tests", function () {
let $gitPanel, $gitIcon;
beforeAll(async function () {
$gitPanel = $("#git-panel");
$gitIcon = $("#git-toolbar-icon");
});

it("should only git settings, init and clone commands be enabled in non-git repos", async function () {
await forCommandEnabled(Commands.CMD_GIT_INIT);
await forCommandEnabled(Commands.CMD_GIT_CLONE);
await forCommandEnabled(Commands.CMD_GIT_SETTINGS_COMMAND_ID);
await forCommandEnabled(Commands.CMD_GIT_TOGGLE_PANEL);
// others are disabled
await forCommandEnabled(Commands.CMD_GIT_REFRESH, false);
await forCommandEnabled(Commands.CMD_GIT_REFRESH, false);
await forCommandEnabled(Commands.CMD_GIT_FETCH, false);
await forCommandEnabled(Commands.CMD_GIT_PULL, false);
await forCommandEnabled(Commands.CMD_GIT_PUSH, false);
});

it("Should Git icon be hidden in non-git repo", async function () {
expect($gitIcon.is(":visible")).toBeFalse();
});

it("Should be able to show git panel in non-git repo, and icon will come up", async function () {
await __PR.execCommand(Commands.CMD_GIT_TOGGLE_PANEL);
expect($gitPanel.is(":visible")).toBeTrue();
expect($gitIcon.is(":visible")).toBeTrue();
// verify that only the init and clone button is visible
expect($gitPanel.find(".git-init").is(":visible")).toBeTrue();
expect($gitPanel.find(".git-clone").is(":visible")).toBeTrue();
// in non git repos the git buttons are not visible
expect($gitPanel.find(".git-commit").is(":visible")).toBeFalse();
expect($gitPanel.find(".git-prev-gutter").is(":visible")).toBeFalse();
expect($gitPanel.find(".git-file-history").is(":visible")).toBeFalse();
expect($gitPanel.find(".git-right-icons").is(":visible")).toBeFalse();
});

it("Should be able to initialize git repo", async function () {
await showGitPanel();
$gitPanel.find(".git-init").click();
await awaitsFor(()=>{
return $gitPanel.find(".modified-file").length === 4;
}, "4 files to be added in modified files list", 10000);
expect($(".check-all").prop("checked")).toBeFalse();
});

it("Should be able to stage and commit initialized git repo", async function () {
await showGitPanel();
expect($(".check-all").prop("checked")).toBeFalse();
$(".check-all").click();
await awaitsFor(()=>{
const checkboxes = document.querySelectorAll(".check-one");
return Array.from(checkboxes).every(checkbox => checkbox.checked);
}, "All files to be staged for commit", 10000);
$(".git-commit").click();
});
});

});
});
Loading