]> source.dussan.org Git - sonarqube.git/commitdiff
add issue web tests
authorStas Vilchik <vilchiks@gmail.com>
Tue, 30 Jun 2015 16:20:38 +0000 (18:20 +0200)
committerStas Vilchik <vilchiks@gmail.com>
Tue, 30 Jun 2015 16:34:13 +0000 (18:34 +0200)
server/sonar-web/package.json
server/sonar-web/test/intern-browser.js
server/sonar-web/test/intern.js
server/sonar-web/test/unit/issue.spec.js [new file with mode: 0644]

index f82f544b835bf726f13ff2519449c1d40e365bd8..44d05adaeac366e367f2d4c07e4731e781df95df 100644 (file)
@@ -17,6 +17,7 @@
     "grunt-text-replace": "0.4.0",
     "intern": "^3.0.0-rc.1",
     "jit-grunt": "0.9.1",
+    "sinon": "^1.15.4",
     "time-grunt": "1.2.1"
   },
   "scripts": {
index eb1465020d02380a6abfe2d420b852771b0276dd..a7ace36b0e6e3e613162f5822c90f707cc13011d 100644 (file)
@@ -5,7 +5,8 @@ define({
   defaultTimeout: 60 * 1000,
 
   suites: [
-    'test/unit/application.spec'
+    'test/unit/application.spec',
+    'test/unit/issue.spec'
   ],
 
   tunnel: 'NullTunnel',
index 984906c4ea9c328fae2a3ef3d816652f7ba7a9ed..17cab286e7d9ae4326b402e888611ce39d56f622 100644 (file)
@@ -15,7 +15,8 @@ define(['intern'], function (intern) {
     ],
 
     suites: [
-      'test/unit/application.spec'
+      'test/unit/application.spec',
+      'test/unit/issue.spec'
     ],
 
     functionalSuites: [
diff --git a/server/sonar-web/test/unit/issue.spec.js b/server/sonar-web/test/unit/issue.spec.js
new file mode 100644 (file)
index 0000000..a9f61a7
--- /dev/null
@@ -0,0 +1,114 @@
+define(function (require) {
+  var bdd = require('intern!bdd');
+  var assert = require('intern/chai!assert');
+
+  require('intern/order!build/js/libs/translate.js');
+  require('intern/order!build/js/libs/third-party/jquery.js');
+  require('intern/order!build/js/libs/third-party/underscore.js');
+  require('intern/order!build/js/libs/third-party/backbone.js');
+  require('intern/order!build/js/libs/third-party/keymaster.js');
+  require('intern/order!build/js/libs/third-party/numeral.js');
+  require('intern/order!build/js/libs/third-party/numeral-languages.js');
+  require('intern/order!build/js/libs/application.js');
+  require('intern/order!node_modules/sinon/pkg/sinon');
+
+  var Issue = require('build/js/components/issue/models/issue');
+
+  bdd.describe('Issue', function () {
+    bdd.before(function () {
+      window.baseUrl = '';
+    });
+
+    bdd.it('should have correct urlRoot', function () {
+      var issue = new Issue();
+      assert.equal(issue.urlRoot(), '/api/issues');
+    });
+
+    bdd.it('should parse response without root issue object', function () {
+      var issue = new Issue();
+      var example = { a: 1 };
+      assert.deepEqual(issue.parse(example), example);
+    });
+
+    bdd.it('should parse response with the root issue object', function () {
+      var issue = new Issue();
+      var example = { a: 1 };
+      assert.deepEqual(issue.parse({ issue: example }), example);
+    });
+
+    bdd.it('should reset attributes (no attributes initially)', function () {
+      var issue = new Issue();
+      var example = { a: 1 };
+      issue.reset(example);
+      assert.deepEqual(issue.toJSON(), example);
+    });
+
+    bdd.it('should reset attributes (override attribute)', function () {
+      var issue = new Issue({ a: 2 });
+      var example = { a: 1 };
+      issue.reset(example);
+      assert.deepEqual(issue.toJSON(), example);
+    });
+
+    bdd.it('should reset attributes (different attributes)', function () {
+      var issue = new Issue({ a: 2 });
+      var example = { b: 1 };
+      issue.reset(example);
+      assert.deepEqual(issue.toJSON(), example);
+    });
+
+    bdd.describe('Actions', function () {
+      var stub;
+
+      bdd.beforeEach(function () {
+        stub = sinon.stub(jQuery, 'ajax');
+      });
+
+      bdd.afterEach(function () {
+        jQuery.ajax.restore();
+      });
+
+      bdd.it('should assign', function () {
+        new Issue({ key: 'issue-key' }).assign('admin');
+        assert.isTrue(stub.calledOnce);
+        assert.equal(stub.firstCall.args[0].url, '/api/issues/assign');
+        assert.deepEqual(stub.firstCall.args[0].data, { issue: 'issue-key', assignee: 'admin' });
+      });
+
+      bdd.it('should unassign', function () {
+        new Issue({ key: 'issue-key' }).assign();
+        assert.isTrue(stub.calledOnce);
+        assert.equal(stub.firstCall.args[0].url, '/api/issues/assign');
+        assert.deepEqual(stub.firstCall.args[0].data, { issue: 'issue-key', assignee: undefined });
+      });
+
+      bdd.it('should plan', function () {
+        new Issue({ key: 'issue-key' }).plan('plan');
+        assert.isTrue(stub.calledOnce);
+        assert.equal(stub.firstCall.args[0].url, '/api/issues/plan');
+        assert.deepEqual(stub.firstCall.args[0].data, { issue: 'issue-key', plan: 'plan' });
+      });
+
+      bdd.it('should unplan', function () {
+        new Issue({ key: 'issue-key' }).plan();
+        assert.isTrue(stub.calledOnce);
+        assert.equal(stub.firstCall.args[0].url, '/api/issues/plan');
+        assert.deepEqual(stub.firstCall.args[0].data, { issue: 'issue-key', plan: undefined });
+      });
+
+      bdd.it('should set severity', function () {
+        new Issue({ key: 'issue-key' }).setSeverity('BLOCKER');
+        assert.isTrue(stub.calledOnce);
+        assert.equal(stub.firstCall.args[0].url, '/api/issues/set_severity');
+        assert.deepEqual(stub.firstCall.args[0].data, { issue: 'issue-key', severity: 'BLOCKER' });
+      });
+
+      bdd.it('should do a transition', function () {
+        new Issue({ key: 'issue-key' }).transition('RESOLVED');
+        assert.isTrue(stub.calledOnce);
+        assert.equal(stub.firstCall.args[0].url, '/api/issues/do_transition');
+        assert.deepEqual(stub.firstCall.args[0].data, { issue: 'issue-key', transition: 'RESOLVED' });
+      });
+    });
+  });
+});