webogram-i2p/test/unit/ChangelogModalControlelerSpec.js
Bart 5099d14df9 Added test for ChangeLogModalController, AppFooterController and PeerSelectController (#1355)
* Added test for ChangeLogModalController
This commit changes the test scores as follows

|     | % Statements | % Branch | % Functions | % Lines |
|:---:|:------------:|:--------:|-------------|---------|
| Old |      3.5     |     0    | 0.36        | 3.52    |
| New |     4.22     |   0.36   | 1.08        | 4.24    |

* Added tests for AppFooterController
This commit changes the test scores as follows

|     | % Statements | % Branch | % Functions | % Lines |
|:---:|:------------:|:--------:|-------------|---------|
| Old |     4.22     |   0.36   |    1.08     |   4.24  |
| New |     4.29     |   0.36   |    1.44     |   4.31  |

* Added tests for PeerSelectController
This commit changes the test scores as follows

|     | % Statements | % Branch | % Functions | % Lines |
|:---:|:------------:|:--------:|-------------|---------|
| Old |     4.29     |   0.36   |    1.44     |   4.31  |
| New |     5.61     |   1.16   |    2.88     |   5.64  |

* Change Time-out time to variable
Instead of doing time-outs based on a constant, the time-out is based on a variable. This will make changing the time of time-out easier.

* Rename AppFooterController test, removed unnecessary test, fixed code style

Renamed test/unit/AppFooterController.js to test/unit/AppFooterControllerSpec.js to conform with other test files.
Removed a test in the renamed file. It only tested if the controller would compile given the test-environment, something that was implicitly tested in the other (now only) test.
The code style over all test files was not consistent (spacing), this is fixed.

* Changed style to StandardJS

When running "standard test/unit/..", there were some errors on the code-style of the tests
These are fixed
2017-03-13 21:57:11 +03:00

70 lines
2.0 KiB
JavaScript

/* global describe, it, inject, expect, beforeEach, Config */
describe('ChangeLogModalController', function () {
var $controller, $scope, modal, modalFlag
beforeEach(module('myApp.controllers'))
beforeEach(function () {
modalFlag = false
modal = {
open: function (data) {
modalFlag = true
}
}
inject(function (_$controller_, _$rootScope_) {
$controller = _$controller_
$scope = _$rootScope_.$new()
$controller('ChangelogModalController', {
$scope: $scope,
$modal: modal
})
})
})
// define tests
it('will have standard data when no function is called', function (done) {
expect($scope.changelogHidden).toBe(false)
expect($scope.changelogShown).toBe(false)
expect($scope.currentVersion).toBe(Config.App.version)
done()
})
it('will show the changelog', function (done) {
$scope.showAllVersions()
expect($scope.changelogHidden).toBe(false)
expect($scope.changelogShown).toBe(true)
done()
})
it('will allow to show any version when "changelogShown" is true', function (done) {
$scope.changelogShown = true
expect($scope.canShowVersion(null)).toBe(true)
expect($scope.canShowVersion('0.0.1')).toBe(true)
expect($scope.canShowVersion('0.1.0')).toBe(true)
expect($scope.canShowVersion('1.0.0')).toBe(true)
done()
})
it('will allow the version to be shown when the current verion is bigger than the last function', function (done) {
expect($scope.canShowVersion('100.100.100')).toBe(true)
done()
})
it('won\'t allow the version to be shown when it is smaller than the current version', function (done) {
expect($scope.changelogHidden).toBe(false)
expect($scope.canShowVersion('0.0.0')).toBe(false)
expect($scope.changelogHidden).toBe(true)
done()
})
it('will call modal when the changeUsername function is called', function (done) {
expect(modalFlag).toBe(false)
$scope.changeUsername()
expect(modalFlag).toBe(true)
done()
})
})