-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbranchCommitSelectorDirective.unit.js
More file actions
102 lines (95 loc) · 2.33 KB
/
branchCommitSelectorDirective.unit.js
File metadata and controls
102 lines (95 loc) · 2.33 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
'use strict';
describe('branchCommitSelectorDirective'.bold.underline.blue, function () {
var element;
var $scope;
var $rootScope;
var keypather;
var fetchCommitDataStub;
var $elScope;
var $controller;
var $q;
var ctx;
function initializeCtx() {
ctx = {};
ctx.commits = [
{
name: 'This is a commit message!'
}
];
ctx.branch = {
attrs: {
name: 'default'
},
commits: {
fetch: sinon.stub().returns({
models: ctx.commits
}),
models: ctx.commits
}
};
}
function initState(scope) {
angular.mock.module('app');
angular.mock.module(function ($provide) {
$provide.factory('branchSelectorDirective', function () {
return {
priority: 100000,
terminal: true,
link: angular.noop
};
});
$provide.factory('fetchCommitData', function ($q) {
fetchCommitDataStub = {
activeCommit: sinon.stub().returns($q.when(true))
}
return fetchCommitDataStub;
});
$provide.factory('github', function ($q) {
ctx.github = {
branchOrPRCommits: sinon.stub().returns($q.when(ctx.commits))
};
return ctx.github;
});
});
angular.mock.inject(function (
$compile,
_$controller_,
_$rootScope_,
_keypather_,
_$q_
) {
$controller = _$controller_;
keypather = _keypather_;
$rootScope = _$rootScope_;
$q = _$q_;
$scope = $rootScope.$new();
angular.extend($scope, scope);
var tpl = directiveTemplate.attribute('branch-commit-selector', {
'data': 'data'
});
element = $compile(tpl)($scope);
$scope.$digest();
$elScope = element.isolateScope();
});
}
beforeEach(function () {
initializeCtx();
});
describe('basics', function () {
beforeEach(function () {
initState({
data: {
branch: ctx.branch
}
});
});
it('Check the scope', function () {
//Should fetch once the branch is set
$scope.$digest();
expect($elScope.BCSC.data.branch, 'data.branch').to.equal(ctx.branch);
sinon.assert.called(ctx.github.branchOrPRCommits);
expect($elScope.fetchingCommits, 'fetchingCommits').to.be.false;
$rootScope.$destroy();
});
});
});