Commit 25cbbb33e3166fc110d1324d23a6eda815fc6bbf
Committed by
Daniel
1 parent
4e9c082c
Exists in
colab
and in
4 other branches
Create JS unit test for choose_metric
This test is necessary in order to provide proper coverage that allows a refactor. Signed off by: Diego Araújo <diegoamc90@gmail.com>
Showing
1 changed file
with
30 additions
and
0 deletions
Show diff stats
| ... | ... | @@ -0,0 +1,30 @@ |
| 1 | +#= require spec_helper | |
| 2 | +#= require metric_collector | |
| 3 | + | |
| 4 | +describe "MetricCollector", -> | |
| 5 | + describe 'choose_metric', -> | |
| 6 | + before -> | |
| 7 | + sinon.stub(window, "$") | |
| 8 | + | |
| 9 | + @metric_code = 'acc' | |
| 10 | + @metric_code_field = sinon.stub() | |
| 11 | + @metric_code_field.val = sinon.stub().withArgs(@metric_code) | |
| 12 | + | |
| 13 | + @metric_collector_name = 'Analizo' | |
| 14 | + @metric_collector_name_field = sinon.stub() | |
| 15 | + @metric_collector_name_field.val = sinon.stub().withArgs(@metric_collector_name) | |
| 16 | + | |
| 17 | + @form = sinon.stub() | |
| 18 | + @form.submit = sinon.stub() | |
| 19 | + | |
| 20 | + $.withArgs("#metric_code").returns(@metric_code_field) | |
| 21 | + $.withArgs("#metric_collector_name").returns(@metric_collector_name_field) | |
| 22 | + $.withArgs("form").returns(@form) | |
| 23 | + | |
| 24 | + it 'is expected to fill in the form and submit', -> | |
| 25 | + MetricCollector.choose_metric(@metric_code, @metric_collector_name) | |
| 26 | + | |
| 27 | + sinon.assert.calledOnce(@metric_code_field.val, @metric_code) | |
| 28 | + sinon.assert.calledOnce(@metric_collector_name_field.val, @metric_collector_name) | |
| 29 | + sinon.assert.calledOnce(@form.submit) | |
| 30 | + | ... | ... |