1 | var assert = require ('assert');
|
2 | var path = require ('path');
|
3 | var item_manager = require('../lib/item-manager');
|
4 |
|
5 | describe ('item_manager', function(){
|
6 |
|
7 | var packagesLocalFolder = path.join(process.cwd(), "/test/fixtures/packages");
|
8 | var packagesAtlasboardFolder = path.join(process.cwd(), "/packages");
|
9 | var packagesTestNamespacing = path.join(process.cwd(), "/test/fixtures/package_test_namespacing");
|
10 | var packageWithDisabledDashboards = path.join(process.cwd(), "/test/fixtures/package_with_disabled_dashboards");
|
11 |
|
12 | describe ('resolve location', function(){
|
13 | it('should resolve location of dashboards correctly', function(done){
|
14 | var location = item_manager.resolve_location("dashboard1","dashboards",'.json');
|
15 | assert.equal("dashboards/dashboard1.json", location);
|
16 | done();
|
17 | });
|
18 |
|
19 | it('should resolve location of jobs correctly', function(done){
|
20 | var location = item_manager.resolve_location("job1","jobs",'.js');
|
21 | assert.equal("jobs/job1/job1.js", location);
|
22 | done();
|
23 | });
|
24 |
|
25 | it('should resolve location of widgets correctly', function(done){
|
26 | var location = item_manager.resolve_location("widget1","widgets",'.js');
|
27 | assert.equal("widgets/widget1/widget1.js", location);
|
28 | done();
|
29 | });
|
30 |
|
31 | });
|
32 |
|
33 | describe ('resolve candidates', function(){
|
34 | it('should resolve namespaced item', function(done){
|
35 | var items =
|
36 | [
|
37 | '/Volumes/SSD/confluence-wallboard/packages/alek-atlassian/widgets/buildoverview/buildoverview.html',
|
38 | '/Volumes/SSD/confluence-wallboard/packages/atlassian/widgets/buildoverview/buildoverview.html'
|
39 | ];
|
40 | var candidates = item_manager.resolve_candidates(items, 'atlassian#buildoverview', 'widgets', '.html');
|
41 | assert.equal(1, candidates.length);
|
42 | assert.equal(items[1], candidates[0]);
|
43 | done();
|
44 | });
|
45 |
|
46 | });
|
47 |
|
48 | describe ('dashboards', function(){
|
49 | it('should have the right number of dashboards', function(done){
|
50 | item_manager.get([packagesLocalFolder, packagesAtlasboardFolder], "dashboards", ".json", function(err, dashboards){
|
51 | assert.ok(!err, err);
|
52 | assert.equal(4, dashboards.length);
|
53 | done();
|
54 | });
|
55 | });
|
56 |
|
57 | it('should not read dashboards with invalid extensions', function(done){
|
58 | item_manager.get([packagesLocalFolder, packagesAtlasboardFolder], "dashboards", ".json", function(err, dashboards){
|
59 | assert.ok(!err, err);
|
60 | dashboards.forEach(function(item){
|
61 | assert.ok(path.extname(item) === ".json");
|
62 | });
|
63 | done();
|
64 | });
|
65 | });
|
66 |
|
67 | it('should not read disabled dashboards', function(done){
|
68 | item_manager.get([packageWithDisabledDashboards], "dashboards", ".json", function(err, dashboards){
|
69 | assert.ok(!err, err);
|
70 | assert.equal(1, dashboards.length);
|
71 | done();
|
72 | });
|
73 | });
|
74 |
|
75 | });
|
76 |
|
77 | describe ('jobs', function(){
|
78 |
|
79 | it('should have the right number of jobs', function(done){
|
80 | item_manager.get([packagesLocalFolder], "jobs", ".js", function(err, jobs){
|
81 | assert.ok(!err, err);
|
82 | assert.equal(6, jobs.length);
|
83 | done();
|
84 | });
|
85 | });
|
86 |
|
87 | it('should return jobs by package', function(done){
|
88 | item_manager.getByPackage([packagesLocalFolder], "jobs", ".js", function(err, packages){
|
89 | assert.ok(!err, err);
|
90 |
|
91 | assert.equal(2, packages.length);
|
92 |
|
93 | assert.equal(packagesLocalFolder + '/default', packages[0].dir);
|
94 | assert.equal(3, packages[0].items.length);
|
95 |
|
96 | assert.equal(packagesLocalFolder + '/otherpackage1', packages[1].dir);
|
97 | assert.equal(3, packages[1].items.length);
|
98 |
|
99 | done();
|
100 | });
|
101 | });
|
102 |
|
103 | it('should ignore wrong directories', function(done){
|
104 | item_manager.getByPackage([packagesLocalFolder, "wrongdirecto/ry"], "jobs", ".js", function(err, packages){
|
105 | assert.ok(!err, err);
|
106 |
|
107 | assert.equal(2, packages.length);
|
108 | done();
|
109 | });
|
110 | });
|
111 |
|
112 | it('should be able to pick up the right job with namespacing (1)', function(done){
|
113 | item_manager.get_first([packagesLocalFolder], "otherpackage1#job1", "jobs", ".js", function(err, job_path){
|
114 | assert.ok(!err, err);
|
115 | assert.ok(job_path);
|
116 | var job = require (job_path);
|
117 | var result = job();
|
118 | assert.equal ("otherpackage1#job1", result);
|
119 | done();
|
120 | });
|
121 | });
|
122 |
|
123 | it('should be able to pick up the right job with namespacing (2)', function(done){
|
124 | item_manager.get_first([packagesLocalFolder], "default#job1", "jobs", ".js", function(err, job_path){
|
125 | assert.ok(!err, err);
|
126 | assert.ok(job_path);
|
127 | var job = require (job_path);
|
128 | var result = job();
|
129 | assert.equal ("default#job1", result);
|
130 | done();
|
131 | });
|
132 | });
|
133 |
|
134 | });
|
135 |
|
136 | describe ('widgets', function(){
|
137 | it('should have the right number of widgets', function(done){
|
138 | item_manager.get([packagesLocalFolder], "widgets", ".js", function(err, widgets){
|
139 | assert.ok(!err, err);
|
140 | assert.equal(1, widgets.length);
|
141 | done();
|
142 | });
|
143 | });
|
144 |
|
145 | it('should be able to pick up the right widget with namespacing', function(done){
|
146 | item_manager.get_first([packagesTestNamespacing], "cccccc#blockers", "widgets", ".html", function(err, widget_path){
|
147 | assert.ok(!err, err);
|
148 | assert.ok(widget_path.indexOf('test/fixtures/package_test_namespacing/cccccc/widgets/blockers/blockers.html') > -1);
|
149 | done();
|
150 | });
|
151 | });
|
152 |
|
153 | });
|
154 |
|
155 | }); |
\ | No newline at end of file |