diff options
author | Stas Vilchik <vilchiks@gmail.com> | 2014-07-11 12:42:14 +0600 |
---|---|---|
committer | Stas Vilchik <vilchiks@gmail.com> | 2014-07-15 12:04:08 +0600 |
commit | 557db7be44ec049f777c7705eace34f2486a93c6 (patch) | |
tree | 4fcb3625dbc47c1b806cbbdefaad74c1e3488fd4 /sonar-server/src | |
parent | fb1f98a971cff6313798b3e00188c109a7c91f5e (diff) | |
download | sonarqube-557db7be44ec049f777c7705eace34f2486a93c6.tar.gz sonarqube-557db7be44ec049f777c7705eace34f2486a93c6.zip |
karma tests
Diffstat (limited to 'sonar-server/src')
8 files changed, 386 insertions, 0 deletions
diff --git a/sonar-server/src/main/coffee/tests/common/inputsSpec.coffee b/sonar-server/src/main/coffee/tests/common/inputsSpec.coffee new file mode 100644 index 00000000000..3cbc6591925 --- /dev/null +++ b/sonar-server/src/main/coffee/tests/common/inputsSpec.coffee @@ -0,0 +1,87 @@ +$ = jQuery + +describe 'WORK_DUR suite', -> + + beforeEach -> + window.SS = {} + window.SS.phrases = + 'work_duration': + 'x_days': '{0}d', 'x_hours': '{0}h', 'x_minutes': '{0}min' + + @input = $('<input type="text">') + @input.appendTo $('body') + @input.data 'type', 'WORK_DUR' + + + it 'converts', -> + @input.originalVal '2d 7h 13min' + expect(@input.val()).toBe 1393 + + it 'converts only days', -> + @input.originalVal '1d' + expect(@input.val()).toBe 480 + + it 'converts hours with minutes', -> + @input.originalVal '2h 30min' + expect(@input.val()).toBe 150 + + it 'converts zero', -> + @input.originalVal '0' + expect(@input.val()).toBe 0 + + + it 'restores', -> + @input.val 1393 + expect(@input.originalVal()).toBe '2d 7h 13min' + + it 'restores zero', -> + @input.val '0' + expect(@input.originalVal()).toBe '0' + + + it 'returns initially incorrect value', -> + @input.val 'something' + expect(@input.val()).toBe 'something' + + +describe 'RATING suite', -> + + beforeEach -> + @input = $('<input type="text">') + @input.appendTo $('body') + @input.data 'type', 'RATING' + + + it 'converts A', -> + @input.originalVal 'A' + expect(@input.val()).toBe 1 + + + it 'converts B', -> + @input.originalVal 'B' + expect(@input.val()).toBe 2 + + + it 'converts E', -> + @input.originalVal 'E' + expect(@input.val()).toBe 5 + + + it 'does not convert F', -> + @input.originalVal 'F' + expect(@input.val()).toBe 'F' + + + it 'restores A', -> + @input.val 1 + expect(@input.originalVal()).toBe 'A' + + + it 'restores E', -> + @input.val 5 + expect(@input.originalVal()).toBe 'E' + + + it 'returns initially incorrect value', -> + @input.val 'something' + expect(@input.val()).toBe 'something' diff --git a/sonar-server/src/main/coffee/tests/component-viewer/baseSpec.coffee b/sonar-server/src/main/coffee/tests/component-viewer/baseSpec.coffee new file mode 100644 index 00000000000..7fd5a4cbe50 --- /dev/null +++ b/sonar-server/src/main/coffee/tests/component-viewer/baseSpec.coffee @@ -0,0 +1,30 @@ +$ = jQuery +window.baseUrl = '' +window.suppressTranslationWarnings = true + + +define [ + 'component-viewer/main' +], ( + ComponentViewer +) -> + + describe 'Component Viewer Base Test Suite', -> + + beforeEach -> + @viewer = new ComponentViewer() + @viewer.render().$el.appendTo $('body') + + + afterEach -> + @viewer.close() + + + it 'attaches to the page', -> + expect($('.component-viewer', 'body').length).toBe 1 + + + it 'has all parts', -> + expect(@viewer.$('.component-viewer-header').length).toBe 1 + expect(@viewer.$('.component-viewer-source').length).toBe 1 + expect(@viewer.$('.component-viewer-workspace').length).toBe 1 diff --git a/sonar-server/src/main/coffee/tests/translateSpec.coffee b/sonar-server/src/main/coffee/tests/translateSpec.coffee new file mode 100644 index 00000000000..7b4576bcfff --- /dev/null +++ b/sonar-server/src/main/coffee/tests/translateSpec.coffee @@ -0,0 +1,75 @@ +$ = jQuery + +describe 'translation "t" suite', -> + + beforeEach -> + window.messages = + 'something': 'SOMETHING' + 'something_with_underscore': 'SOMETHING_WITH_UNDERSCORE' + 'something_with{braces}': 'SOMETHING_WITH{braces}' + + window.SS = + phrases: + 'something': 'SOMETHING ANOTHER' + + + afterEach -> + window.messages = window.SS = undefined + + + it 'translates', -> + expect(t('something')).toBe 'SOMETHING' + + + it 'translates with underscore', -> + expect(t('something_with_underscore')).toBe 'SOMETHING_WITH_UNDERSCORE' + + + it 'translates with braces', -> + expect(t('something_with{braces}')).toBe 'SOMETHING_WITH{braces}' + + + it 'fallbacks to "translate"', -> + window.messages = undefined + expect(t('something')).toBe 'SOMETHING ANOTHER' + + + it 'returns the key when no translation', -> + expect(t('something_another')).toBe 'something_another' + + + +describe 'translation "translate" suite', -> + + beforeEach -> + window.SS = + phrases: + 'something': 'SOMETHING' + 'something_with_underscore': 'SOMETHING_WITH_UNDERSCORE' + 'something_with{braces}': 'SOMETHING_WITH{braces}' + + + afterEach -> + window.messages = window.SS = undefined + + + it 'translates', -> + expect(translate('something')).toBe 'SOMETHING' + + + it 'translates with underscore', -> + expect(translate('something_with_underscore')).toBe 'SOMETHING_WITH_UNDERSCORE' + + + it 'translates with braces', -> + expect(translate('something_with{braces}')).toBe 'SOMETHING_WITH{braces}' + + + it 'returns the key when no translation', -> + expect(translate('something_another')).toBe 'something_another' + + + it 'does not fail when there is no dictionary', -> + window.SS = undefined + expect(translate('something_another')).toBe 'something_another' + diff --git a/sonar-server/src/main/coffee/tests/widgets/BaseSpec.coffee b/sonar-server/src/main/coffee/tests/widgets/BaseSpec.coffee new file mode 100644 index 00000000000..b869aed84d5 --- /dev/null +++ b/sonar-server/src/main/coffee/tests/widgets/BaseSpec.coffee @@ -0,0 +1,47 @@ +$ = jQuery + +describe 'base widget suite', -> + + it 'exists', -> + expect(window.SonarWidgets).toBeDefined() + expect(window.SonarWidgets.BaseWidget).toBeDefined() + + + it 'adds fields', -> + widget = new window.SonarWidgets.BaseWidget() + widget.addField 'fieldName', 1 + + expect(typeof widget.fieldName).toBe 'function' + expect(widget.fieldName()).toBe 1 + + expect(widget.fieldName(2)).toBe widget + expect(widget.fieldName()).toBe 2 + + + it 'adds metrics', -> + widget = new window.SonarWidgets.BaseWidget() + widget.addField 'metrics', 'metricA': { name: 'Metric A', someField: 2 } + widget.addField 'metricsPriority', ['metricA'] + widget.addMetric 'myMetric', 0 + + expect(widget.myMetric).toBeDefined() + expect(widget.myMetric.key).toBe 'metricA' + expect(widget.myMetric.name).toBe 'Metric A' + expect(widget.myMetric.someField).toBe 2 + expect(typeof widget.myMetric.value).toBe 'function' + expect(typeof widget.myMetric.formattedValue).toBe 'function' + + + it 'has default properties', -> + widget = new window.SonarWidgets.BaseWidget() + + expect(widget.components).toBeDefined() + expect(widget.metrics).toBeDefined() + expect(widget.metricsPriority).toBeDefined() + expect(widget.options).toBeDefined() + + + it 'created "translate" string', -> + widget = new window.SonarWidgets.BaseWidget() + + expect(widget.trans(1, 2)).toBe 'translate(1,2)' diff --git a/sonar-server/src/main/coffee/tests/widgets/treemapSpec.coffee b/sonar-server/src/main/coffee/tests/widgets/treemapSpec.coffee new file mode 100644 index 00000000000..4f1ddcfd20a --- /dev/null +++ b/sonar-server/src/main/coffee/tests/widgets/treemapSpec.coffee @@ -0,0 +1,49 @@ +$ = jQuery + +METRICS = + ncloc: + name: 'Lines of code' + coverage: + name: 'Coverage' + direction: -1 + +METRICS_PRIORITY = ['coverage', 'ncloc'] + +COMPONENTS = [ + { key: 'some-key-1', name: 'Some Name 1', longName: 'Some Long Name 1', qualifier: 'TRK', measures } +] + + + +describe 'treemap widget suite', -> + + uid = 1 + + render = (treemap, components = COMPONENTS, metrics = METRICS, metricsPriority = METRICS_PRIORITY) -> + elementId = 'treemap-' + ++uid + $("<div id='#{elementId}'></div>").appendTo 'body' + treemap.metrics(metrics).metricsPriority(metricsPriority).components(components).options( + heightInPercents: 55 + maxItems: 10 + maxItemsReachedMessage: '' + baseUrl: '' + noData: '' + ).render('#' + elementId); + + + close = -> + elementId = 'treemap-' + uid + $('#' + elementId).delete() + + + beforeEach -> + @treemap = new window.SonarWidgets.Treemap() + + + afterEach -> + @treemap = undefined + close() + + + it 'renders', -> + render @treemap diff --git a/sonar-server/src/main/js/tests/main.js b/sonar-server/src/main/js/tests/main.js new file mode 100644 index 00000000000..eb95545cb5b --- /dev/null +++ b/sonar-server/src/main/js/tests/main.js @@ -0,0 +1,44 @@ +window.__karma__.loaded = function() {}; + +var tests = []; +for (var file in window.__karma__.files) { + if (window.__karma__.files.hasOwnProperty(file)) { + if (/Spec\.js$/.test(file)) { + tests.push(file); + } + } +} + +requirejs.config({ + baseUrl: '/base', + + paths: { + 'backbone': 'third-party/backbone', + 'backbone.marionette': 'third-party/backbone.marionette', + 'handlebars': 'third-party/handlebars', + 'moment': 'third-party/moment' + }, + + shim: { + 'backbone.marionette': { + deps: ['backbone'], + exports: 'Marionette' + }, + 'backbone': { + exports: 'Backbone' + }, + 'handlebars': { + exports: 'Handlebars' + }, + 'moment': { + exports: 'moment' + } + }, + + // ask Require.js to load these files (all our tests) + deps: tests, + + // start test run, once Require.js is done + callback: window.__karma__.start + +}); diff --git a/sonar-server/src/main/js/tests/navigator/filters/BaseFilterViewSpec.js b/sonar-server/src/main/js/tests/navigator/filters/BaseFilterViewSpec.js new file mode 100644 index 00000000000..b1a0ab15c4f --- /dev/null +++ b/sonar-server/src/main/js/tests/navigator/filters/BaseFilterViewSpec.js @@ -0,0 +1,15 @@ +define(['navigator/filters/base-filters'], function(BaseFilters) { + + describe('BaseFilterView', function() { + + it('initializes', function() { + var baseFilterView = new BaseFilters.BaseFilterView({ + model: new BaseFilters.Filter() + }); + expect(baseFilterView.detailsView).toBeDefined(); + expect(baseFilterView.detailsView.options.filterView).toBe(baseFilterView); + }); + + }); + +}); diff --git a/sonar-server/src/main/js/tests/navigator/filters/ChoiceFilterViewSpec.js b/sonar-server/src/main/js/tests/navigator/filters/ChoiceFilterViewSpec.js new file mode 100644 index 00000000000..3b905a9f88f --- /dev/null +++ b/sonar-server/src/main/js/tests/navigator/filters/ChoiceFilterViewSpec.js @@ -0,0 +1,39 @@ +define(['navigator/filters/base-filters', 'navigator/filters/choice-filters'], function(BaseFilters, ChoiceFilters) { + + describe('BaseFilterView', function() { + var choices, choiceFilter, choiceFilterView; + + beforeEach(function() { + choices = { + 'ONE': 'one', + 'TWO': 'two', + 'THREE': 'three', + '!OPPOSITE': 'opposite' + }; + + choiceFilter = new BaseFilters.Filter({ + name: 'Choice Filter Name', + property: 'choiceFilterProperty', + type: ChoiceFilters.ChoiceFilterView, + enabled: true, + optional: false, + choices: choices + }); + + choiceFilterView = new ChoiceFilters.ChoiceFilterView({ + model: choiceFilter + }); + }); + + it('creates choices', function() { + expect(choiceFilterView.choices).toBeDefined(); + expect(choiceFilterView.choices.length).toBe(Object.keys(choices).length); + }); + + it('does not have selected by default', function() { + expect(choiceFilterView.getSelected().length).toBe(0); + }); + + }); + +}); |