forked from hodgepodgers/ng-intl-tel-input
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ng-intl-tel-input.provider.spec.js
65 lines (59 loc) · 2.28 KB
/
ng-intl-tel-input.provider.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
describe('ngIntlTelInput Provider', function () {
var provider, element;
describe('Provider Config', function () {
beforeEach(module('ngIntlTelInput', function (ngIntlTelInputProvider) {
provider = ngIntlTelInputProvider;
}));
beforeEach(inject(function (_$injector_, $compile) {
$injector = _$injector_;
element = angular.element(
'<form name="form">' +
'<label for="tel">Telephone</label>' +
'<input ng-model="model.tel" type="text" name="tel" ng-intl-tel-input />' +
'</form>'
);
}));
it('should allow the passing of utils file', function () {
var script = {'utilsScript': '/path/to/utils'};
provider.set(script);
var stub = sinon.stub(element, 'intlTelInput');
$injector.invoke(provider.$get).init(element);
expect(stub.calledWith(script)).toBe(true);
stub.restore();
});
it('should set initial country', function () {
provider.set({'initialCountry': 'af'});
$injector.invoke(provider.$get).init(element);
expect(element.intlTelInput('getSelectedCountryData').iso2).toEqual('af');
});
it('should set multiple properties', function () {
var script = {'initialCountry': 'us', 'utilsScript': 'lol'};
provider.set(script);
var stub = sinon.stub(element, 'intlTelInput');
$injector.invoke(provider.$get).init(element);
expect(stub.calledWith(script)).toBe(true);
stub.restore();
});
});
describe('Attribute Config', function () {
beforeEach(module('ngIntlTelInput', function (ngIntlTelInputProvider) {
provider = ngIntlTelInputProvider;
}));
beforeEach(inject(function (_$injector_, $compile) {
$injector = _$injector_;
element = angular.element(
'<form name="form">' +
'<label for="tel">Telephone</label>' +
'<input ng-model="model.tel" type="text" name="tel" ng-intl-tel-input data-initial-country="af"/>' +
'</form>'
);
}));
it('should override the default country', inject(function ($compile, $rootScope) {
provider.set({'initialCountry': 'gb'});
var input = element.find('input');
$compile(element)($rootScope);
$rootScope.$digest();
expect(input.intlTelInput('getSelectedCountryData').iso2).toEqual('af');
}));
});
});