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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
/*
#--
# Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#--
*/
MergeRequestControllerTest = TestCase("Merge request controller", {
tearDown: function() {
Gitorious.MergeRequestController.getInstance()._setTransport(jQuery);
},
testSingleton: function() {
var firstController = Gitorious.MergeRequestController.getInstance();
var secondController = Gitorious.MergeRequestController.getInstance();
assertSame(firstController, secondController);
},
testNoReloadUnlessChanged: function() {
var c = new Gitorious.MergeRequestController();
c._setCurrentShaRange("ffac");
c.shaSelected("ffac");
assertFalse(c.needsUpdate());
c._setCurrentVersion(2);
c.versionSelected(2);
assertFalse(c.needsUpdate());
c.shaSelected("ffcc");
assertTrue(c.needsUpdate());
},
testFetchShasInVersion: function() {
var c = Gitorious.MergeRequestController.getInstance();
var shasFetched = false;
var controllerMock = {
ajax: function(options){
NotificationCenter.notifyObservers("MergeRequestShaListingReceived",
true, "data","text");
}
}
// Mocking this one, as it depends on the DOM
c.replaceShaListing = function(html) {
this._shaListing = html;
}
c._setTransport(controllerMock);
c.versionChanged(7);
assertTrue(c.needsUpdate());
},
testSelectDifferentVersion: function() {
var c = Gitorious.MergeRequestController.getInstance();
c._setCurrentShaRange("ffac");
c._setCurrentVersion(2);
var ControllerMock = function() {
this.called = false;
this.ajax = function(args){
this.calledWith = args;
};
this.ajaxReceived = function() {
NotificationCenter.notifyObservers("MergeRequestDiffReceived",
"data", "message");
}
};
var m = new ControllerMock();
c._setTransport(m);
c.update({'version': 1, 'sha': 'ffcc-aa90888'});
var callArgs = m.calledWith;
assertEquals("ffcc-aa90888", callArgs.data.commit_shas);
m.ajaxReceived();
assertFalse(c.needsUpdate());
},
testParseShaAndReturnInstance: function() {
var spec = Gitorious.ShaSpec.parseShas("abc-bcd");
assertEquals("abc-bcd", spec.shaSpec());
}
});
ShaSpecTest = TestCase("Sha specs", {
testAddSha: function() {
var spec = new Gitorious.ShaSpec();
assertEquals(0, spec.allShas.length);
spec.addSha("foo");
assertEquals(1, spec.allShas.length);
spec.addSha("bar");
assertEquals(2, spec.allShas.length);
},
testParseShasPair: function() {
var spec = new Gitorious.ShaSpec();
spec.parseShas("foo-bar");
assertEquals(2, spec.allShas.length);
assertEquals("foo", spec.firstSha().fullSha);
assertEquals("bar", spec.lastSha().fullSha);
assertEquals("foo-bar", spec.shaSpec());
},
testParseShasSingle: function() {
var spec = new Gitorious.ShaSpec();
spec.parseShas("foo");
assertEquals(1, spec.allShas.length);
assertEquals("foo", spec.firstSha().fullSha);
assertEquals("foo", spec.shaSpec());
}
});
CommentFormTest = TestCase("CommentForm", {
testPrefixInitialCommentBody: function() {
var commentForm = new Gitorious.CommentForm("foo/bar.rb");
commentForm.setInitialCommentBody(" foo\nbar\nbaz");
assertEquals("> foo\n> bar\n> baz\n\n", commentForm.initialCommentBody);
},
testPrefixInitialCommentBodyWithWindozeLineEndings: function() {
var commentForm = new Gitorious.CommentForm("foo/bar.rb");
commentForm.setInitialCommentBody(" foo\r\nbar\r\nbaz");
assertEquals("> foo\n> bar\n> baz\n\n", commentForm.initialCommentBody);
},
testLinesAsInternalFormat: function() {
var cf = new Gitorious.CommentForm("foo/bar.rb");
cf.numbers = ["1-1", "2-2", "3-3"];
assertEquals("1-1:3-3+2", cf.linesAsInternalFormat());
},
"test should get a summary": function() {
var cf = new Gitorious.CommentForm("file.txt");
assertEquals("Commenting on file.txt", cf.getSummary());
},
"test should get the last line number tuple": function() {
var cf = new Gitorious.CommentForm("file.txt");
cf.setLineNumbers(["1-1", "2-1", "3-1"]);
assertEquals("3-1", cf.lastLineNumber());
}
});
|