diff options
author | Stas Vilchik <vilchiks@gmail.com> | 2016-09-02 16:13:51 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-09-02 16:13:51 +0200 |
commit | 5fac9ad9ac653dba89f5f53457c8d17959cef7cc (patch) | |
tree | 8f1516f14adaaa1ffc421b50737b33a887d29f75 /server/sonar-web/src/main/js/components/__tests__ | |
parent | e71ab396b44b4a4f6e03edcba97564b27de6efa9 (diff) | |
download | sonarqube-5fac9ad9ac653dba89f5f53457c8d17959cef7cc.tar.gz sonarqube-5fac9ad9ac653dba89f5f53457c8d17959cef7cc.zip |
use jest (#1202)
Diffstat (limited to 'server/sonar-web/src/main/js/components/__tests__')
-rw-r--r-- | server/sonar-web/src/main/js/components/__tests__/issue-test.js | 270 | ||||
-rw-r--r-- | server/sonar-web/src/main/js/components/__tests__/source-viewer-test.js | 152 |
2 files changed, 205 insertions, 217 deletions
diff --git a/server/sonar-web/src/main/js/components/__tests__/issue-test.js b/server/sonar-web/src/main/js/components/__tests__/issue-test.js index 75d4e89f119..66f124afaf1 100644 --- a/server/sonar-web/src/main/js/components/__tests__/issue-test.js +++ b/server/sonar-web/src/main/js/components/__tests__/issue-test.js @@ -17,175 +17,167 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -import chai, { expect } from 'chai'; -import sinon from 'sinon'; -import sinonChai from 'sinon-chai'; - import Issue from '../issue/models/issue'; -chai.use(sinonChai); - -describe('Issue', function () { - describe('Model', function () { - it('should have correct urlRoot', function () { - const issue = new Issue(); - expect(issue.urlRoot()).to.equal('/api/issues'); - }); +describe('Model', function () { + it('should have correct urlRoot', function () { + const issue = new Issue(); + expect(issue.urlRoot()).toBe('/api/issues'); + }); - it('should parse response without root issue object', function () { - const issue = new Issue(); - const example = { a: 1 }; - expect(issue.parse(example)).to.deep.equal(example); - }); + it('should parse response without root issue object', function () { + const issue = new Issue(); + const example = { a: 1 }; + expect(issue.parse(example)).toEqual(example); + }); - it('should parse response with the root issue object', function () { - const issue = new Issue(); - const example = { a: 1 }; - expect(issue.parse({ issue: example })).to.deep.equal(example); - }); + it('should parse response with the root issue object', function () { + const issue = new Issue(); + const example = { a: 1 }; + expect(issue.parse({ issue: example })).toEqual(example); + }); - it('should reset attributes (no attributes initially)', function () { - const issue = new Issue(); - const example = { a: 1 }; - issue.reset(example); - expect(issue.toJSON()).to.deep.equal(example); - }); + it('should reset attributes (no attributes initially)', function () { + const issue = new Issue(); + const example = { a: 1 }; + issue.reset(example); + expect(issue.toJSON()).toEqual(example); + }); - it('should reset attributes (override attribute)', function () { - const issue = new Issue({ a: 2 }); - const example = { a: 1 }; - issue.reset(example); - expect(issue.toJSON()).to.deep.equal(example); - }); + it('should reset attributes (override attribute)', function () { + const issue = new Issue({ a: 2 }); + const example = { a: 1 }; + issue.reset(example); + expect(issue.toJSON()).toEqual(example); + }); - it('should reset attributes (different attributes)', function () { - const issue = new Issue({ a: 2 }); - const example = { b: 1 }; - issue.reset(example); - expect(issue.toJSON()).to.deep.equal(example); - }); + it('should reset attributes (different attributes)', function () { + const issue = new Issue({ a: 2 }); + const example = { b: 1 }; + issue.reset(example); + expect(issue.toJSON()).toEqual(example); + }); - it('should unset `textRange` of a closed issue', function () { - const issue = new Issue(); - const result = issue.parse({ issue: { status: 'CLOSED', textRange: { startLine: 5 } } }); - expect(result.textRange).to.not.be.ok; - }); + it('should unset `textRange` of a closed issue', function () { + const issue = new Issue(); + const result = issue.parse({ issue: { status: 'CLOSED', textRange: { startLine: 5 } } }); + expect(result.textRange).toBeFalsy(); + }); - it('should unset `flows` of a closed issue', function () { - const issue = new Issue(); - const result = issue.parse({ issue: { status: 'CLOSED', flows: [1, 2, 3] } }); - expect(result.flows).to.deep.equal([]); - }); + it('should unset `flows` of a closed issue', function () { + const issue = new Issue(); + const result = issue.parse({ issue: { status: 'CLOSED', flows: [1, 2, 3] } }); + expect(result.flows).toEqual([]); + }); - describe('Actions', function () { - it('should assign', function () { - const issue = new Issue({ key: 'issue-key' }); - const spy = sinon.spy(); - issue._action = spy; - issue.assign('admin'); - expect(spy).to.have.been.calledWith({ - data: { assignee: 'admin', issue: 'issue-key' }, - url: '/api/issues/assign' - }); + describe('Actions', function () { + it('should assign', function () { + const issue = new Issue({ key: 'issue-key' }); + const spy = jest.fn(); + issue._action = spy; + issue.assign('admin'); + expect(spy).toBeCalledWith({ + data: { assignee: 'admin', issue: 'issue-key' }, + url: '/api/issues/assign' }); + }); - it('should unassign', function () { - const issue = new Issue({ key: 'issue-key' }); - const spy = sinon.spy(); - issue._action = spy; - issue.assign(); - expect(spy).to.have.been.calledWith({ - data: { assignee: undefined, issue: 'issue-key' }, - url: '/api/issues/assign' - }); + it('should unassign', function () { + const issue = new Issue({ key: 'issue-key' }); + const spy = jest.fn(); + issue._action = spy; + issue.assign(); + expect(spy).toBeCalledWith({ + data: { assignee: undefined, issue: 'issue-key' }, + url: '/api/issues/assign' }); + }); - it('should plan', function () { - const issue = new Issue({ key: 'issue-key' }); - const spy = sinon.spy(); - issue._action = spy; - issue.plan('plan'); - expect(spy).to.have.been.calledWith({ data: { plan: 'plan', issue: 'issue-key' }, url: '/api/issues/plan' }); - }); + it('should plan', function () { + const issue = new Issue({ key: 'issue-key' }); + const spy = jest.fn(); + issue._action = spy; + issue.plan('plan'); + expect(spy).toBeCalledWith({ data: { plan: 'plan', issue: 'issue-key' }, url: '/api/issues/plan' }); + }); - it('should unplan', function () { - const issue = new Issue({ key: 'issue-key' }); - const spy = sinon.spy(); - issue._action = spy; - issue.plan(); - expect(spy).to.have.been.calledWith({ data: { plan: undefined, issue: 'issue-key' }, url: '/api/issues/plan' }); - }); + it('should unplan', function () { + const issue = new Issue({ key: 'issue-key' }); + const spy = jest.fn(); + issue._action = spy; + issue.plan(); + expect(spy).toBeCalledWith({ data: { plan: undefined, issue: 'issue-key' }, url: '/api/issues/plan' }); + }); - it('should set severity', function () { - const issue = new Issue({ key: 'issue-key' }); - const spy = sinon.spy(); - issue._action = spy; - issue.setSeverity('BLOCKER'); - expect(spy).to.have.been.calledWith({ - data: { severity: 'BLOCKER', issue: 'issue-key' }, - url: '/api/issues/set_severity' - }); + it('should set severity', function () { + const issue = new Issue({ key: 'issue-key' }); + const spy = jest.fn(); + issue._action = spy; + issue.setSeverity('BLOCKER'); + expect(spy).toBeCalledWith({ + data: { severity: 'BLOCKER', issue: 'issue-key' }, + url: '/api/issues/set_severity' }); }); + }); - describe('#getLinearLocations', function () { - it('should return single line location', function () { - const issue = new Issue({ textRange: { startLine: 1, endLine: 1, startOffset: 0, endOffset: 10 } }); - const locations = issue.getLinearLocations(); - expect(locations.length).to.equal(1); + describe('#getLinearLocations', function () { + it('should return single line location', function () { + const issue = new Issue({ textRange: { startLine: 1, endLine: 1, startOffset: 0, endOffset: 10 } }); + const locations = issue.getLinearLocations(); + expect(locations.length).toBe(1); - expect(locations[0].line).to.equal(1); - expect(locations[0].from).to.equal(0); - expect(locations[0].to).to.equal(10); - }); + expect(locations[0].line).toBe(1); + expect(locations[0].from).toBe(0); + expect(locations[0].to).toBe(10); + }); - it('should return location not from 0', function () { - const issue = new Issue({ textRange: { startLine: 1, endLine: 1, startOffset: 5, endOffset: 10 } }); - const locations = issue.getLinearLocations(); - expect(locations.length).to.equal(1); + it('should return location not from 0', function () { + const issue = new Issue({ textRange: { startLine: 1, endLine: 1, startOffset: 5, endOffset: 10 } }); + const locations = issue.getLinearLocations(); + expect(locations.length).toBe(1); - expect(locations[0].line).to.equal(1); - expect(locations[0].from).to.equal(5); - expect(locations[0].to).to.equal(10); - }); + expect(locations[0].line).toBe(1); + expect(locations[0].from).toBe(5); + expect(locations[0].to).toBe(10); + }); - it('should return 2-lines location', function () { - const issue = new Issue({ textRange: { startLine: 2, endLine: 3, startOffset: 5, endOffset: 10 } }); - const locations = issue.getLinearLocations(); - expect(locations.length).to.equal(2); + it('should return 2-lines location', function () { + const issue = new Issue({ textRange: { startLine: 2, endLine: 3, startOffset: 5, endOffset: 10 } }); + const locations = issue.getLinearLocations(); + expect(locations.length).toBe(2); - expect(locations[0].line).to.equal(2); - expect(locations[0].from).to.equal(5); - expect(locations[0].to).to.equal(999999); + expect(locations[0].line).toBe(2); + expect(locations[0].from).toBe(5); + expect(locations[0].to).toBe(999999); - expect(locations[1].line).to.equal(3); - expect(locations[1].from).to.equal(0); - expect(locations[1].to).to.equal(10); - }); + expect(locations[1].line).toBe(3); + expect(locations[1].from).toBe(0); + expect(locations[1].to).toBe(10); + }); - it('should return 3-lines location', function () { - const issue = new Issue({ textRange: { startLine: 4, endLine: 6, startOffset: 5, endOffset: 10 } }); - const locations = issue.getLinearLocations(); - expect(locations.length).to.equal(3); + it('should return 3-lines location', function () { + const issue = new Issue({ textRange: { startLine: 4, endLine: 6, startOffset: 5, endOffset: 10 } }); + const locations = issue.getLinearLocations(); + expect(locations.length).toBe(3); - expect(locations[0].line).to.equal(4); - expect(locations[0].from).to.equal(5); - expect(locations[0].to).to.equal(999999); + expect(locations[0].line).toBe(4); + expect(locations[0].from).toBe(5); + expect(locations[0].to).toBe(999999); - expect(locations[1].line).to.equal(5); - expect(locations[1].from).to.equal(0); - expect(locations[1].to).to.equal(999999); + expect(locations[1].line).toBe(5); + expect(locations[1].from).toBe(0); + expect(locations[1].to).toBe(999999); - expect(locations[2].line).to.equal(6); - expect(locations[2].from).to.equal(0); - expect(locations[2].to).to.equal(10); - }); + expect(locations[2].line).toBe(6); + expect(locations[2].from).toBe(0); + expect(locations[2].to).toBe(10); + }); - it('should return [] when no location', function () { - const issue = new Issue(); - const locations = issue.getLinearLocations(); - expect(locations.length).to.equal(0); - }); + it('should return [] when no location', function () { + const issue = new Issue(); + const locations = issue.getLinearLocations(); + expect(locations.length).toBe(0); }); }); }); diff --git a/server/sonar-web/src/main/js/components/__tests__/source-viewer-test.js b/server/sonar-web/src/main/js/components/__tests__/source-viewer-test.js index 99ce9b0d700..5d27c5ad0b1 100644 --- a/server/sonar-web/src/main/js/components/__tests__/source-viewer-test.js +++ b/server/sonar-web/src/main/js/components/__tests__/source-viewer-test.js @@ -17,93 +17,89 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -import { expect } from 'chai'; - import helper from '../source-viewer/helpers/code-with-issue-locations-helper'; -describe('Source Viewer', function () { - describe('Code With Issue Locations Helper', function () { - it('should be a function', function () { - expect(helper).to.be.a('function'); - }); +describe('Code With Issue Locations Helper', function () { + it('should be a function', function () { + expect(helper).toBeTruthy(); + }); - it('should mark one location', function () { - const code = '<span class="k">if</span> (<span class="sym-2 sym">a</span> + <span class="c">1</span>) {'; - const locations = [{ from: 1, to: 5 }]; - const result = helper(code, locations, 'x'); - expect(result).to.equal([ - '<span class="k">i</span>', - '<span class="k x">f</span>', - '<span class=" x"> (</span>', - '<span class="sym-2 sym x">a</span>', - '<span class=""> + </span>', - '<span class="c">1</span>', - '<span class="">) {</span>' - ].join('')); - }); + it('should mark one location', function () { + const code = '<span class="k">if</span> (<span class="sym-2 sym">a</span> + <span class="c">1</span>) {'; + const locations = [{ from: 1, to: 5 }]; + const result = helper(code, locations, 'x'); + expect(result).toBe([ + '<span class="k">i</span>', + '<span class="k x">f</span>', + '<span class=" x"> (</span>', + '<span class="sym-2 sym x">a</span>', + '<span class=""> + </span>', + '<span class="c">1</span>', + '<span class="">) {</span>' + ].join('')); + }); - it('should mark two locations', function () { - const code = 'abcdefghijklmnopqrst'; - const locations = [ - { from: 1, to: 6 }, - { from: 11, to: 16 } - ]; - const result = helper(code, locations, 'x'); - expect(result).to.equal([ - '<span class="">a</span>', - '<span class=" x">bcdef</span>', - '<span class="">ghijk</span>', - '<span class=" x">lmnop</span>', - '<span class="">qrst</span>' - ].join('')); - }); + it('should mark two locations', function () { + const code = 'abcdefghijklmnopqrst'; + const locations = [ + { from: 1, to: 6 }, + { from: 11, to: 16 } + ]; + const result = helper(code, locations, 'x'); + expect(result).toBe([ + '<span class="">a</span>', + '<span class=" x">bcdef</span>', + '<span class="">ghijk</span>', + '<span class=" x">lmnop</span>', + '<span class="">qrst</span>' + ].join('')); + }); - it('should mark one locations', function () { - const code = '<span class="cppd"> * Copyright (C) 2008-2014 SonarSource</span>'; - const locations = [{ from: 15, to: 20 }]; - const result = helper(code, locations, 'x'); - expect(result).to.equal([ - '<span class="cppd"> * Copyright (C</span>', - '<span class="cppd x">) 200</span>', - '<span class="cppd">8-2014 SonarSource</span>' - ].join('')); - }); + it('should mark one locations', function () { + const code = '<span class="cppd"> * Copyright (C) 2008-2014 SonarSource</span>'; + const locations = [{ from: 15, to: 20 }]; + const result = helper(code, locations, 'x'); + expect(result).toBe([ + '<span class="cppd"> * Copyright (C</span>', + '<span class="cppd x">) 200</span>', + '<span class="cppd">8-2014 SonarSource</span>' + ].join('')); + }); - it('should mark two locations', function () { - const code = '<span class="cppd"> * Copyright (C) 2008-2014 SonarSource</span>'; - const locations = [ - { from: 24, to: 29 }, - { from: 15, to: 20 } - ]; - const result = helper(code, locations, 'x'); - expect(result).to.equal([ - '<span class="cppd"> * Copyright (C</span>', - '<span class="cppd x">) 200</span>', - '<span class="cppd">8-20</span>', - '<span class="cppd x">14 So</span>', - '<span class="cppd">narSource</span>' - ].join('')); - }); + it('should mark two locations', function () { + const code = '<span class="cppd"> * Copyright (C) 2008-2014 SonarSource</span>'; + const locations = [ + { from: 24, to: 29 }, + { from: 15, to: 20 } + ]; + const result = helper(code, locations, 'x'); + expect(result).toBe([ + '<span class="cppd"> * Copyright (C</span>', + '<span class="cppd x">) 200</span>', + '<span class="cppd">8-20</span>', + '<span class="cppd x">14 So</span>', + '<span class="cppd">narSource</span>' + ].join('')); + }); - it('should parse line with < and >', function () { - const code = '<span class="j">#include <stdio.h></span>'; - const result = helper(code, []); - expect(result).to.equal('<span class="j">#include <stdio.h></span>'); - }); + it('should parse line with < and >', function () { + const code = '<span class="j">#include <stdio.h></span>'; + const result = helper(code, []); + expect(result).toBe('<span class="j">#include <stdio.h></span>'); + }); - it('should parse syntax and usage highlighting', function () { - const code = '<span class="k"><span class="sym-3 sym">this</span></span>'; - const expected = '<span class="k sym-3 sym">this</span>'; - const result = helper(code, []); - expect(result).to.equal(expected); - }); + it('should parse syntax and usage highlighting', function () { + const code = '<span class="k"><span class="sym-3 sym">this</span></span>'; + const expected = '<span class="k sym-3 sym">this</span>'; + const result = helper(code, []); + expect(result).toBe(expected); + }); - it('should parse nested tags', function () { - const code = '<span class="k"><span class="sym-3 sym">this</span> is</span>'; - const expected = '<span class="k sym-3 sym">this</span><span class="k"> is</span>'; - const result = helper(code, []); - expect(result).to.equal(expected); - }); + it('should parse nested tags', function () { + const code = '<span class="k"><span class="sym-3 sym">this</span> is</span>'; + const expected = '<span class="k sym-3 sym">this</span><span class="k"> is</span>'; + const result = helper(code, []); + expect(result).toBe(expected); }); }); |