Igor Zhukov 7 years ago
parent
commit
db1dcadae6
  1. 18
      app/js/controllers.js
  2. 2
      app/vendor/README.md
  3. 24
      test/unit/controllers/AppFooterControllerSpec.js
  4. 10
      test/unit/controllers/AppImPanelControllerSpec.js
  5. 23
      test/unit/controllers/AppLangSelectControllerSpec.js
  6. 37
      test/unit/controllers/AppWelcomeControllerSpec.js
  7. 55
      test/unit/controllers/ChangelogModalControlelerSpec.js
  8. 181
      test/unit/controllers/CountrySelectModalControllerSpec.js
  9. 145
      test/unit/controllers/DocumentModalControllerSpec.js
  10. 74
      test/unit/controllers/EmbedModalController.js
  11. 160
      test/unit/controllers/ImportContactModalControllerSpec.js
  12. 113
      test/unit/controllers/PasswordRecoveryModalControllerSpec.js
  13. 305
      test/unit/controllers/PeerSelectControllerSpec.js
  14. 108
      test/unit/controllers/ProfileEditModalControllerSpec.js
  15. 146
      test/unit/controllers/UsernameEditModalControllerSpec.js
  16. 152
      test/unit/controllers/VideoModalControllerSpec.js
  17. 14
      test/unit/directives/myHeadDirective.js
  18. 14
      test/unit/directives/myLangFooterDirective.js
  19. 20
      test/unit/services/PhonebookContactsServiceSpec.js

18
app/js/controllers.js

