summaryrefslogtreecommitdiffstats
path: root/server/sonar-web/tests/helpers/path-test.js
blob: f663fb59b12c3c45e43c7e1b927d3a56a1e157e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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');
    });
  });
});