* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
+import { collapsedDirFromPath } from '../path';
+
module.exports = function (path) {
- return window.collapsedDirFromPath(path);
+ return collapsedDirFromPath(path);
};
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
+import { fileFromPath } from '../path';
+
module.exports = function (path) {
return window.fileFromPath(path);
};
var body = [].concat(head, cut ? ['...'] : [], middle, tail);
return body.join('/');
}
+
+
+/**
+ * Return a collapsed path without a file name
+ * @example
+ * // returns 'src/.../js/components/navigator/app/models/'
+ * collapsedDirFromPath('src/main/js/components/navigator/app/models/state.js')
+ * @param {string} path
+ * @returns {string|null}
+ */
+export function collapsedDirFromPath (path) {
+ var limit = 30;
+ if (typeof path === 'string') {
+ var tokens = _.initial(path.split('/'));
+ if (tokens.length > 2) {
+ var head = _.first(tokens),
+ tail = _.last(tokens),
+ middle = _.initial(_.rest(tokens)),
+ cut = false;
+ while (middle.join().length > limit && middle.length > 0) {
+ middle.shift();
+ cut = true;
+ }
+ var body = [].concat(head, cut ? ['...'] : [], middle, tail);
+ return body.join('/') + '/';
+ } else {
+ return tokens.join('/') + '/';
+ }
+ } else {
+ return null;
+ }
+}
+
+
+/**
+ * Return a file name for a given file path
+ * * @example
+ * // returns 'state.js'
+ * collapsedDirFromPath('src/main/js/components/navigator/app/models/state.js')
+ * @param {string} path
+ * @returns {string|null}
+ */
+export function fileFromPath (path) {
+ if (typeof path === 'string') {
+ var tokens = path.split('/');
+ return _.last(tokens);
+ } else {
+ return null;
+ }
+}
-/*
- * File Path
- */
-
-(function () {
- /**
- * Return a collapsed path without a file name
- * @example
- * // returns 'src/.../js/components/navigator/app/models/'
- * collapsedDirFromPath('src/main/js/components/navigator/app/models/state.js')
- * @param {string} path
- * @returns {string|null}
- */
- window.collapsedDirFromPath = function (path) {
- var limit = 30;
- if (typeof path === 'string') {
- var tokens = _.initial(path.split('/'));
- if (tokens.length > 2) {
- var head = _.first(tokens),
- tail = _.last(tokens),
- middle = _.initial(_.rest(tokens)),
- cut = false;
- while (middle.join().length > limit && middle.length > 0) {
- middle.shift();
- cut = true;
- }
- var body = [].concat(head, cut ? ['...'] : [], middle, tail);
- return body.join('/') + '/';
- } else {
- return tokens.join('/') + '/';
- }
- } else {
- return null;
- }
- };
-
- /**
- * Return a file name for a given file path
- * * @example
- * // returns 'state.js'
- * collapsedDirFromPath('src/main/js/components/navigator/app/models/state.js')
- * @param {string} path
- * @returns {string|null}
- */
- window.fileFromPath = function (path) {
- if (typeof path === 'string') {
- var tokens = path.split('/');
- return _.last(tokens);
- } else {
- return null;
- }
- };
-})();
-
-
-
/*
* Users
*/
import SearchTemplate from '../templates/nav-search.hbs';
import RecentHistory from '../component/recent-history';
import { translate } from '../../../helpers/l10n';
+import { collapsedDirFromPath, fileFromPath } from '../../../helpers/path';
var SearchItemView = Marionette.ItemView.extend({
tagName: 'li',
var isFile = ['FIL', 'UTS'].indexOf(f.qualifier) !== -1;
return {
url: baseUrl + '/dashboard/index?id=' + encodeURIComponent(f.key) + window.dashboardParameters(true),
- name: isFile ? window.collapsedDirFromPath(f.lname) + window.fileFromPath(f.lname) : f.name,
+ name: isFile ? collapsedDirFromPath(f.lname) + fileFromPath(f.lname) : f.name,
icon: 'favorite'
};
});
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import $ from 'jquery';
+import { collapsedDirFromPath, fileFromPath } from '../../helpers/path';
window.SonarWidgets = window.SonarWidgets == null ? {} : window.SonarWidgets;
sizeMetricValue = d.measures[widget.sizeMetric].fval;
return '<div class="text-left">' +
- window.collapsedDirFromPath(d.longName) + '<br>' +
- window.fileFromPath(d.longName) + '<br>' + '<br>' +
+ collapsedDirFromPath(d.longName) + '<br>' +
+ fileFromPath(d.longName) + '<br>' + '<br>' +
xMetricName + ': ' + xMetricValue + '<br>' +
yMetricName + ': ' + yMetricValue + '<br>' +
sizeMetricName + ': ' + sizeMetricValue +
+++ /dev/null
-describe.skip('Application', function () {
- describe('#collapsedDirFromPath()', function () {
- it('should return null when pass null', function () {
- assert.isNull(window.collapsedDirFromPath(null));
- });
-
- it('should return "/" when pass "/"', function () {
- assert.equal(window.collapsedDirFromPath('/'), '/');
- });
-
- it('should not cut short path', function () {
- assert.equal(window.collapsedDirFromPath('src/main/js/components/state.js'), 'src/main/js/components/');
- });
-
- it('should cut long path', function () {
- assert.equal(window.collapsedDirFromPath('src/main/js/components/navigator/app/models/state.js'),
- 'src/.../js/components/navigator/app/models/');
- });
-
- it('should cut very long path', function () {
- assert.equal(window.collapsedDirFromPath('src/main/another/js/components/navigator/app/models/state.js'),
- 'src/.../js/components/navigator/app/models/');
- });
- });
-
- describe('#fileFromPath()', function () {
- it('should return null when pass null', function () {
- assert.isNull(window.fileFromPath(null));
- });
-
- it('should return empty string when pass "/"', function () {
- assert.equal(window.fileFromPath('/'), '');
- });
-
- it('should return file name when pass only file name', function () {
- assert.equal(window.fileFromPath('file.js'), 'file.js');
- });
-
- it('should return file name when pass file path', function () {
- assert.equal(window.fileFromPath('src/main/js/file.js'), 'file.js');
- });
-
- it('should return file name when pass file name without extension', function () {
- assert.equal(window.fileFromPath('src/main/file'), 'file');
- });
- });
-
- describe('Severity Comparators', function () {
- describe('#severityComparator', function () {
- it('should have correct order', function () {
- assert.equal(window.severityComparator('BLOCKER'), 0);
- assert.equal(window.severityComparator('CRITICAL'), 1);
- assert.equal(window.severityComparator('MAJOR'), 2);
- assert.equal(window.severityComparator('MINOR'), 3);
- assert.equal(window.severityComparator('INFO'), 4);
- });
- });
-
- describe('#severityColumnsComparator', function () {
- it('should have correct order', function () {
- assert.equal(window.severityColumnsComparator('BLOCKER'), 0);
- assert.equal(window.severityColumnsComparator('CRITICAL'), 2);
- assert.equal(window.severityColumnsComparator('MAJOR'), 4);
- assert.equal(window.severityColumnsComparator('MINOR'), 1);
- assert.equal(window.severityColumnsComparator('INFO'), 3);
- });
- });
- });
-});
--- /dev/null
+import { expect } from 'chai';
+import { collapsedDirFromPath, fileFromPath } from '../../src/main/js/helpers/path'
+
+describe('Path', function () {
+ describe('#collapsedDirFromPath()', function () {
+ it('should return null when pass null', function () {
+ expect(collapsedDirFromPath(null)).to.be.null;
+ });
+
+ it('should return "/" when pass "/"', function () {
+ expect(collapsedDirFromPath('/')).to.equal('/');
+ });
+
+ it('should not cut short path', function () {
+ expect(collapsedDirFromPath('src/main/js/components/state.js')).to.equal('src/main/js/components/');
+ });
+
+ it('should cut long path', function () {
+ expect(collapsedDirFromPath('src/main/js/components/navigator/app/models/state.js'))
+ .to.equal('src/.../js/components/navigator/app/models/');
+ });
+
+ it('should cut very long path', function () {
+ expect(collapsedDirFromPath('src/main/another/js/components/navigator/app/models/state.js'))
+ .to.equal('src/.../js/components/navigator/app/models/');
+ });
+ });
+
+ describe('#fileFromPath()', function () {
+ it('should return null when pass null', function () {
+ expect(fileFromPath(null)).to.be.null;
+ });
+
+ it('should return empty string when pass "/"', function () {
+ expect(fileFromPath('/')).to.equal('');
+ });
+
+ it('should return file name when pass only file name', function () {
+ expect(fileFromPath('file.js')).to.equal('file.js');
+ });
+
+ it('should return file name when pass file path', function () {
+ expect(fileFromPath('src/main/js/file.js')).to.equal('file.js');
+ });
+
+ it('should return file name when pass file name without extension', function () {
+ expect(fileFromPath('src/main/file')).to.equal('file');
+ });
+ });
+});