Skip to content

Commit 66c253d

Browse files
committed
test: git integ tests scaffolding and initial test
1 parent fe4a1c7 commit 66c253d

File tree

6 files changed

+237
-30
lines changed

6 files changed

+237
-30
lines changed

src/command/Commands.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,88 @@ define(function (require, exports, module) {
483483
/** Shows the sidebar */
484484
exports.SHOW_SIDEBAR = "view.showSidebar"; // SidebarView.js show()
485485

486+
// commands
487+
/** Initializes a new git repository */
488+
exports.CMD_GIT_INIT = "git-init";
489+
490+
/** Clones a git repository */
491+
exports.CMD_GIT_CLONE = "git-clone";
492+
493+
/** Clones a git repository with a specific URL */
494+
exports.CMD_GIT_CLONE_WITH_URL = "git-clone-url";
495+
496+
/** Opens git settings */
497+
exports.CMD_GIT_SETTINGS_COMMAND_ID = "git-settings";
498+
499+
/** Closes unmodified files */
500+
exports.CMD_GIT_CLOSE_UNMODIFIED = "git-close-unmodified-files";
501+
502+
/** Checks out a branch or commit */
503+
exports.CMD_GIT_CHECKOUT = "git-checkout";
504+
505+
/** Performs a hard reset */
506+
exports.CMD_GIT_RESET_HARD = "git-reset-hard";
507+
508+
/** Performs a soft reset */
509+
exports.CMD_GIT_RESET_SOFT = "git-reset-soft";
510+
511+
/** Performs a mixed reset */
512+
exports.CMD_GIT_RESET_MIXED = "git-reset-mixed";
513+
514+
/** Toggles the git panel */
515+
exports.CMD_GIT_TOGGLE_PANEL = "git-toggle-panel";
516+
517+
/** Goes to next git change */
518+
exports.CMD_GIT_GOTO_NEXT_CHANGE = "git-gotoNextChange";
519+
520+
/** Goes to previous git change */
521+
exports.CMD_GIT_GOTO_PREVIOUS_CHANGE = "git-gotoPrevChange";
522+
523+
/** Commits current file changes */
524+
exports.CMD_GIT_COMMIT_CURRENT = "git-commitCurrent";
525+
526+
/** Commits all changes */
527+
exports.CMD_GIT_COMMIT_ALL = "git-commitAll";
528+
529+
/** Fetches from remote */
530+
exports.CMD_GIT_FETCH = "git-fetch";
531+
532+
/** Pulls from remote */
533+
exports.CMD_GIT_PULL = "git-pull";
534+
535+
/** Pushes to remote */
536+
exports.CMD_GIT_PUSH = "git-push";
537+
538+
/** Refreshes git status */
539+
exports.CMD_GIT_REFRESH = "git-refresh";
540+
541+
/** Creates a git tag */
542+
exports.CMD_GIT_TAG = "git-tag";
543+
544+
/** Discards all changes */
545+
exports.CMD_GIT_DISCARD_ALL_CHANGES = "git-discard-all-changes";
546+
547+
/** Undoes the last commit */
548+
exports.CMD_GIT_UNDO_LAST_COMMIT = "git-undo-last-commit";
549+
550+
/** Changes git username */
551+
exports.CMD_GIT_CHANGE_USERNAME = "git-change-username";
552+
553+
/** Changes git email */
554+
exports.CMD_GIT_CHANGE_EMAIL = "git-change-email";
555+
556+
/** Pushes to Gerrit code review */
557+
exports.CMD_GIT_GERRIT_PUSH_REF = "git-gerrit-push_ref";
558+
559+
/** Shows authors of selected code */
560+
exports.CMD_GIT_AUTHORS_OF_SELECTION = "git-authors-of-selection";
561+
562+
/** Shows authors of current file */
563+
exports.CMD_GIT_AUTHORS_OF_FILE = "git-authors-of-file";
564+
565+
/** Toggles display of untracked files */
566+
exports.CMD_GIT_TOGGLE_UNTRACKED = "git-toggle-untracked";
567+
486568
// DEPRECATED: Working Set Commands
487569
DeprecationWarning.deprecateConstant(exports, "SORT_WORKINGSET_BY_ADDED", "CMD_WORKINGSET_SORT_BY_ADDED");
488570
DeprecationWarning.deprecateConstant(exports, "SORT_WORKINGSET_BY_NAME", "CMD_WORKINGSET_SORT_BY_NAME");

src/command/Menus.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ define(function (require, exports, module) {
7575
SPLITVIEW_MENU: "splitview-menu"
7676
};
7777

78+
/**
79+
* Brackets well known submenus
80+
* @enum {string}
81+
*/
82+
let SubMenuIds = {
83+
GIT_SUB_MENU: "git-submenu"
84+
};
85+
7886
/**
7987
* Event triggered before the context menu opens.
8088
* @event EVENT_BEFORE_CONTEXT_MENU_OPEN
@@ -254,6 +262,15 @@ define(function (require, exports, module) {
254262
return menuMap[id];
255263
}
256264

265+
/**
266+
* Retrieves the subMenu object for the corresponding id if present.
267+
* @param {string} id
268+
* @return {Menu}
269+
*/
270+
function getSubMenu(id) {
271+
return getContextMenu(id);
272+
}
273+
257274
/**
258275
* retruns a set containing all commands that has a menu item registered
259276
* @returns {Set<string>}
@@ -1755,6 +1772,7 @@ define(function (require, exports, module) {
17551772
exports.LAST_IN_SECTION = LAST_IN_SECTION;
17561773
exports.DIVIDER = DIVIDER;
17571774
exports.getMenu = getMenu;
1775+
exports.getSubMenu = getSubMenu;
17581776
exports.getAllMenus = getAllMenus;
17591777
exports.getMenuItem = getMenuItem;
17601778
exports.getContextMenu = getContextMenu;
@@ -1768,6 +1786,7 @@ define(function (require, exports, module) {
17681786
exports.Menu = Menu;
17691787
exports.MenuItem = MenuItem;
17701788
exports.ContextMenu = ContextMenu;
1789+
exports.SubMenuIds = SubMenuIds;
17711790
// public events
17721791
exports.EVENT_BEFORE_CONTEXT_MENU_OPEN = EVENT_BEFORE_CONTEXT_MENU_OPEN;
17731792
exports.EVENT_BEFORE_CONTEXT_MENU_CLOSE = EVENT_BEFORE_CONTEXT_MENU_CLOSE;

src/extensions/default/Git/src/Constants.js

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,40 +19,43 @@
1919
*/
2020

2121
define(function (require, exports) {
22+
const Commands = brackets.getModule("command/Commands"),
23+
Menus = brackets.getModule("command/Menus");
24+
2225
exports.GIT_STRING_UNIVERSAL = "Git";
23-
exports.GIT_SUB_MENU = "git-submenu";
26+
exports.GIT_SUB_MENU = Menus.SubMenuIds.GIT_SUB_MENU;
2427

2528
// Menus
2629
exports.GIT_PANEL_CHANGES_CMENU = "git-panel-changes-cmenu";
2730
exports.GIT_PANEL_HISTORY_CMENU = "git-panel-history-cmenu";
2831
exports.GIT_PANEL_OPTIONS_CMENU = "git-panel-options-cmenu";
2932

3033
// commands
31-
exports.CMD_GIT_INIT = "git-init";
32-
exports.CMD_GIT_CLONE = "git-clone";
33-
exports.CMD_GIT_CLONE_WITH_URL = "git-clone-url";
34-
exports.CMD_GIT_SETTINGS_COMMAND_ID = "git-settings";
35-
exports.CMD_GIT_CLOSE_UNMODIFIED = "git-close-unmodified-files";
36-
exports.CMD_GIT_CHECKOUT = "git-checkout";
37-
exports.CMD_GIT_RESET_HARD = "git-reset-hard";
38-
exports.CMD_GIT_RESET_SOFT = "git-reset-soft";
39-
exports.CMD_GIT_RESET_MIXED = "git-reset-mixed";
40-
exports.CMD_GIT_TOGGLE_PANEL = "git-toggle-panel";
41-
exports.CMD_GIT_GOTO_NEXT_CHANGE = "git-gotoNextChange";
42-
exports.CMD_GIT_GOTO_PREVIOUS_CHANGE = "git-gotoPrevChange";
43-
exports.CMD_GIT_COMMIT_CURRENT = "git-commitCurrent";
44-
exports.CMD_GIT_COMMIT_ALL = "git-commitAll";
45-
exports.CMD_GIT_FETCH = "git-fetch";
46-
exports.CMD_GIT_PULL = "git-pull";
47-
exports.CMD_GIT_PUSH = "git-push";
48-
exports.CMD_GIT_REFRESH = "git-refresh";
49-
exports.CMD_GIT_TAG = "git-tag";
50-
exports.CMD_GIT_DISCARD_ALL_CHANGES = "git-discard-all-changes";
51-
exports.CMD_GIT_UNDO_LAST_COMMIT = "git-undo-last-commit";
52-
exports.CMD_GIT_CHANGE_USERNAME = "git-change-username";
53-
exports.CMD_GIT_CHANGE_EMAIL = "git-change-email";
54-
exports.CMD_GIT_GERRIT_PUSH_REF = "git-gerrit-push_ref";
55-
exports.CMD_GIT_AUTHORS_OF_SELECTION = "git-authors-of-selection";
56-
exports.CMD_GIT_AUTHORS_OF_FILE = "git-authors-of-file";
57-
exports.CMD_GIT_TOGGLE_UNTRACKED = "git-toggle-untracked";
34+
exports.CMD_GIT_INIT = Commands.CMD_GIT_INIT;
35+
exports.CMD_GIT_CLONE = Commands.CMD_GIT_CLONE;
36+
exports.CMD_GIT_CLONE_WITH_URL = Commands.CMD_GIT_CLONE_WITH_URL;
37+
exports.CMD_GIT_SETTINGS_COMMAND_ID = Commands.CMD_GIT_SETTINGS_COMMAND_ID;
38+
exports.CMD_GIT_CLOSE_UNMODIFIED = Commands.CMD_GIT_CLOSE_UNMODIFIED;
39+
exports.CMD_GIT_CHECKOUT = Commands.CMD_GIT_CHECKOUT;
40+
exports.CMD_GIT_RESET_HARD = Commands.CMD_GIT_RESET_HARD;
41+
exports.CMD_GIT_RESET_SOFT = Commands.CMD_GIT_RESET_SOFT;
42+
exports.CMD_GIT_RESET_MIXED = Commands.CMD_GIT_RESET_MIXED;
43+
exports.CMD_GIT_TOGGLE_PANEL = Commands.CMD_GIT_TOGGLE_PANEL;
44+
exports.CMD_GIT_GOTO_NEXT_CHANGE = Commands.CMD_GIT_GOTO_NEXT_CHANGE;
45+
exports.CMD_GIT_GOTO_PREVIOUS_CHANGE = Commands.CMD_GIT_GOTO_PREVIOUS_CHANGE;
46+
exports.CMD_GIT_COMMIT_CURRENT = Commands.CMD_GIT_COMMIT_CURRENT;
47+
exports.CMD_GIT_COMMIT_ALL = Commands.CMD_GIT_COMMIT_ALL;
48+
exports.CMD_GIT_FETCH = Commands.CMD_GIT_FETCH;
49+
exports.CMD_GIT_PULL = Commands.CMD_GIT_PULL;
50+
exports.CMD_GIT_PUSH = Commands.CMD_GIT_PUSH;
51+
exports.CMD_GIT_REFRESH = Commands.CMD_GIT_REFRESH;
52+
exports.CMD_GIT_TAG = Commands.CMD_GIT_TAG;
53+
exports.CMD_GIT_DISCARD_ALL_CHANGES = Commands.CMD_GIT_DISCARD_ALL_CHANGES;
54+
exports.CMD_GIT_UNDO_LAST_COMMIT = Commands.CMD_GIT_UNDO_LAST_COMMIT;
55+
exports.CMD_GIT_CHANGE_USERNAME = Commands.CMD_GIT_CHANGE_USERNAME;
56+
exports.CMD_GIT_CHANGE_EMAIL = Commands.CMD_GIT_CHANGE_EMAIL;
57+
exports.CMD_GIT_GERRIT_PUSH_REF = Commands.CMD_GIT_GERRIT_PUSH_REF;
58+
exports.CMD_GIT_AUTHORS_OF_SELECTION = Commands.CMD_GIT_AUTHORS_OF_SELECTION;
59+
exports.CMD_GIT_AUTHORS_OF_FILE = Commands.CMD_GIT_AUTHORS_OF_FILE;
60+
exports.CMD_GIT_TOGGLE_UNTRACKED = Commands.CMD_GIT_TOGGLE_UNTRACKED;
5861
});

src/utils/ExtensionLoader.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,23 @@ define(function (require, exports, module) {
624624

625625
}
626626

627+
/**
628+
* Loads the default extension located at given extensions/default/extensionFolderName . used for tests
629+
*
630+
* @private
631+
* @param {string} extensionFolderName
632+
* @return {!$.Promise} A promise object that is resolved when all extensions complete loading.
633+
*/
634+
function _loadDefaultExtension(extensionFolderName) {
635+
const extensionPath = getDefaultExtensionPath();
636+
637+
logger.leaveTrail("loading default extension: " + extensionFolderName);
638+
var extConfig = {
639+
baseUrl: extensionPath + "/" + extensionFolderName
640+
};
641+
return loadExtension(extensionFolderName, extConfig, 'main');
642+
}
643+
627644
/**
628645
* Loads the extension that lives at baseUrl into its own Require.js context
629646
*
@@ -906,8 +923,11 @@ define(function (require, exports, module) {
906923
EventDispatcher.makeEventDispatcher(exports);
907924

908925
// unit tests
909-
exports._setInitExtensionTimeout = _setInitExtensionTimeout;
910-
exports._getInitExtensionTimeout = _getInitExtensionTimeout;
926+
if(Phoenix.isTestWindow) {
927+
exports._loadDefaultExtension = _loadDefaultExtension;
928+
exports._setInitExtensionTimeout = _setInitExtensionTimeout;
929+
exports._getInitExtensionTimeout = _getInitExtensionTimeout;
930+
}
911931

912932
// private internal usage
913933
exports._DELETED_EXTENSION_FILE_MARKER = _DELETED_EXTENSION_FILE_MARKER;

test/UnitTestSuite.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ define(function (require, exports, module) {
131131
require("spec/Extn-CSSCodeHints-integ-test");
132132
require("spec/Extn-HTMLCodeHints-Lint-integ-test");
133133
require("spec/Extn-HtmlTagSyncEdit-integ-test");
134+
require("spec/Extn-Git-integ-test");
134135
// Node Tests
135136
require("spec/NodeConnection-test");
136137
// todo TEST_MODERN

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

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
* GNU AGPL-3.0 License
3+
*
4+
* Copyright (c) 2021 - present core.ai . All rights reserved.
5+
* Original work Copyright (c) 2012 - 2021 Adobe Systems Incorporated. All rights reserved.
6+
*
7+
* This program is free software: you can redistribute it and/or modify it
8+
* under the terms of the GNU Affero General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful, but WITHOUT
13+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
15+
* for more details.
16+
*
17+
* You should have received a copy of the GNU Affero General Public License
18+
* along with this program. If not, see https://opensource.org/licenses/AGPL-3.0.
19+
*
20+
*/
21+
22+
/*global describe, it, expect, beforeEach, afterEach, awaitsForDone,beforeAll, awaitsFor */
23+
24+
define(function (require, exports, module) {
25+
26+
if(!Phoenix.isNativeApp) {
27+
return;
28+
}
29+
30+
let $, __PR, testWindow, ExtensionLoader, Menus, Commands, CommandManager,
31+
SpecRunnerUtils = require("spec/SpecRunnerUtils"),
32+
anotherTestFolder = SpecRunnerUtils.getTestPath("/spec/LowLevelFileIO-test-files");
33+
34+
let testPathGit;
35+
36+
function forCommandEnabled(commandID, enabled = true) {
37+
const command = CommandManager.get(commandID);
38+
if(!commandID){
39+
throw new Error(`no such command ${commandID}`);
40+
}
41+
return awaitsFor(()=>{
42+
return command && command.getEnabled() === enabled;
43+
}, `Git ${commandID} to be ${enabled? "enabled" : "disabled"}`);
44+
}
45+
46+
describe("LegacyInteg:Git Workflows test", function () {
47+
48+
beforeAll(async function () {
49+
testWindow = await SpecRunnerUtils.createTestWindowAndRun({forceReload: true});
50+
// Load module instances from brackets.test
51+
$ = testWindow.$;
52+
__PR = testWindow.__PR;
53+
Menus = testWindow.brackets.test.Menus;
54+
ExtensionLoader = testWindow.brackets.test.ExtensionLoader;
55+
Commands = testWindow.brackets.test.Commands;
56+
CommandManager = testWindow.brackets.test.CommandManager;
57+
testPathGit = await SpecRunnerUtils.getTempTestDirectory("/spec/EditorCommandHandlers-test-files");
58+
59+
await SpecRunnerUtils.loadProjectInTestWindow(testPathGit);
60+
await ExtensionLoader._loadDefaultExtension("Git");
61+
await awaitsFor(()=>{
62+
return !!Menus.getSubMenu(Menus.SubMenuIds.GIT_SUB_MENU);
63+
}, "Git menus to be present", 10000);
64+
}, 30000);
65+
66+
describe("Init repo", function () {
67+
it("should only git settings, init and clone commands be enabled in non-git repos", async function () {
68+
await forCommandEnabled(Commands.CMD_GIT_INIT);
69+
await forCommandEnabled(Commands.CMD_GIT_CLONE);
70+
await forCommandEnabled(Commands.CMD_GIT_SETTINGS_COMMAND_ID);
71+
await forCommandEnabled(Commands.CMD_GIT_TOGGLE_PANEL);
72+
// others are disabled
73+
await forCommandEnabled(Commands.CMD_GIT_REFRESH, false);
74+
await forCommandEnabled(Commands.CMD_GIT_REFRESH, false);
75+
await forCommandEnabled(Commands.CMD_GIT_FETCH, false);
76+
await forCommandEnabled(Commands.CMD_GIT_PULL, false);
77+
await forCommandEnabled(Commands.CMD_GIT_PUSH, false);
78+
});
79+
});
80+
81+
});
82+
});

0 commit comments

Comments
 (0)