Skip to content

Commit 9b60c01

Browse files
committed
test: sidebar tabs integ tests
1 parent 4caee5a commit 9b60c01

File tree

4 files changed

+491
-31
lines changed

4 files changed

+491
-31
lines changed

src/brackets.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ define(function (require, exports, module) {
292292
WorkspaceManager: require("view/WorkspaceManager"),
293293
SearchResultsView: require("search/SearchResultsView"),
294294
ScrollTrackMarkers: require("search/ScrollTrackMarkers"),
295+
SidebarTabs: require("view/SidebarTabs"),
295296
WorkingSetView: require("project/WorkingSetView"),
296297
doneLoading: false
297298
};

src/view/SidebarTabs.js

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
*/
3535
define(function (require, exports, module) {
3636

37-
var AppInit = require("utils/AppInit"),
37+
const AppInit = require("utils/AppInit"),
3838
EventDispatcher = require("utils/EventDispatcher");
3939

4040
// --- Constants -----------------------------------------------------------
@@ -43,73 +43,73 @@ define(function (require, exports, module) {
4343
* The built-in Files tab id.
4444
* @const {string}
4545
*/
46-
var SIDEBAR_TAB_FILES = "sidebar-tab-files";
46+
const SIDEBAR_TAB_FILES = "sidebar-tab-files";
4747

4848
// --- Events --------------------------------------------------------------
4949

5050
/**
5151
* Fired when a new tab is registered via `addTab`.
5252
* @const {string}
5353
*/
54-
var EVENT_TAB_ADDED = "tabAdded";
54+
const EVENT_TAB_ADDED = "tabAdded";
5555

5656
/**
5757
* Fired when a tab is removed via `removeTab`.
5858
* @const {string}
5959
*/
60-
var EVENT_TAB_REMOVED = "tabRemoved";
60+
const EVENT_TAB_REMOVED = "tabRemoved";
6161

6262
/**
6363
* Fired when the active tab changes via `setActiveTab`.
6464
* @const {string}
6565
*/
66-
var EVENT_TAB_CHANGED = "tabChanged";
66+
const EVENT_TAB_CHANGED = "tabChanged";
6767

6868
// --- Private state -------------------------------------------------------
6969

7070
/** @type {jQuery} */
71-
var $navTabBar;
71+
let $navTabBar;
7272

7373
/** @type {jQuery} */
74-
var $sidebar;
74+
let $sidebar;
7575

7676
/**
7777
* Ordered array of registered tab descriptors.
7878
* Each entry: { id, label, iconClass, priority, $tabItem }
7979
* @type {Array}
8080
*/
81-
var _tabs = [];
81+
const _tabs = [];
8282

8383
/**
8484
* Map from tabId -> array of DOM elements (not jQuery) associated with
8585
* that tab via `addToTab`.
8686
* @type {Object.<string, Array.<Element>>}
8787
*/
88-
var _tabContent = {};
88+
const _tabContent = {};
8989

9090
/**
9191
* Set of DOM elements that were appended to #sidebar by `addToTab` (i.e.
9292
* they were NOT already children of #sidebar). Used so `removeFromTab` can
9393
* decide whether to also detach the node from the DOM.
9494
* @type {Set.<Element>}
9595
*/
96-
var _appendedNodes = new Set();
96+
const _appendedNodes = new Set();
9797

9898
/**
9999
* Currently active tab id.
100100
* @type {string}
101101
*/
102-
var _activeTabId = SIDEBAR_TAB_FILES;
102+
let _activeTabId = SIDEBAR_TAB_FILES;
103103

104104
// --- IDs to always exclude from visibility toggling ----------------------
105105

106-
var _EXCLUDED_IDS = { "mainNavBar": true, "navTabBar": true };
106+
const _EXCLUDED_IDS = { "mainNavBar": true, "navTabBar": true };
107107

108108
/**
109109
* CSS classes that mark structural/resizer elements which must never be
110110
* hidden by tab switching.
111111
*/
112-
var _EXCLUDED_CLASSES = ["horz-resizer", "vert-resizer"];
112+
const _EXCLUDED_CLASSES = ["horz-resizer", "vert-resizer"];
113113

114114
// --- Private helpers -----------------------------------------------------
115115

@@ -121,7 +121,7 @@ define(function (require, exports, module) {
121121
if (_EXCLUDED_IDS[node.id]) {
122122
return true;
123123
}
124-
for (var i = 0; i < _EXCLUDED_CLASSES.length; i++) {
124+
for (let i = 0; i < _EXCLUDED_CLASSES.length; i++) {
125125
if (node.classList.contains(_EXCLUDED_CLASSES[i])) {
126126
return true;
127127
}
@@ -136,7 +136,7 @@ define(function (require, exports, module) {
136136
$navTabBar.empty();
137137
_tabs.sort(function (a, b) { return a.priority - b.priority; });
138138
_tabs.forEach(function (tab) {
139-
var $item = $('<div class="sidebar-tab" data-tab-id="' + tab.id + '">' +
139+
const $item = $('<div class="sidebar-tab" data-tab-id="' + tab.id + '">' +
140140
'<i class="' + tab.iconClass + '"></i>' +
141141
'<span>' + tab.label + '</span>' +
142142
'</div>');
@@ -168,8 +168,8 @@ define(function (require, exports, module) {
168168
* registered tab.
169169
*/
170170
function _isNodeInAnyTab(node) {
171-
var tabIds = Object.keys(_tabContent);
172-
for (var i = 0; i < tabIds.length; i++) {
171+
const tabIds = Object.keys(_tabContent);
172+
for (let i = 0; i < tabIds.length; i++) {
173173
if (_tabContent[tabIds[i]].indexOf(node) !== -1) {
174174
return true;
175175
}
@@ -190,13 +190,13 @@ define(function (require, exports, module) {
190190
return;
191191
}
192192

193-
var children = $sidebar.children().toArray();
193+
const children = $sidebar.children().toArray();
194194

195195
if (_activeTabId === SIDEBAR_TAB_FILES) {
196196
// Files tab: show nodes that are in the files tab content OR
197197
// unassociated (not in any tab). Hide nodes that are exclusively
198198
// in other tabs.
199-
var filesNodes = new Set(_tabContent[SIDEBAR_TAB_FILES] || []);
199+
const filesNodes = new Set(_tabContent[SIDEBAR_TAB_FILES] || []);
200200

201201
children.forEach(function (child) {
202202
if (_isExcludedNode(child)) {
@@ -211,7 +211,7 @@ define(function (require, exports, module) {
211211
} else {
212212
// Non-files tab: show nodes associated with this tab, hide
213213
// everything else (except excluded nodes).
214-
var activeNodes = new Set(_tabContent[_activeTabId] || []);
214+
const activeNodes = new Set(_tabContent[_activeTabId] || []);
215215

216216
children.forEach(function (child) {
217217
if (_isExcludedNode(child)) {
@@ -241,13 +241,13 @@ define(function (require, exports, module) {
241241
options = options || {};
242242

243243
// Prevent duplicate registrations
244-
for (var i = 0; i < _tabs.length; i++) {
244+
for (let i = 0; i < _tabs.length; i++) {
245245
if (_tabs[i].id === id) {
246246
return;
247247
}
248248
}
249249

250-
var tab = {
250+
const tab = {
251251
id: id,
252252
label: label,
253253
iconClass: iconClass,
@@ -270,7 +270,7 @@ define(function (require, exports, module) {
270270
* @param {jQuery|Element} $content DOM node or jQuery wrapper
271271
*/
272272
function addToTab(tabId, $content) {
273-
var node = $content instanceof $ ? $content[0] : $content;
273+
const node = $content instanceof $ ? $content[0] : $content;
274274
if (!node) {
275275
return;
276276
}
@@ -312,12 +312,12 @@ define(function (require, exports, module) {
312312
* @param {jQuery|Element} $content DOM node or jQuery wrapper
313313
*/
314314
function removeFromTab(tabId, $content) {
315-
var node = $content instanceof $ ? $content[0] : $content;
315+
const node = $content instanceof $ ? $content[0] : $content;
316316
if (!node || !_tabContent[tabId]) {
317317
return;
318318
}
319319

320-
var idx = _tabContent[tabId].indexOf(node);
320+
const idx = _tabContent[tabId].indexOf(node);
321321
if (idx === -1) {
322322
return;
323323
}
@@ -355,8 +355,8 @@ define(function (require, exports, module) {
355355
return false;
356356
}
357357

358-
var removed = false;
359-
for (var i = _tabs.length - 1; i >= 0; i--) {
358+
let removed = false;
359+
for (let i = _tabs.length - 1; i >= 0; i--) {
360360
if (_tabs[i].id === id) {
361361
_tabs.splice(i, 1);
362362
removed = true;
@@ -388,8 +388,8 @@ define(function (require, exports, module) {
388388
*/
389389
function setActiveTab(id) {
390390
// Verify the tab exists
391-
var found = false;
392-
for (var i = 0; i < _tabs.length; i++) {
391+
let found = false;
392+
for (let i = 0; i < _tabs.length; i++) {
393393
if (_tabs[i].id === id) {
394394
found = true;
395395
break;
@@ -399,7 +399,7 @@ define(function (require, exports, module) {
399399
return;
400400
}
401401

402-
var previousTabId = _activeTabId;
402+
const previousTabId = _activeTabId;
403403
_activeTabId = id;
404404

405405
// Update active class on tab items
@@ -450,7 +450,7 @@ define(function (require, exports, module) {
450450

451451
// Set up click handler for tab switching
452452
$navTabBar.on("click", ".sidebar-tab", function () {
453-
var tabId = $(this).attr("data-tab-id");
453+
const tabId = $(this).attr("data-tab-id");
454454
if (tabId) {
455455
setActiveTab(tabId);
456456
}

test/UnitTestSuite.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ define(function (require, exports, module) {
9494
require("spec/PreferencesManager-integ-test");
9595
require("spec/MainViewFactory-integ-test");
9696
require("spec/MainViewManager-integ-test");
97+
require("spec/SidebarTabs-integ-test");
9798
require("spec/Keyboard-nav-integ-test");
9899
require("spec/Menu-integ-test");
99100
require("spec/ProjectManager-integ-test");

0 commit comments

Comments
 (0)