@ -3537,7 +3537,7 @@ angular.module('myApp.controllers', ['myApp.i18n']) @@ -3537,7 +3537,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
}
$scope.$on('history_delete', function (e, historyUpdate) {
if (historyUpdate.msgs[$scope.messageID]) {
if (historyUpdate && historyUpdate.msgs && historyUpdate.msgs[$scope.messageID]) {
$modalInstance.dismiss()
}
})
@ -3571,7 +3571,7 @@ angular.module('myApp.controllers', ['myApp.i18n']) @@ -3571,7 +3571,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
}
$scope.$on('history_delete', function (e, historyUpdate) {
if (historyUpdate.msgs[$scope.messageID]) {
if (historyUpdate && historyUpdate.msgs && historyUpdate.msgs[$scope.messageID]) {
$modalInstance.dismiss()
}
})
@ -4455,9 +4455,11 @@ angular.module('myApp.controllers', ['myApp.i18n']) @@ -4455,9 +4455,11 @@ angular.module('myApp.controllers', ['myApp.i18n'])
AppUsersManager.saveApiUser(user)
$modalInstance.close()
}, function (error) {
if (error.type == 'USERNAME_NOT_MODIFIED') {
error.handled = true
$modalInstance.close()
switch (error.type) {
case 'USERNAME_NOT_MODIFIED':
error.handled = true
$modalInstance.close()
break
}
})['finally'](function () {
delete $scope.profile.updating
@ -4470,9 +4472,9 @@ angular.module('myApp.controllers', ['myApp.i18n']) @@ -4470,9 +4472,9 @@ angular.module('myApp.controllers', ['myApp.i18n'])
return
}
MtpApiManager.invokeApi('account.checkUsername', {
username: newVal || ''
username: newVal
}).then(function (valid) {
if ($scope.profile.username != newVal) {
if ($scope.profile.username !== newVal) {
return
}
if (valid) {
@ -4481,7 +4483,7 @@ angular.module('myApp.controllers', ['myApp.i18n']) @@ -4481,7 +4483,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
$scope.checked = {error: true}
}
}, function (error) {
if ($scope.profile.username != newVal) {
if ($scope.profile.username !== newVal) {
return
}
switch (error.type) {

2
app/vendor/README.md vendored

@ -46,7 +46,7 @@ Normalize, CSS-framework @@ -46,7 +46,7 @@ Normalize, CSS-framework
### [nanoScrollerJS](https://github.com/jamesflorentino/nanoScrollerJS)
**Author**: James Florentino
**License**: MIT, https://github.com/jamesflorentino/nanoScrollerJS/blob/master/LICENSE-MIT
**License**: MIT, https://github.com/jamesflorentino/nanoScrollerJS/blob/master/LICENSE
Beautiful OS X Lion-like scrollbars

24
test/unit/controllers/AppFooterControllerSpec.js

@ -2,34 +2,32 @@ @@ -2,34 +2,32 @@
/* global describe, it, inject, expect, beforeEach */
describe('AppFooterController', function () {
var $controller, $scope, service, serviceFlag
beforeEach(module('myApp.controllers'))
beforeEach(function () {
serviceFlag = false
service = {
this.LayoutSwitchService = {
serviceFlag: false,
switchLayout: function (parameter) {
serviceFlag = true
this.serviceFlag = true
}
}
inject(function (_$controller_, _$rootScope_) {
$controller = _$controller_
this.$controller = _$controller_
$scope = _$rootScope_.$new()
$controller('AppFooterController', {
$scope: $scope,
LayoutSwitchService: service
this.$scope = _$rootScope_.$new()
this.$controller('AppFooterController', {
$scope: this.$scope,
LayoutSwitchService: this.LayoutSwitchService
})
})
})
// define tests
it('calls the right function', function (done) {
expect(serviceFlag).toBe(false)
$scope.switchLayout(null)
expect(serviceFlag).toBe(true)
expect(this.LayoutSwitchService.serviceFlag).toBe(false)
this.$scope.switchLayout(true)
expect(this.LayoutSwitchService.serviceFlag).toBe(true)
done()
})
})

10
test/unit/controllers/AppImPanelControllerSpec.js

@ -2,21 +2,19 @@ @@ -2,21 +2,19 @@
/* global describe, it, inject, expect, beforeEach, jasmine */
describe('AppImPanelController', function () {
var $scope
beforeEach(module('myApp.controllers'))
beforeEach(function () {
inject(function (_$controller_, _$rootScope_) {
$scope = _$rootScope_.$new()
$scope.$on = jasmine.createSpy('$on')
_$controller_('AppImPanelController', { $scope: $scope })
this.$scope = _$rootScope_.$new()
this.$scope.$on = jasmine.createSpy('$on')
_$controller_('AppImPanelController', { $scope: this.$scope })
})
})
// define tests
it('sets $on(user_update) to no-operation function', function (done) {
expect($scope.$on).toHaveBeenCalledWith('user_update', angular.noop)
expect(this.$scope.$on).toHaveBeenCalledWith('user_update', angular.noop)
done()
})
})

23
test/unit/controllers/AppLangSelectControllerSpec.js

@ -2,18 +2,17 @@ @@ -2,18 +2,17 @@
/* global describe, it, inject, expect, beforeEach, xit */
describe('AppLangSelectController', function () {
var $controller, $scope
beforeEach(module('ui.bootstrap'))
beforeEach(module('myApp.services'))
beforeEach(module('myApp.controllers'))
beforeEach(function () {
inject(function (_$controller_, _$rootScope_, _, Storage, ErrorService, AppRuntimeManager) {
$controller = _$controller_
$scope = _$rootScope_.$new()
$controller('AppLangSelectController', {
$scope: $scope,
this.$controller = _$controller_
this.$scope = _$rootScope_.$new()
this.$controller('AppLangSelectController', {
$scope: this.$scope,
_: _,
Storage: Storage,
ErrorService: ErrorService,
@ -23,24 +22,24 @@ describe('AppLangSelectController', function () { @@ -23,24 +22,24 @@ describe('AppLangSelectController', function () {
})
it('holds the supportedLocales', function () {
expect($scope.supportedLocales).toBeDefined()
expect(this.$scope.supportedLocales).toBeDefined()
})
it('holds langNames', function () {
expect($scope.langNames).toBeDefined()
expect(this.$scope.langNames).toBeDefined()
})
it('holds the current locale', function () {
expect($scope.curLocale).toBeDefined()
expect(this.$scope.curLocale).toBeDefined()
})
it('has a locale form', function () {
expect($scope.form).toBeDefined()
expect($scope.form.locale).toBeDefined()
expect(this.$scope.form).toBeDefined()
expect(this.$scope.form.locale).toBeDefined()
})
it('allows to select a locale', function () {
expect($scope.localeSelect).toBeDefined()
expect(this.$scope.localeSelect).toBeDefined()
})
describe('when the user switches the locale', function () {

37
test/unit/controllers/AppWelcomeControllerSpec.js

@ -2,21 +2,18 @@ @@ -2,21 +2,18 @@
/* global describe, it, inject, expect, beforeEach */
describe('AppWelcomeController', function () {
var $controller, $rootScope, $scope, $location, MtpApiManager, ErrorService,
ChangelogNotifyService, LayoutSwitchService
beforeEach(module('myApp.controllers'))
beforeEach(function () {
ChangelogNotifyService = {
this.ChangelogNotifyService = {
checkUpdate: function () {}
}
LayoutSwitchService = {
this.LayoutSwitchService = {
start: function () {}
}
MtpApiManager = {
this.MtpApiManager = {
getUserID: function () {
return {
then: function () {}
@ -24,23 +21,19 @@ describe('AppWelcomeController', function () { @@ -24,23 +21,19 @@ describe('AppWelcomeController', function () {
}
}
module(function ($provide) {
$provide.value('MtpApiManager', MtpApiManager)
})
inject(function (_$controller_, _$rootScope_, _$location_) {
$controller = _$controller_
$rootScope = _$rootScope_
$location = _$location_
$scope = $rootScope.$new()
$controller('AppWelcomeController', {
$scope: $scope,
$location: $location,
MtpApiManager: MtpApiManager,
ErrorService: ErrorService,
ChangelogNotifyService: ChangelogNotifyService,
LayoutSwitchService: LayoutSwitchService
this.$controller = _$controller_
this.$rootScope = _$rootScope_
this.$location = _$location_
this.$scope = _$rootScope_.$new()
this.$controller('AppWelcomeController', {
$scope: this.$scope,
$location: this.$location,
MtpApiManager: this.MtpApiManager,
ErrorService: this.ErrorService,
ChangelogNotifyService: this.ChangelogNotifyService,
LayoutSwitchService: this.LayoutSwitchService
})
})
})

55
test/unit/controllers/ChangelogModalControlelerSpec.js

@ -2,69 +2,68 @@ @@ -2,69 +2,68 @@
/* global describe, it, inject, expect, beforeEach, Config */
describe('ChangeLogModalController', function () {
var $controller, $scope, modal, modalFlag
beforeEach(module('myApp.controllers'))
beforeEach(function () {
modalFlag = false
modal = {
this.modal = {
modalFlag: false,
open: function (data) {
modalFlag = true
this.modalFlag = true
}
}
inject(function (_$controller_, _$rootScope_) {
$controller = _$controller_
this.$controller = _$controller_
this.$scope = _$rootScope_.$new()
$scope = _$rootScope_.$new()
$controller('ChangelogModalController', {
$scope: $scope,
$modal: modal
this.$controller('ChangelogModalController', {
$scope: this.$scope,
$modal: this.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)
expect(this.$scope.changelogHidden).toBe(false)
expect(this.$scope.changelogShown).toBe(false)
expect(this.$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)
this.$scope.showAllVersions()
expect(this.$scope.changelogHidden).toBe(false)
expect(this.$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)
this.$scope.changelogShown = true
expect(this.$scope.canShowVersion(null)).toBe(true)
expect(this.$scope.canShowVersion('0.0.1')).toBe(true)
expect(this.$scope.canShowVersion('0.1.0')).toBe(true)
expect(this.$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)
expect(this.$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)
expect(this.$scope.changelogHidden).toBe(false)
expect(this.$scope.canShowVersion('0.0.0')).toBe(false)
expect(this.$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)
expect(this.modal.modalFlag).toBe(false)
this.$scope.changeUsername()
expect(this.modal.modalFlag).toBe(true)
done()
})
})

181
test/unit/controllers/CountrySelectModalControllerSpec.js

@ -0,0 +1,181 @@ @@ -0,0 +1,181 @@
'use strict'
/* global describe, it, inject, expect, beforeEach, afterEach, spyOn, jasmine, Config, SearchIndexManager */
describe('CountrySelectModalController', function () {
beforeEach(module('myApp.controllers'))
beforeEach(inject(function (_$controller_, _$rootScope_, ___) {
this.$controller = _$controller_
this.$rootScope = _$rootScope_
this._ = ___
this.$scope = _$rootScope_.$new()
this.createController = function () {
this.$controller('CountrySelectModalController', {
$scope: this.$scope,
$modalInstance: {},
$rootScope: this.$rootScope,
_: this._
})
}
spyOn(SearchIndexManager, 'indexObject').and.callThrough()
}))
beforeEach(function () {
this.ConfigCountryCodes = Config.CountryCodes
this.testData = {
singleCode: {
countryCode: ['NL', 'country_select_modal_country_nl', '+31'],
countryCode_full: 'NL Netherlands +31',
countryPhoneSets: [{ name: 'Netherlands', code: '+31' }]
},
multipleCode: {
countryCode: ['VA', 'country_select_modal_country_va', '+39 06 698', '+379'],
countryCode_full: 'VA Vatican City +39 06 698 +379',
countryPhoneSets: [{ name: 'Vatican City', code: '+39 06 698' }, { name: 'Vatican City', code: '+379' }]
},
multipleCode2: {
countryCode: ['AB', 'country_select_modal_country_ab', '+7 840', '+7 940', '+995 44'],
countryCode_full: 'AB Abkhazia +7 840 +7 940 +995 44',
countryPhoneSets: [{ name: 'Abkhazia', code: '+7 840' }, { name: 'Abkhazia', code: '+7 940' }, { name: 'Abkhazia', code: '+995 44' }]
},
allSetsSorted: function () {
return [].concat(this.multipleCode2.countryPhoneSets, this.singleCode.countryPhoneSets, this.multipleCode.countryPhoneSets)
},
allSetsUnsorted: function () {
return [].concat(this.singleCode.countryPhoneSets, this.multipleCode2.countryPhoneSets, this.multipleCode.countryPhoneSets)
}
}
})
afterEach(function () {
Config.CountryCodes = this.ConfigCountryCodes
})
// The tests before controller initiation.
// In order to mock Config data
it('initiates Country to select', function (done) {
Config.CountryCodes = [this.testData.singleCode.countryCode]
var expected = this.testData.singleCode.countryCode_full
this.createController()
expect(SearchIndexManager.indexObject).toHaveBeenCalledWith(0, expected, jasmine.any(Object))
done()
})
it('initiates Countriy to select with 2 (or more) country codes', function (done) {
Config.CountryCodes = [this.testData.multipleCode.countryCode]
var expected = this.testData.multipleCode.countryCode_full
this.createController()
expect(SearchIndexManager.indexObject).toHaveBeenCalledWith(0, expected, jasmine.any(Object))
done()
})
it('initiates Countries to select', function (done) {
Config.CountryCodes = [this.testData.singleCode.countryCode, this.testData.multipleCode.countryCode]
var expected1 = this.testData.singleCode.countryCode_full
var expected2 = this.testData.multipleCode.countryCode_full
this.createController()
expect(SearchIndexManager.indexObject).toHaveBeenCalledWith(0, expected1, jasmine.any(Object))
expect(SearchIndexManager.indexObject).toHaveBeenCalledWith(1, expected2, jasmine.any(Object))
done()
})
describe('(after initiation)', function () {
beforeEach(function () {
Config.CountryCodes = [this.testData.singleCode.countryCode, this.testData.multipleCode2.countryCode, this.testData.multipleCode.countryCode]
this.createController()
})
it('initiates the right values', function (done) {
expect(this.$scope.search).toEqual({})
expect(this.$scope.slice).toEqual({limit: 20, limitDelta: 20})
done()
})
it('creates a sorted list of all selectable countries', function (done) {
this.$rootScope.$digest()
var expected = this.testData.allSetsSorted()
expect(this.$scope.countries).toEqual(expected)
done()
})
it('creates a sorted list of all selectable countries for an empty string-input', function (done) {
this.$rootScope.$digest()
this.$scope.search.query = ''
this.$rootScope.$digest()
var expected = this.testData.allSetsSorted()
expect(this.$scope.countries).toEqual(expected)
done()
})
describe(', when an input is given,', function () {
beforeEach(function () {
this.$rootScope.$digest()
this.$scope.search.query = 'A'
})
it('creates a sorted list of all countries containing the input', function (done) {
var expected = this.testData.allSetsSorted()
expect(this.$scope.countries).toEqual(expected)
this.$rootScope.$digest()
expected = this.testData.multipleCode2.countryPhoneSets
expect(this.$scope.countries).toEqual(expected)
done()
})
it('restore the original list when the input is deleted', function (done) {
this.$rootScope.$digest()
this.$scope.search.query = ''
this.$rootScope.$digest()
var expected = this.testData.allSetsSorted()
expect(this.$scope.countries).toEqual(expected)
done()
})
it('restore the original list when the input is changed', function (done) {
this.$rootScope.$digest()
this.$scope.search.query = 'Ne'
this.$rootScope.$digest()
var expected = this.testData.singleCode.countryPhoneSets
expect(this.$scope.countries).toEqual(expected)
done()
})
})
describe(', when no sorting is available,', function () {
beforeEach(function () {
this.StringCompare = String.prototype.localeCompare
String.prototype.localeCompare = null
})
afterEach(function () {
String.prototype.localeCompare = this.StringCompare
})
it('creates a list of all selectable countries', function (done) {
this.$rootScope.$digest()
var expected = this.testData.allSetsUnsorted()
expect(this.$scope.countries).toEqual(expected)
done()
})
})
})
})

145
test/unit/controllers/DocumentModalControllerSpec.js

@ -1,20 +1,19 @@ @@ -1,20 +1,19 @@
'use strict'
/* global describe, it, inject, expect, beforeEach, jasmine */
/* global describe, it, inject, expect, beforeEach, jasmine, spyOn */
describe('DocumentModalController', function () {
var $controller, $scope, $rootScope, $docManager, $errService, $input, $messManager, $pSelectService, $modalI, createController
beforeEach(module('myApp.controllers'))
beforeEach(function () {
$docManager = {}
$docManager.wrapForHistory = jasmine.createSpy('wrapForHistory')
$docManager.saveDocFile = jasmine.createSpy('saveDocFile')
this.AppDocsManager = {
wrapForHistory: jasmine.createSpy('wrapForHistory'),
saveDocFile: jasmine.createSpy('saveDocFile')
}
$input = {}
$errService = {
this.ErrorService = {
$input: {},
confirm: function (message) {
$input = message
this.$input = message
return {
then: function (f) {
f()
@ -23,9 +22,10 @@ describe('DocumentModalController', function () { @@ -23,9 +22,10 @@ describe('DocumentModalController', function () {
}
}
$pSelectService = {
this.PeersSelectService = {
$input: {},
selectPeer: function (options) {
$input = options
this.$input = options
return {
then: function (f) {
f('Peerselected')
@ -34,100 +34,103 @@ describe('DocumentModalController', function () { @@ -34,100 +34,103 @@ describe('DocumentModalController', function () {
}
}
createController = function (spyBroadcast, spyOn) {
if (spyBroadcast) {
$rootScope.$broadcast = jasmine.createSpy('$broadcast')
}
if (spyOn) {
$scope.$on = jasmine.createSpy('$on')
}
$controller('DocumentModalController', {
$scope: $scope,
$rootScope: $rootScope,
$modalInstance: $modalI,
PeersSelectService: $pSelectService,
AppMessagesManager: $messManager,
AppDocsManager: $docManager,
AppPeersManager: {},
ErrorService: $errService
})
this.AppMessagesManager = {
deleteMessages: jasmine.createSpy('deleteMessages')
}
$messManager = {}
$messManager.deleteMessages = jasmine.createSpy('deleteMessages')
$modalI = {}
$modalI.dismiss = jasmine.createSpy('dismissModal')
this.$modalInstance = {
dismiss: jasmine.createSpy('dismissModal')
}
inject(function (_$controller_, _$rootScope_) {
$rootScope = _$rootScope_
$scope = $rootScope.$new()
$scope.docID = 'randomdoc'
$controller = _$controller_
this.$rootScope = _$rootScope_
this.$scope = this.$rootScope.$new()
this.$scope.docID = 'randomdoc'
this.$controller = _$controller_
spyOn(this.$rootScope, '$broadcast').and.callThrough()
spyOn(this.$scope, '$on').and.callThrough()
this.$controller('DocumentModalController', {
$scope: this.$scope,
$rootScope: this.$rootScope,
$modalInstance: this.$modalInstance,
PeersSelectService: this.PeersSelectService,
AppMessagesManager: this.AppMessagesManager,
AppDocsManager: this.AppDocsManager,
AppPeersManager: {},
ErrorService: this.ErrorService
})
})
})
// define tests
it('sets the document in the scope', function (done) {
createController(false, false)
expect($docManager.wrapForHistory).toHaveBeenCalledWith($scope.docID)
expect(this.AppDocsManager.wrapForHistory).toHaveBeenCalledWith(this.$scope.docID)
done()
})
it('forwards a message with a document', function (done) {
createController(true, false)
$scope.messageID = 'id039'
this.$scope.messageID = 'id039'
var messageID = this.$scope.messageID
$scope.forward()
expect($input).toEqual({canSend: true})
expect($scope.$broadcast).toHaveBeenCalledWith('history_focus', {
this.$scope.forward()
expect(this.PeersSelectService.$input).toEqual({canSend: true})
expect(this.$scope.$broadcast).toHaveBeenCalledWith('history_focus', {
peerString: 'Peerselected',
attachment: {
_: 'fwd_messages',
id: [$scope.messageID]
id: [messageID]
}
})
done()
})
it('deletes a message with a document', function (done) {
createController(false, false)
$scope.messageID = 'id123'
this.$scope.messageID = 'id123'
$scope.delete()
expect($input).toEqual({type: 'MESSAGE_DELETE'})
expect($messManager.deleteMessages).toHaveBeenCalledWith([$scope.messageID])
this.$scope.delete()
expect(this.ErrorService.$input).toEqual({type: 'MESSAGE_DELETE'})
expect(this.AppMessagesManager.deleteMessages).toHaveBeenCalledWith([this.$scope.messageID])
done()
})
it('downloads the document', function (done) {
createController(false, false)
$scope.download()
expect($docManager.saveDocFile).toHaveBeenCalledWith($scope.docID)
this.$scope.download()
expect(this.AppDocsManager.saveDocFile).toHaveBeenCalledWith(this.$scope.docID)
done()
})
it('delete a document linked to a message', function (done) {
createController(false, true)
$scope.messageID = 'id33'
it('can not delete a document not linked to a message', function (done) {
this.$scope.messageID = 'id42'
$rootScope.$broadcast('history_delete')
expect($scope.$on).toHaveBeenCalledWith('history_delete', jasmine.any(Function))
expect($modalI.dismiss).not.toHaveBeenCalled()
var historyUpdate = {}
this.$rootScope.$broadcast('history_delete', historyUpdate)
expect(this.$scope.$on).toHaveBeenCalledWith('history_delete', jasmine.any(Function))
expect(this.$modalInstance.dismiss).not.toHaveBeenCalled()
historyUpdate.msgs = {}
this.$rootScope.$broadcast('history_delete', historyUpdate)
expect(this.$scope.$on).toHaveBeenCalledWith('history_delete', jasmine.any(Function))
expect(this.$modalInstance.dismiss).not.toHaveBeenCalled()
done()
})
it('delete a document linked to a modal instance', function (done) {
createController(false, false)
$scope.messageID = 'id876'
var $msgs = {}
$msgs[$scope.messageID] = {message: 'some non-empty message'}
$rootScope.$broadcast('history_delete', {msgs: $msgs})
expect($modalI.dismiss).toHaveBeenCalled()
done()
describe('when the document is related to the message', function () {
beforeEach(function () {
this.historyUpdate = {
msgs: {}
}
})
it('delete that document', function (done) {
this.$scope.messageID = 'id33'
this.historyUpdate.msgs[this.$scope.messageID] = 'an update for id33'
this.$rootScope.$broadcast('history_delete', this.historyUpdate)
expect(this.$scope.$on).toHaveBeenCalledWith('history_delete', jasmine.any(Function))
expect(this.$modalInstance.dismiss).toHaveBeenCalled()
done()
})
})
})

74
test/unit/controllers/EmbedModalController.js

@ -2,18 +2,17 @@ @@ -2,18 +2,17 @@
/* global describe, it, inject, expect, beforeEach, jasmine */
describe('EmbedModalController', function () {
var $scope, $rootScope, $webpageManager, $errService, $input, $messManager, $pSelectService, $modalI
beforeEach(module('myApp.controllers'))
beforeEach(function () {
$webpageManager = {}
$webpageManager.wrapForFull = jasmine.createSpy('wrapForFull')
this.AppWebPagesManager = {
wrapForFull: jasmine.createSpy('wrapForFull')
}
$input = {}
$errService = {
this.ErrorService = {
input: {},
confirm: function (message) {
$input = message
this.input = message
return {
then: function (f) {
f()
@ -22,9 +21,10 @@ describe('EmbedModalController', function () { @@ -22,9 +21,10 @@ describe('EmbedModalController', function () {
}
}
$pSelectService = {
this.PeersSelectService = {
input: {},
selectPeer: function (options) {
$input = options
this.input = options
return {
then: function (f) {
f('Peerselected')
@ -33,60 +33,64 @@ describe('EmbedModalController', function () { @@ -33,60 +33,64 @@ describe('EmbedModalController', function () {
}
}
$messManager = {}
$messManager.deleteMessages = jasmine.createSpy('deleteMessages')
this.AppMessagesManager = {
deleteMessages: jasmine.createSpy('deleteMessages')
}
$modalI = {}
$modalI.dismiss = jasmine.createSpy('dismissModal')
this.$modalInstance = {
dismiss: jasmine.createSpy('dismissModal')
}
inject(function (_$controller_, _$rootScope_) {
$rootScope = _$rootScope_
$rootScope.$broadcast = jasmine.createSpy('$broadcast')
$scope = $rootScope.$new()
$scope.webpageID = 'www.notRelevant.com'
this.$rootScope = _$rootScope_
this.$rootScope.$broadcast = jasmine.createSpy('$broadcast')
this.$scope = this.$rootScope.$new()
this.$scope.webpageID = 'www.notRelevant.com'
_$controller_('EmbedModalController', {
$q: {},
$scope: $scope,
$rootScope: $rootScope,
$modalInstance: $modalI,
PeersSelectService: $pSelectService,
AppMessagesManager: $messManager,
$scope: this.$scope,
$rootScope: this.$rootScope,
$modalInstance: this.$modalInstance,
PeersSelectService: this.PeersSelectService,
AppMessagesManager: this.AppMessagesManager,
AppPeersManager: {},
AppPhotosManager: {},
AppWebPagesManager: $webpageManager,
ErrorService: $errService
AppWebPagesManager: this.AppWebPagesManager,
ErrorService: this.ErrorService
})
})
})
// define tests
it('sets the embeded webpage in the scope', function (done) {
expect($scope.nav).toEqual({})
expect($webpageManager.wrapForFull).toHaveBeenCalledWith($scope.webpageID)
expect(this.$scope.nav).toEqual({})
expect(this.AppWebPagesManager.wrapForFull).toHaveBeenCalledWith(this.$scope.webpageID)
done()
})
it('forwards a message with an embeded link', function (done) {
$scope.messageID = 'id1234234'
this.$scope.messageID = 'id1234234'
var messageID = this.$scope.messageID
$scope.forward()
expect($input).toEqual({canSend: true})
expect($scope.$broadcast).toHaveBeenCalledWith('history_focus', {
this.$scope.forward()
expect(this.PeersSelectService.input).toEqual({canSend: true})
expect(this.$scope.$broadcast).toHaveBeenCalledWith('history_focus', {
peerString: 'Peerselected',
attachment: {
_: 'fwd_messages',
id: [$scope.messageID]
id: [messageID]
}
})
done()
})
it('deletes a message with an embeded link', function (done) {
$scope.messageID = 'id979565673'
this.$scope.messageID = 'id979565673'
$scope.delete()
expect($input).toEqual({type: 'MESSAGE_DELETE'})
expect($messManager.deleteMessages).toHaveBeenCalledWith([$scope.messageID])
this.$scope.delete()
expect(this.ErrorService.input).toEqual({type: 'MESSAGE_DELETE'})
expect(this.AppMessagesManager.deleteMessages).toHaveBeenCalledWith([this.$scope.messageID])
done()
})
})

160
test/unit/controllers/ImportContactModalControllerSpec.js

@ -0,0 +1,160 @@ @@ -0,0 +1,160 @@
'use strict'
/* global describe, it, inject, expect, beforeEach, jasmine */
describe('ImportContactModalController', function () {
beforeEach(module('myApp.controllers'))
beforeEach(function () {
this.modalInstance = {
close: jasmine.createSpy('close'),
dismiss: jasmine.createSpy('dismiss')
}
this.randomID = 123456852
function thenFinallyFactory (input) {
return {
then: function (callback) {
callback(input)
return {
finally: function (callback) {
callback()
}
}
}
}
}
this.AppUsersManager = {
thenValue: null,
importContact: function (phone, first, last) {
this.input = {
phone: phone,
first: first,
last: last
}
return thenFinallyFactory(this.thenValue)
}
}
this.ErrorService = {
show: jasmine.createSpy('show')
}
this.PhonebookContactsService = {
thenValue: false,
isAvailable: function () {
return false
},
openPhonebookImport: function () {
var then = thenFinallyFactory(this.thenValue)
return {
result: then
}
}
}
inject(function (_$controller_, _$rootScope_) {
this.$controller = _$controller_
this.$rootScope = _$rootScope_
this.$scope = _$rootScope_.$new()
this.createController = function () {
this.$controller('ImportContactModalController', {
$scope: this.$scope,
$modalInstance: this.modalInstance,
$rootScope: this.$rootScope,
AppUsersManager: this.AppUsersManager,
ErrorService: this.ErrorService,
PhonebookContactsService: this.PhonebookContactsService
})
}
})
})
it('can create a controller when no imported contacts are defined', function (done) {
this.createController()
expect(this.$scope.importContact).toEqual({})
done()
})
it('can create a controller when imported contacts are defined', function (done) {
this.$scope.importContact = { non_empty: true }
this.createController()
var expected = { non_empty: true }
expect(this.$scope.importContact).toEqual(expected)
done()
})
describe('(when the controller is created), ', function () {
beforeEach(function () {
this.createController()
})
it('does nothing when no phonenumber was entered', function (done) {
this.$scope.doImport()
expect(this.$scope.progress).not.toBeDefined()
this.$scope.importContact = {
first_name: 'bob'
}
expect(this.$scope.progress).not.toBeDefined()
done()
})
describe('when contact-information is added, it', function () {
beforeEach(function () {
this.$scope.importContact = {
phone: '+316132465798'
}
})
it('can handle phoneNumber that are not telegram users', function (done) {
this.$scope.doImport()
expect(this.ErrorService.show).toHaveBeenCalledWith({ error: {code: 404, type: 'USER_NOT_USING_TELEGRAM'} })
expect(this.modalInstance.close).toHaveBeenCalledWith(null)
expect(this.$scope.progress.enabled).not.toBeDefined()
done()
})
it('can import contacts that are telegram users', function (done) {
this.AppUsersManager.thenValue = this.randomID
this.$scope.doImport()
expect(this.ErrorService.show).not.toHaveBeenCalled()
expect(this.modalInstance.close).toHaveBeenCalledWith(this.randomID)
expect(this.$scope.progress.enabled).not.toBeDefined()
expect(this.AppUsersManager.input).toEqual({phone: '+316132465798', first: '', last: ''})
done()
})
it('can handle contacts with first and last name', function (done) {
this.$scope.importContact.first_name = 'jan'
this.$scope.importContact.last_name = 'wandelaar'
this.$scope.doImport()
expect(this.AppUsersManager.input).toEqual({phone: '+316132465798', first: 'jan', last: 'wandelaar'})
done()
})
})
it('can not import contacts from a phonebook if none were found', function (done) {
this.$scope.importPhonebook()
expect(this.modalInstance.dismiss).toHaveBeenCalled()
done()
})
it('can import contacts from a phonebook', function (done) {
this.PhonebookContactsService.thenValue = {0: 'dummy'}
this.$scope.importPhonebook()
expect(this.modalInstance.close).toHaveBeenCalledWith('dummy')
done()
})
})
})

113
test/unit/controllers/PasswordRecoveryModalControllerSpec.js

@ -0,0 +1,113 @@ @@ -0,0 +1,113 @@
'use strict'
/* global describe, it, inject, expect, beforeEach, jasmine */
describe('PasswordRecoveryModalController', function () {
beforeEach(module('myApp.controllers'))
beforeEach(function () {
this.PasswordManager = {
errorField: null,
recover: function () {
return this
},
then: function (callback, error) {
if (!this.errorField) {
callback({})
} else {
error(this.errorField)
}
return {
finally: function (final) {
final()
}
}
}
}
this.ErrorService = { alert: jasmine.createSpy('alert') }
this.modalInstance = {
close: jasmine.createSpy('close'),
dismiss: jasmine.createSpy('dismiss')
}
inject(function (_$controller_, _$rootScope_, ___) {
this.$controller = _$controller_
this.$scope = _$rootScope_.$new()
this.$scope.recovery = {}
this.$controller('PasswordRecoveryModalController', {
$scope: this.$scope,
$q: {},
_: ___,
PasswordManager: this.PasswordManager,
MtpApiManager: {},
ErrorService: this.ErrorService,
$modalInstance: this.modalInstance
})
})
})
it('can handle a successful password change', function (done) {
this.$scope.checkCode()
expect(this.$scope.recovery.updating).toBe(true)
expect(this.ErrorService.alert).toHaveBeenCalledWith('Password deactivated', 'You have disabled Two-Step Verification.')
expect(this.modalInstance.close).toHaveBeenCalled()
done()
})
describe('when an error occurs', function () {
beforeEach(function () {
this.PasswordManager.errorField = {}
})
it('cancels the recovery', function (done) {
this.$scope.checkCode()
expect(this.$scope.recovery.updating).not.toBeDefined()
expect(this.ErrorService.alert).not.toHaveBeenCalled()
expect(this.modalInstance.close).not.toHaveBeenCalled()
done()
})
it('can handle the error for an empty code', function (done) {
this.PasswordManager.errorField.type = 'CODE_EMPTY'
this.$scope.checkCode()
expect(this.$scope.recovery.error_field).toEqual('code')
done()
})
it('can handle the error for an invalid code', function (done) {
this.PasswordManager.errorField.type = 'CODE_INVALID'
this.$scope.checkCode()
expect(this.$scope.recovery.error_field).toEqual('code')
done()
})
it('can handle the error for an empty password', function (done) {
this.PasswordManager.errorField.type = 'PASSWORD_EMPTY'
this.$scope.checkCode()
expect(this.modalInstance.dismiss).toHaveBeenCalled()
done()
})
it('can handle the error for the unavailability of the recovery', function (done) {
this.PasswordManager.errorField.type = 'PASSWORD_RECOVERY_NA'
this.$scope.checkCode()
expect(this.modalInstance.dismiss).toHaveBeenCalled()
done()
})
it('can handle the error for an expired recovery', function (done) {
this.PasswordManager.errorField.type = 'PASSWORD_RECOVERY_EXPIRED'
this.$scope.checkCode()
expect(this.modalInstance.dismiss).toHaveBeenCalled()
done()
})
})
})

305
test/unit/controllers/PeerSelectControllerSpec.js

@ -2,22 +2,20 @@ @@ -2,22 +2,20 @@
/* global describe, it, inject, expect, beforeEach */
describe('PeerSelectController', function () {
var $controller, $scope, $q, $mod, $APManager, $EService, createController, timeoutTime, $promiseData, $promise, $promiseFlag
beforeEach(module('myApp.controllers'))
beforeEach(function () {
// The modalInstance will propably usually give a boolean as return.
// However, for testing purposes it is important to gain knowledge about the input of the function
$mod = {
this.$modalInstance = {
close: function (arr) {
return arr
}
}
timeoutTime = 1000
this.oneSecond = 1000
$APManager = {
this.AppPeersManager = {
getPeerString: function (str) {
return 'P'.concat(str)
},
@ -29,229 +27,232 @@ describe('PeerSelectController', function () { @@ -29,229 +27,232 @@ describe('PeerSelectController', function () {
}
}
// The controller is created in the test in order to test different initial content of scope variables.
createController = function () {
$controller('PeerSelectController', {
$scope: $scope,
$modalInstance: $mod,
$q: $q,
AppPeersManager: $APManager,
ErrorService: $EService
})
}
$promiseFlag = false
$promise = {
this.promise = {
promiseFlag: false,
then: function (f) {
$promiseFlag = true
this.$promiseFlag = true
f()
}
}
$EService = {
confirm: function (data) {
$promiseData = data
return $promise
var promise = this.promise
this.$q = {
when: function () {
return promise
}
}
$q = {
when: function () {
return $promise
this.ErrorService = {
$promiseData: {},
confirm: function (data) {
this.$promiseData = data
return promise
}
}
inject(function (_$controller_, _$rootScope_) {
$controller = _$controller_
$scope = _$rootScope_.$new()
this.$controller = _$controller_
this.$scope = _$rootScope_.$new()
// The controller is created in the test in order to test different initial content of scope variables.
this.createController = function () {
this.$controller('PeerSelectController', {
$scope: this.$scope,
$modalInstance: this.$modalInstance,
$q: this.$q,
AppPeersManager: this.AppPeersManager,
ErrorService: this.ErrorService
})
}
})
})
it('initialises properties', function (done) {
createController()
this.createController()
// Set timer to give the controller time to resolve.
setTimeout(function () {
expect($scope.selectedPeers).toBeDefined()
expect($scope.selectedPeersIDs).toBeDefined()
expect($scope.selectedCount).toBeDefined()
}, timeoutTime)
expect(this.$scope.selectedPeers).toBeDefined()
expect(this.$scope.selectedPeersIDs).toBeDefined()
expect(this.$scope.selectedCount).toBeDefined()
}, this.oneSecond)
done()
})
it('compiles with a shareLinkPromise that resolves', function (done) {
var expected = 'testURL'
$scope.shareLinkPromise = {
var oneSecond = this.oneSecond
this.$scope.shareLinkPromise = {
then: function (resolve, reject) {
setTimeout(resolve(expected), timeoutTime)
setTimeout(resolve(expected), oneSecond)
}
}
createController()
this.createController()
setTimeout(function () {
expect($scope.shareLink.loading).toBe(true)
expect($scope.shareLink.url).not.toBeDefined()
setTimeout(function () {
expect($scope.shareLink.url).toBe(expected)
}, timeoutTime)
}, timeoutTime)
function afterLoad () {
expect(this.$scope.shareLink.url).toBe(expected)
}
function duringLoad () {
expect(this.$scope.shareLink.loading).toBe(true)
expect(this.$scope.shareLink.url).not.toBeDefined()
setTimeout(afterLoad, oneSecond)
}
setTimeout(duringLoad, oneSecond)
done()
})
it('compiles with a shareLinkPromise that doesn\'t resolve', function (done) {
$scope.shareLinkPromise = {
var oneSecond = this.oneSecond
this.$scope.shareLinkPromise = {
then: function (resolve, reject) {
setTimeout(reject(), timeoutTime)
setTimeout(reject(), oneSecond)
}
}
createController()
this.createController()
setTimeout(function () {
expect($scope.shareLink.loading).toBe(true)
setTimeout(function () {
expect($scope.shareLink).not.toBeDefined()
}, timeoutTime)
}, timeoutTime)
done()
})
it('can select and submit a single dialog without confirmed type', function (done) {
createController()
$scope.dialogSelect('dialogX')
expect($promiseData).not.toBeDefined()
expect($promiseFlag).toBe(true)
done()
})
it('can select and submit a single dialog with confirmed type', function (done) {
createController()
$scope.confirm_type = 'INVITE_TO_GROUP'
$scope.dialogSelect('dialogX')
var expected = {
type: 'INVITE_TO_GROUP',
peer_id: 'X',
peer_data: 'Xpeer'
function afterLoad () {
expect(this.$scope.shareLink).not.toBeDefined()
}
expect($promiseData).toEqual(expected)
expect($promiseFlag).toBe(true)
function duringLoad () {
expect(this.$scope.shareLink.loading).toBe(true)
setTimeout(afterLoad, oneSecond)
}
setTimeout(duringLoad, oneSecond)
done()
})
it('can select a dialog', function (done) {
createController()
describe('after initialisation', function () {
beforeEach(function () {
this.createController()
})
$scope.multiSelect = true
$scope.dialogSelect('dialogX')
it('can select and submit a single dialog without confirmed type', function (done) {
this.$scope.dialogSelect('dialogX')
var expected = ['X']
expect(this.ErrorService.$promiseData).toEqual({})
expect(this.promise.$promiseFlag).toBe(true)
expect($scope.selectedPeers['X']).toBe('Xpeer')
expect($scope.selectedCount).toBe(1)
expect($scope.selectedPeerIDs).toEqual(expected)
done()
})
done()
})
it('can select and submit a single dialog with confirmed type', function (done) {
this.$scope.confirm_type = 'INVITE_TO_GROUP'
this.$scope.dialogSelect('dialogX')
it('can select multiple dialogs', function (done) {
createController()
var peerId = 'X'
var expected = {
type: 'INVITE_TO_GROUP',
peer_id: peerId,
peer_data: this.AppPeersManager.getPeer(peerId)
}
$scope.multiSelect = true
$scope.dialogSelect('dialogX')
$scope.dialogSelect('dialogZ')
$scope.dialogSelect('dialogY')
expect(this.ErrorService.$promiseData).toEqual(expected)
expect(this.promise.$promiseFlag).toBe(true)
var expected = ['Y', 'Z', 'X']
done()
})
expect($scope.selectedCount).toBe(3)
expect($scope.selectedPeerIDs).toEqual(expected)
it('can select a dialog', function (done) {
this.$scope.multiSelect = true
this.$scope.dialogSelect('dialogX')
done()
})
var expected = {
selectedPeers: 'Xpeer',
selectedPeerIDs: ['X']
}
it('can unselect a dialog', function (done) {
createController()
expect(this.$scope.selectedPeers['X']).toBe(expected.selectedPeers)
expect(this.$scope.selectedCount).toBe(1)
expect(this.$scope.selectedPeerIDs).toEqual(expected.selectedPeerIDs)
$scope.multiSelect = true
$scope.selectedCount = 1
$scope.selectedPeers['Y'] = 'aYPeer'
$scope.selectedPeerIDs.unshift('Y')
done()
})
$scope.dialogSelect('dialogY')
it('can select multiple dialogs', function (done) {
this.$scope.multiSelect = true
this.$scope.dialogSelect('dialogX')
this.$scope.dialogSelect('dialogZ')
this.$scope.dialogSelect('dialogY')
var expected = []
var expected = ['Y', 'Z', 'X']
expect($scope.selectedPeers['Y']).not.toBeDefined()
expect($scope.selectedCount).toBe(0)
expect($scope.selectedPeerIDs).toEqual(expected)
expect(this.$scope.selectedCount).toBe(3)
expect(this.$scope.selectedPeerIDs).toEqual(expected)
done()
})
done()
})
it('can select multiple dialogs', function (done) {
createController()
it('can unselect a dialog', function (done) {
this.$scope.multiSelect = true
this.$scope.selectedCount = 1
this.$scope.selectedPeers['Y'] = 'aYPeer'
this.$scope.selectedPeerIDs.unshift('Y')
$scope.multiSelect = true
$scope.dialogSelect('dialogX')
$scope.dialogSelect('dialogZ')
$scope.dialogSelect('dialogY')
$scope.dialogSelect('dialogZ')
this.$scope.dialogSelect('dialogY')
var expected = ['Y', 'X']
var expected = []
expect($scope.selectedCount).toBe(2)
expect($scope.selectedPeerIDs).toEqual(expected)
expect(this.$scope.selectedPeers['Y']).not.toBeDefined()
expect(this.$scope.selectedCount).toBe(0)
expect(this.$scope.selectedPeerIDs).toEqual(expected)
done()
})
done()
})
it('can\'t submit a empty set of dialogs', function (done) {
createController()
it('can select multiple dialogs', function (done) {
this.$scope.multiSelect = true
this.$scope.dialogSelect('dialogX')
this.$scope.dialogSelect('dialogZ')
this.$scope.dialogSelect('dialogY')
this.$scope.dialogSelect('dialogZ')
expect($scope.submitSelected()).not.toBeDefined()
var expected = ['Y', 'X']
done()
})
expect(this.$scope.selectedCount).toBe(2)
expect(this.$scope.selectedPeerIDs).toEqual(expected)
it('can submit one dialog', function (done) {
createController()
done()
})
$scope.selectedCount = 1
$scope.selectedPeers['test'] = 'peer'
var expected = ['Ptest']
expect($scope.submitSelected()).toEqual(expected)
it('can\'t submit a empty set of dialogs', function (done) {
expect(this.$scope.submitSelected()).not.toBeDefined()
done()
})
done()
})
it('can submit multiple dialogs', function (done) {
createController()
it('can submit one dialog', function (done) {
this.$scope.selectedCount = 1
this.$scope.selectedPeers['test'] = 'peer'
var expected = ['Ptest']
expect(this.$scope.submitSelected()).toEqual(expected)
$scope.selectedCount = 3
$scope.selectedPeers['test1'] = $scope.selectedPeers['test2'] = $scope.selectedPeers['test4'] = 'peer'
done()
})
var expected = ['Ptest4', 'Ptest2', 'Ptest1']
expect($scope.submitSelected()).toEqual(expected)
it('can submit multiple dialogs', function (done) {
this.$scope.selectedCount = 3
this.$scope.selectedPeers['test1'] = this.$scope.selectedPeers['test2'] = this.$scope.selectedPeers['test4'] = 'peer'
done()
})
var expected = ['Ptest4', 'Ptest2', 'Ptest1']
expect(this.$scope.submitSelected()).toEqual(expected)
it('can toggle', function (done) {
createController()
done()
})
var broadcastFlag = ''
$scope.$broadcast = function (input) { broadcastFlag = input }
it('can toggle', function (done) {
var broadcastFlag = ''
this.$scope.$broadcast = function (input) { broadcastFlag = input }
$scope.toggleSearch()
expect(broadcastFlag).toBe('dialogs_search_toggle')
this.$scope.toggleSearch()
expect(broadcastFlag).toBe('dialogs_search_toggle')
done()
done()
})
})
})

108
test/unit/controllers/ProfileEditModalControllerSpec.js

@ -0,0 +1,108 @@ @@ -0,0 +1,108 @@
'use strict'
/* global describe, it, inject, expect, beforeEach, jasmine */
describe('ProfileEditModalController', function () {
beforeEach(module('myApp.controllers'))
beforeEach(function () {
var id = 42
this.randomID = id
this.MtpApiManager = {
errorField: null,
getUserID: function () {
return {
then: function (callback) {
callback(id)
}
}
},
invokeApi: function (action, params) {
return this
},
then: function (callback, error) {
if (!this.errorField) {
callback({})
} else {
error(this.errorField)
}
return {
finally: function (final) {
final()
}
}
}
}
this.AppUsersManager = {
getUser: function (userId) {
return {
first_name: 'John',
last_name: 'Doe'
}
},
saveApiUser: jasmine.createSpy('saveApiUser')
}
this.$modalInstance = { close: jasmine.createSpy('close') }
inject(function (_$controller_, _$rootScope_) {
this.$controller = _$controller_
this.$scope = _$rootScope_.$new()
this.$controller('ProfileEditModalController', {
$scope: this.$scope,
$modalInstance: this.$modalInstance,
AppUsersManager: this.AppUsersManager,
MtpApiManager: this.MtpApiManager
})
})
})
it('should initiate the right scope', function (done) {
expect(this.$scope.profile).toEqual({first_name: 'John', last_name: 'Doe'})
expect(this.$scope.error).toEqual({})
done()
})
it('can send a successful profile update request', function (done) {
this.$scope.updateProfile()
expect(this.AppUsersManager.saveApiUser).toHaveBeenCalled()
expect(this.$modalInstance.close).toHaveBeenCalled()
done()
})
it('can handle empty name/surname', function (done) {
delete this.$scope.profile.first_name
delete this.$scope.profile.last_name
this.$scope.updateProfile()
expect(this.AppUsersManager.saveApiUser).toHaveBeenCalled()
expect(this.$modalInstance.close).toHaveBeenCalled()
done()
})
it('can handle an invalid first name error', function (done) {
this.MtpApiManager.errorField = {type: 'FIRSTNAME_INVALID'}
this.$scope.updateProfile()
expect(this.$scope.error.field).toEqual('first_name')
done()
})
it('can handle an invalid last name error', function (done) {
this.MtpApiManager.errorField = {type: 'LASTNAME_INVALID'}
this.$scope.updateProfile()
expect(this.$scope.error.field).toEqual('last_name')
done()
})
it('can handle an unmodified name error', function (done) {
this.MtpApiManager.errorField = {type: 'NAME_NOT_MODIFIED'}
this.$scope.updateProfile()
expect(this.$modalInstance.close).toHaveBeenCalled()
done()
})
})

146
test/unit/controllers/UsernameEditModalControllerSpec.js

@ -0,0 +1,146 @@ @@ -0,0 +1,146 @@
'use strict'
/* global describe, it, inject, expect, beforeEach, jasmine */
describe('UsernameEditModalController', function () {
beforeEach(module('myApp.controllers'))
beforeEach(function () {
this.MtpApiManager = {
errorField: false,
isValid: true,
invokeApi: function () {
return this
},
getUserID: function () {
return this
},
then: function (callback, error) {
if (!this.errorField) {
callback(this.isValid)
} else {
error(this.errorField)
}
return {
finally: function (final) {
final()
}
}
}
}
this.AppUsersManager = {
saveApiUser: jasmine.createSpy('saveApiUser'),
getUser: function (id) {
return { username: 'bob' }
}
}
this.modalInstance = {
close: jasmine.createSpy('close')
}
inject(function (_$controller_, _$rootScope_) {
this.$controller = _$controller_
this.$scope = _$rootScope_.$new()
this.$controller('UsernameEditModalController', {
$scope: this.$scope,
$modalInstance: this.modalInstance,
AppUsersManager: this.AppUsersManager,
MtpApiManager: this.MtpApiManager
})
})
})
it('constructs the information for the modal', function (done) {
var expected = {
username: 'bob'
}
expect(this.$scope.profile).toEqual(expected)
expect(this.$scope.error).toEqual({})
done()
})
it('can handle a successful update of the username', function (done) {
this.$scope.updateUsername()
expect(this.$scope.checked).toEqual({})
expect(this.AppUsersManager.saveApiUser).toHaveBeenCalled()
expect(this.modalInstance.close).toHaveBeenCalled()
done()
})
it('can handle a successful update of an empty/undefined username', function (done) {
delete this.$scope.profile.username
this.$scope.updateUsername()
expect(this.$scope.checked).toEqual({})
expect(this.AppUsersManager.saveApiUser).toHaveBeenCalled()
expect(this.modalInstance.close).toHaveBeenCalled()
done()
})
it('can handle an unsuccessful update of an unmodified username', function (done) {
this.MtpApiManager.errorField = { type: 'USERNAME_NOT_MODIFIED' }
this.$scope.updateUsername()
expect(this.$scope.checked).not.toBeDefined()
expect(this.AppUsersManager.saveApiUser).not.toHaveBeenCalled()
expect(this.modalInstance.close).toHaveBeenCalled()
done()
})
it('can check an empty username on change', function (done) {
this.$scope.profile.username = {}
var expected = {}
this.$scope.$digest()
expect(this.$scope.checked).toEqual(expected)
done()
})
it('can check an empty string as username', function (done) {
this.$scope.profile.username = ''
var expected = {}
this.$scope.$digest()
expect(this.$scope.checked).toEqual(expected)
done()
})
it('can check the initial username', function (done) {
// Previous username is expected to be valid
this.$scope.$digest()
var expected = true
expect(this.$scope.checked.success).toBe(expected)
done()
})
it('does not check anything when the name is not changed', function (done) {
this.$scope.$digest()
delete this.$scope.checked.success
this.$scope.$digest()
expect(this.$scope.checked.success).not.toBeDefined()
done()
})
it('can check an invalid username submission', function (done) {
this.MtpApiManager.isValid = false
this.$scope.$digest()
var expected = true
expect(this.$scope.checked.error).toBe(expected)
done()
})
it('can check an invalid username submission 2', function (done) {
this.MtpApiManager.errorField = { type: 'USERNAME_INVALID' }
this.$scope.$digest()
var expected = true
expect(this.$scope.checked.error).toBe(expected)
done()
})
})

152
test/unit/controllers/VideoModalControllerSpec.js

@ -1,20 +1,19 @@ @@ -1,20 +1,19 @@
'use strict'
/* global describe, it, inject, expect, beforeEach, jasmine */
/* global describe, it, inject, expect, beforeEach, jasmine, spyOn */
describe('VideoModalController', function () {
var $controller, $scope, $rootScope, $docManager, $errService, $input, $messManager, $pSelectService, $modalI, createController
beforeEach(module('myApp.controllers'))
beforeEach(function () {
$docManager = {}
$docManager.wrapVideoForFull = jasmine.createSpy('wrapVideoForFull')
$docManager.saveDocFile = jasmine.createSpy('saveDocFile')
this.AppDocsManager = {
wrapVideoForFull: jasmine.createSpy('wrapVideoForFull'),
saveDocFile: jasmine.createSpy('saveDocFile')
}
$input = {}
$errService = {
this.ErrorService = {
input: {},
confirm: function (message) {
$input = message
this.input = message
return {
then: function (f) {
f()
@ -23,9 +22,10 @@ describe('VideoModalController', function () { @@ -23,9 +22,10 @@ describe('VideoModalController', function () {
}
}
$pSelectService = {
this.PeersSelectService = {
input: {},
selectPeer: function (options) {
$input = options
this.input = options
return {
then: function (f) {
f('Peerselected')
@ -34,102 +34,114 @@ describe('VideoModalController', function () { @@ -34,102 +34,114 @@ describe('VideoModalController', function () {
}
}
createController = function (spyBroadcast, spyOn) {
if (spyBroadcast) {
$rootScope.$broadcast = jasmine.createSpy('$broadcast')
}
if (spyOn) {
$scope.$on = jasmine.createSpy('$on')
}
$controller('VideoModalController', {
$scope: $scope,
$rootScope: $rootScope,
$modalInstance: $modalI,
PeersSelectService: $pSelectService,
AppMessagesManager: $messManager,
AppDocsManager: $docManager,
AppPeersManager: {},
ErrorService: $errService
})
this.AppMessagesManager = {
deleteMessages: jasmine.createSpy('deleteMessages')
}
$messManager = {}
$messManager.deleteMessages = jasmine.createSpy('deleteMessages')
$modalI = {}
$modalI.dismiss = jasmine.createSpy('dismissModal')
this.$modalInstance = {
dismiss: jasmine.createSpy('dismissModal')
}
inject(function (_$controller_, _$rootScope_) {
$rootScope = _$rootScope_
$scope = $rootScope.$new()
$scope.docID = 'randomvideo'
$controller = _$controller_
this.$rootScope = _$rootScope_
this.$scope = this.$rootScope.$new()
this.$scope.docID = 'randomvideo'
this.$controller = _$controller_
spyOn(this.$rootScope, '$broadcast').and.callThrough()
spyOn(this.$scope, '$on').and.callThrough()
this.$controller('VideoModalController', {
$scope: this.$scope,
$rootScope: this.$rootScope,
$modalInstance: this.$modalInstance,
PeersSelectService: this.PeersSelectService,
AppMessagesManager: this.AppMessagesManager,
AppDocsManager: this.AppDocsManager,
AppPeersManager: {},
ErrorService: this.ErrorService
})
})
})
// define tests
it('sets the video in the scope', function (done) {
createController(false, false)
expect($scope.progress).toEqual({enabled: false})
expect($scope.player).toEqual({})
expect($docManager.wrapVideoForFull).toHaveBeenCalledWith($scope.docID)
expect(this.$scope.progress).toEqual({enabled: false})
expect(this.$scope.player).toEqual({})
expect(this.AppDocsManager.wrapVideoForFull).toHaveBeenCalledWith(this.$scope.docID)
done()
})
it('forwards a message with a video', function (done) {
createController(true, false)
$scope.messageID = 'id68567'
this.$scope.messageID = 'id68567'
var messageID = this.$scope.messageID
$scope.forward()
expect($input).toEqual({canSend: true})
expect($scope.$broadcast).toHaveBeenCalledWith('history_focus', {
this.$scope.forward()
expect(this.PeersSelectService.input).toEqual({canSend: true})
expect(this.$scope.$broadcast).toHaveBeenCalledWith('history_focus', {
peerString: 'Peerselected',
attachment: {
_: 'fwd_messages',
id: [$scope.messageID]
id: [messageID]
}
})
done()
})
it('deletes a message with a video', function (done) {
createController(false, false)
$scope.messageID = 'id235235'
this.$scope.messageID = 'id235235'
$scope.delete()
expect($input).toEqual({type: 'MESSAGE_DELETE'})
expect($messManager.deleteMessages).toHaveBeenCalledWith([$scope.messageID])
this.$scope.delete()
expect(this.ErrorService.input).toEqual({type: 'MESSAGE_DELETE'})
expect(this.AppMessagesManager.deleteMessages).toHaveBeenCalledWith([this.$scope.messageID])
done()
})
it('downloads the document (video)', function (done) {
createController(false, false)
$scope.download()
expect($docManager.saveDocFile).toHaveBeenCalledWith($scope.docID)
this.$scope.download()
expect(this.AppDocsManager.saveDocFile).toHaveBeenCalledWith(this.$scope.docID)
done()
})
it('delete a video linked to a message', function (done) {
createController(false, true)
$scope.messageID = 'id2352'
this.$scope.messageID = 'id2352'
$rootScope.$broadcast('history_delete')
expect($scope.$on).toHaveBeenCalledWith('history_delete', jasmine.any(Function))
expect($modalI.dismiss).not.toHaveBeenCalled()
this.$rootScope.$broadcast('history_delete')
expect(this.$scope.$on).toHaveBeenCalledWith('history_delete', jasmine.any(Function))
expect(this.$modalInstance.dismiss).not.toHaveBeenCalled()
done()
})
it('delete a video linked to a modal instance', function (done) {
createController(false, false)
$scope.messageID = 'id6234'
it('can not delete a video not linked to a message', function (done) {
this.$scope.messageID = 'id42'
var $msgs = {}
$msgs[$scope.messageID] = {message: 'some non-empty message'}
$rootScope.$broadcast('history_delete', {msgs: $msgs})
expect($modalI.dismiss).toHaveBeenCalled()
var historyUpdate = {}
this.$rootScope.$broadcast('history_delete', historyUpdate)
expect(this.$scope.$on).toHaveBeenCalledWith('history_delete', jasmine.any(Function))
expect(this.$modalInstance.dismiss).not.toHaveBeenCalled()
historyUpdate.msgs = {}
this.$rootScope.$broadcast('history_delete', historyUpdate)
expect(this.$scope.$on).toHaveBeenCalledWith('history_delete', jasmine.any(Function))
expect(this.$modalInstance.dismiss).not.toHaveBeenCalled()
done()
})
describe('when the video is related to the message', function () {
beforeEach(function () {
this.historyUpdate = {
msgs: {}
}
})
it('delete that video', function (done) {
this.$scope.messageID = 'id33'
this.historyUpdate.msgs[this.$scope.messageID] = 'an update for id33'
this.$rootScope.$broadcast('history_delete', this.historyUpdate)
expect(this.$scope.$on).toHaveBeenCalledWith('history_delete', jasmine.any(Function))
expect(this.$modalInstance.dismiss).toHaveBeenCalled()
done()
})
})
})

14
test/unit/directives/myHeadDirective.js

@ -2,25 +2,23 @@ @@ -2,25 +2,23 @@
/* global describe, it, inject, expect, beforeEach */
describe('myHead directive', function () {
var $compile, $rootScope
beforeEach(module('myApp.templates'))
beforeEach(module('myApp.directives'))
beforeEach(inject(function (_$compile_, _$rootScope_) {
$compile = _$compile_
$rootScope = _$rootScope_
this.$compile = _$compile_
this.$rootScope = _$rootScope_
}))
it('compiles a my-head attribute', function () {
var compiledElement = $compile('<div my-head></div>')($rootScope)
$rootScope.$digest() // Fire watchers
var compiledElement = this.$compile('<div my-head></div>')(this.$rootScope)
this.$rootScope.$digest()
expect(compiledElement.html()).toContain('tg_page_head')
})
it('compiles a my-head element', function () {
var compiledElement = $compile('<my-head></my-head>')($rootScope)
$rootScope.$digest() // Fire watchers
var compiledElement = this.$compile('<my-head></my-head>')(this.$rootScope)
this.$rootScope.$digest()
expect(compiledElement.html()).toContain('tg_page_head')
})
})

14
test/unit/directives/myLangFooterDirective.js

@ -2,8 +2,6 @@ @@ -2,8 +2,6 @@
/* global describe, it, inject, expect, beforeEach */
describe('myLangFooter directive', function () {
var $compile, $rootScope
beforeEach(module('ui.bootstrap'))
beforeEach(module('myApp.templates'))
// ErrorServiceProvider in myApp.services is needed by
@ -13,20 +11,20 @@ describe('myLangFooter directive', function () { @@ -13,20 +11,20 @@ describe('myLangFooter directive', function () {
beforeEach(module('myApp.directives'))
beforeEach(inject(function (_$compile_, _$rootScope_) {
$compile = _$compile_
$rootScope = _$rootScope_
this.$compile = _$compile_
this.$rootScope = _$rootScope_
}))
it('compiles a my-lang-footer attribute', function () {
var compiledElement = $compile('<div my-lang-footer></div>')($rootScope)
$rootScope.$digest() // Fire watchers
var compiledElement = this.$compile('<div my-lang-footer></div>')(this.$rootScope)
this.$rootScope.$digest()
expect(compiledElement.html()).toContain('footer_lang_link')
expect(compiledElement.html()).toContain('AppLangSelectController')
})
it('compiles a my-lang-footer element', function () {
var compiledElement = $compile('<my-lang-footer></my-lang-footer>')($rootScope)
$rootScope.$digest() // Fire watchers
var compiledElement = this.$compile('<my-lang-footer></my-lang-footer>')(this.$rootScope)
this.$rootScope.$digest()
expect(compiledElement.html()).toContain('footer_lang_link')
expect(compiledElement.html()).toContain('AppLangSelectController')
})

20
test/unit/services/PhonebookContactsServiceSpec.js

@ -2,52 +2,50 @@ @@ -2,52 +2,50 @@
/* global describe, it, inject, expect, beforeEach, jasmine, xit */
describe('PhonebookContactsService', function () {
var PhonebookContactsService, $modal
beforeEach(module('ui.bootstrap'))
beforeEach(module('myApp.services'))
beforeEach(inject(function (_PhonebookContactsService_) {
PhonebookContactsService = _PhonebookContactsService_
this.PhonebookContactsService = _PhonebookContactsService_
}))
describe('Public API:', function () {
it('checks availability', function () {
expect(PhonebookContactsService.isAvailable).toBeDefined()
expect(this.PhonebookContactsService.isAvailable).toBeDefined()
})
it('open the phonebook for import', function () {
expect(PhonebookContactsService.openPhonebookImport).toBeDefined()
expect(this.PhonebookContactsService.openPhonebookImport).toBeDefined()
})
it('get phonebook contacts', function () {
expect(PhonebookContactsService.getPhonebookContacts).toBeDefined()
expect(this.PhonebookContactsService.getPhonebookContacts).toBeDefined()
})
describe('usage', function () {
describe('of isAvailable()', function () {
it('returns false in most cases', function (done) {
expect(PhonebookContactsService.isAvailable()).toBe(false)
expect(this.PhonebookContactsService.isAvailable()).toBe(false)
done()
})
})
describe('of openPhonebookImport()', function () {
beforeEach(function () {
$modal = {
this.$modal = {
open: jasmine.createSpy('open')
}
})
xit('opens a modal', function () {
PhonebookContactsService.openPhonebookImport()
expect($modal.open).toHaveBeenCalled()
this.PhonebookContactsService.openPhonebookImport()
expect(this.$modal.open).toHaveBeenCalled()
})
})
describe('of getPhonebookContacts()', function () {
xit('will get rejected in most cases', function (done) {
var promise = PhonebookContactsService.getPhonebookContacts()
var promise = this.PhonebookContactsService.getPhonebookContacts()
promise.finally(function () {
expect(promise.isFullfilled()).toBe(true)
done()

Loading…
Cancel
Save