44 getBlameDecorations ,
55 getBlameDecorationsForSelections ,
66 getDecorationFromHunk ,
7- Hunk
7+ Hunk ,
88} from './blame'
99import { createMockSourcegraphAPI } from './util/stubs'
1010
@@ -13,55 +13,54 @@ const FIXTURE_HUNK_1: Hunk = {
1313 endLine : 2 ,
1414 author : {
1515 person : {
16- displayName : 'a'
16+ displayName : 'a' ,
1717 } ,
18- date : '2018-09-10T21:52:45Z'
18+ date : '2018-09-10T21:52:45Z' ,
1919 } ,
2020 rev : 'b' ,
2121 message : 'c' ,
2222 commit : {
23- url : 'd'
24- }
23+ url : 'd' ,
24+ } ,
2525}
2626
2727const FIXTURE_HUNK_2 : Hunk = {
2828 startLine : 2 ,
2929 endLine : 3 ,
3030 author : {
3131 person : {
32- displayName : 'e'
32+ displayName : 'e' ,
3333 } ,
34- date : '2018-11-10T21:52:45Z'
34+ date : '2018-11-10T21:52:45Z' ,
3535 } ,
3636 rev : 'f' ,
3737 message : 'g' ,
3838 commit : {
39- url : 'h'
40- }
39+ url : 'h' ,
40+ } ,
4141}
4242
4343const FIXTURE_HUNK_3 : Hunk = {
4444 startLine : 3 ,
4545 endLine : 4 ,
4646 author : {
4747 person : {
48- displayName : 'i'
48+ displayName : 'i' ,
4949 } ,
50- date : '2018-10-10T21:52:45Z'
50+ date : '2018-10-10T21:52:45Z' ,
5151 } ,
5252 rev : 'j' ,
5353 message : 'k' ,
5454 commit : {
55- url : 'l'
56- }
55+ url : 'l' ,
56+ } ,
5757}
5858
5959const NOW = + new Date ( '2018-12-01T21:52:45Z' )
6060
6161const SOURCEGRAPH = createMockSourcegraphAPI ( )
6262
6363describe ( 'getDecorationsFromHunk()' , ( ) => {
64-
6564 it ( 'creates a TextDocumentDecoration from a Hunk' , ( ) => {
6665 expect ( getDecorationFromHunk ( FIXTURE_HUNK_1 , NOW , 0 , SOURCEGRAPH as any ) ) . toEqual ( {
6766 after : {
@@ -75,66 +74,87 @@ describe('getDecorationsFromHunk()', () => {
7574 backgroundColor : 'rgba(193, 217, 255, 0.65)' ,
7675 color : 'rgba(0, 0, 25, 0.55)' ,
7776 } ,
78- linkURL : 'https://sourcegraph.test/d' ,
79- } ,
80- isWholeLine : true ,
81- range : {
82- end : 0 ,
83- start : 0 ,
84- }
85- }
86- )
77+ linkURL : 'https://sourcegraph.test/d' ,
78+ } ,
79+ isWholeLine : true ,
80+ range : {
81+ end : 0 ,
82+ start : 0 ,
83+ } ,
84+ } )
8785 } )
8886
8987 it ( 'truncates long commit messsages' , ( ) => {
90- const decoration = getDecorationFromHunk ( {
91- ...FIXTURE_HUNK_1 ,
92- message : 'asdgjdsag asdklgbasdghladg asdgjlhbasdgjlhabsdg asdgilbadsgiobasgd'
93- } , NOW , 0 , SOURCEGRAPH as any )
94- expect ( decoration . after && decoration . after . contentText ) . toEqual ( 'a, 3 months ago: • asdgjdsag asdklgbasdghladg asdgjlhbasdgjlhabs…' )
88+ const decoration = getDecorationFromHunk (
89+ {
90+ ...FIXTURE_HUNK_1 ,
91+ message : 'asdgjdsag asdklgbasdghladg asdgjlhbasdgjlhabsdg asdgilbadsgiobasgd' ,
92+ } ,
93+ NOW ,
94+ 0 ,
95+ SOURCEGRAPH as any
96+ )
97+ expect ( decoration . after && decoration . after . contentText ) . toEqual (
98+ 'a, 3 months ago: • asdgjdsag asdklgbasdghladg asdgjlhbasdgjlhabs…'
99+ )
95100 } )
96101
97102 it ( 'truncates long display names' , ( ) => {
98- const decoration = getDecorationFromHunk ( {
99- ...FIXTURE_HUNK_1 ,
100- author : {
101- person : {
102- displayName : 'asdgjdsag asdklgbasdghladg asdgjlhbasdgjlhabsdg asdgilbadsgiobasgd'
103+ const decoration = getDecorationFromHunk (
104+ {
105+ ...FIXTURE_HUNK_1 ,
106+ author : {
107+ person : {
108+ displayName : 'asdgjdsag asdklgbasdghladg asdgjlhbasdgjlhabsdg asdgilbadsgiobasgd' ,
109+ } ,
110+ date : '2018-09-10T21:52:45Z' ,
103111 } ,
104- date :'2018-09-10T21:52:45Z'
105- }
106- } , NOW , 0 , SOURCEGRAPH as any )
107- expect ( decoration . after && decoration . after . contentText ) . toEqual ( 'asdgjdsag asdklgbasdghlad…, 3 months ago: • c' )
112+ } ,
113+ NOW ,
114+ 0 ,
115+ SOURCEGRAPH as any
116+ )
117+ expect ( decoration . after && decoration . after . contentText ) . toEqual (
118+ 'asdgjdsag asdklgbasdghlad…, 3 months ago: • c'
119+ )
108120 } )
109121} )
110122
111123describe ( 'getBlameDecorationsForSelections()' , ( ) => {
112-
113124 it ( 'adds decorations only for hunks that are within the selections' , ( ) => {
114- const decorations = getBlameDecorationsForSelections ( [ FIXTURE_HUNK_1 , FIXTURE_HUNK_2 , FIXTURE_HUNK_3 ] , [
115- new SOURCEGRAPH . Selection ( new SOURCEGRAPH . Position ( 1 , 0 ) , new SOURCEGRAPH . Position ( 1 , 0 ) ) as any
116- ] , NOW , SOURCEGRAPH as any )
117- expect ( decorations ) . toEqual ( [
118- getDecorationFromHunk ( FIXTURE_HUNK_2 , NOW , 1 , SOURCEGRAPH as any )
119- ] )
125+ const decorations = getBlameDecorationsForSelections (
126+ [ FIXTURE_HUNK_1 , FIXTURE_HUNK_2 , FIXTURE_HUNK_3 ] ,
127+ [ new SOURCEGRAPH . Selection ( new SOURCEGRAPH . Position ( 1 , 0 ) , new SOURCEGRAPH . Position ( 1 , 0 ) ) as any ] ,
128+ NOW ,
129+ SOURCEGRAPH as any
130+ )
131+ expect ( decorations ) . toEqual ( [ getDecorationFromHunk ( FIXTURE_HUNK_2 , NOW , 1 , SOURCEGRAPH as any ) ] )
120132 } )
121133
122134 it ( 'handles multiple selections' , ( ) => {
123- const decorations = getBlameDecorationsForSelections ( [ FIXTURE_HUNK_1 , FIXTURE_HUNK_2 , FIXTURE_HUNK_3 ] , [
124- new SOURCEGRAPH . Selection ( new SOURCEGRAPH . Position ( 1 , 0 ) , new SOURCEGRAPH . Position ( 1 , 0 ) ) as any ,
125- new SOURCEGRAPH . Selection ( new SOURCEGRAPH . Position ( 2 , 0 ) , new SOURCEGRAPH . Position ( 5 , 0 ) ) as any ,
126- new SOURCEGRAPH . Selection ( new SOURCEGRAPH . Position ( 6 , 0 ) , new SOURCEGRAPH . Position ( 10 , 0 ) ) as any ,
127- ] , NOW , SOURCEGRAPH as any )
135+ const decorations = getBlameDecorationsForSelections (
136+ [ FIXTURE_HUNK_1 , FIXTURE_HUNK_2 , FIXTURE_HUNK_3 ] ,
137+ [
138+ new SOURCEGRAPH . Selection ( new SOURCEGRAPH . Position ( 1 , 0 ) , new SOURCEGRAPH . Position ( 1 , 0 ) ) as any ,
139+ new SOURCEGRAPH . Selection ( new SOURCEGRAPH . Position ( 2 , 0 ) , new SOURCEGRAPH . Position ( 5 , 0 ) ) as any ,
140+ new SOURCEGRAPH . Selection ( new SOURCEGRAPH . Position ( 6 , 0 ) , new SOURCEGRAPH . Position ( 10 , 0 ) ) as any ,
141+ ] ,
142+ NOW ,
143+ SOURCEGRAPH as any
144+ )
128145 expect ( decorations ) . toEqual ( [
129146 getDecorationFromHunk ( FIXTURE_HUNK_2 , NOW , 1 , SOURCEGRAPH as any ) ,
130147 getDecorationFromHunk ( FIXTURE_HUNK_3 , NOW , 2 , SOURCEGRAPH as any ) ,
131148 ] )
132149 } )
133150
134151 it ( 'handles multiple hunks per selection' , ( ) => {
135- const decorations = getBlameDecorationsForSelections ( [ FIXTURE_HUNK_1 , FIXTURE_HUNK_2 , FIXTURE_HUNK_3 ] , [
136- new SOURCEGRAPH . Selection ( new SOURCEGRAPH . Position ( 0 , 0 ) , new SOURCEGRAPH . Position ( 5 , 0 ) ) as any
137- ] , NOW , SOURCEGRAPH as any )
152+ const decorations = getBlameDecorationsForSelections (
153+ [ FIXTURE_HUNK_1 , FIXTURE_HUNK_2 , FIXTURE_HUNK_3 ] ,
154+ [ new SOURCEGRAPH . Selection ( new SOURCEGRAPH . Position ( 0 , 0 ) , new SOURCEGRAPH . Position ( 5 , 0 ) ) as any ] ,
155+ NOW ,
156+ SOURCEGRAPH as any
157+ )
138158 expect ( decorations ) . toEqual ( [
139159 getDecorationFromHunk ( FIXTURE_HUNK_1 , NOW , 0 , SOURCEGRAPH as any ) ,
140160 getDecorationFromHunk ( FIXTURE_HUNK_2 , NOW , 1 , SOURCEGRAPH as any ) ,
@@ -143,87 +163,83 @@ describe('getBlameDecorationsForSelections()', () => {
143163 } )
144164
145165 it ( 'decorates the start line of the selection if the start line of the hunk is outside of the selection boundaries' , ( ) => {
146- const decorations = getBlameDecorationsForSelections ( [ {
147- ...FIXTURE_HUNK_1 ,
148- startLine : 1 ,
149- endLine : 10
150- } ] , [
151- new SOURCEGRAPH . Selection ( new SOURCEGRAPH . Position ( 2 , 0 ) , new SOURCEGRAPH . Position ( 2 , 0 ) ) as any
152- ] , NOW , SOURCEGRAPH as any )
153- expect ( decorations ) . toEqual ( [
154- getDecorationFromHunk ( FIXTURE_HUNK_1 , NOW , 2 , SOURCEGRAPH as any ) ,
155- ] )
166+ const decorations = getBlameDecorationsForSelections (
167+ [
168+ {
169+ ...FIXTURE_HUNK_1 ,
170+ startLine : 1 ,
171+ endLine : 10 ,
172+ } ,
173+ ] ,
174+ [ new SOURCEGRAPH . Selection ( new SOURCEGRAPH . Position ( 2 , 0 ) , new SOURCEGRAPH . Position ( 2 , 0 ) ) as any ] ,
175+ NOW ,
176+ SOURCEGRAPH as any
177+ )
178+ expect ( decorations ) . toEqual ( [ getDecorationFromHunk ( FIXTURE_HUNK_1 , NOW , 2 , SOURCEGRAPH as any ) ] )
156179 } )
157-
158180} )
159181
160182describe ( 'getAllBlameDecorations()' , ( ) => {
161-
162183 it ( 'adds decorations for all hunks' , ( ) => {
163- expect ( getAllBlameDecorations ( [
164- FIXTURE_HUNK_1 ,
165- FIXTURE_HUNK_2 ,
166- FIXTURE_HUNK_3
167- ] , NOW , SOURCEGRAPH as any ) ) . toEqual ( [
184+ expect (
185+ getAllBlameDecorations ( [ FIXTURE_HUNK_1 , FIXTURE_HUNK_2 , FIXTURE_HUNK_3 ] , NOW , SOURCEGRAPH as any )
186+ ) . toEqual ( [
168187 getDecorationFromHunk ( FIXTURE_HUNK_1 , NOW , 0 , SOURCEGRAPH as any ) ,
169188 getDecorationFromHunk ( FIXTURE_HUNK_2 , NOW , 1 , SOURCEGRAPH as any ) ,
170189 getDecorationFromHunk ( FIXTURE_HUNK_3 , NOW , 2 , SOURCEGRAPH as any ) ,
171-
172190 ] )
173191 } )
174-
175192} )
176193
177194describe ( 'getBlameDecorations()' , ( ) => {
178-
179195 it ( 'gets no decorations if git.blame.lineDecorations is false' , async ( ) => {
180- expect ( await getBlameDecorations ( {
181- uri : 'a' ,
182- settings : {
183- 'git.blame.lineDecorations' : false
184- } ,
185- now : NOW ,
186- selections : null ,
187- queryHunks : ( ) => Promise . resolve ( [ FIXTURE_HUNK_1 , FIXTURE_HUNK_2 , FIXTURE_HUNK_3 ] ) ,
188- sourcegraph : SOURCEGRAPH as any
189- } ) ) . toEqual ( [ ] )
196+ expect (
197+ await getBlameDecorations ( {
198+ uri : 'a' ,
199+ settings : {
200+ 'git.blame.lineDecorations' : false ,
201+ } ,
202+ now : NOW ,
203+ selections : null ,
204+ queryHunks : ( ) => Promise . resolve ( [ FIXTURE_HUNK_1 , FIXTURE_HUNK_2 , FIXTURE_HUNK_3 ] ) ,
205+ sourcegraph : SOURCEGRAPH as any ,
206+ } )
207+ ) . toEqual ( [ ] )
190208 } )
191209
192210 it ( 'gets decorations for all hunks if no selections are passed' , async ( ) => {
193- expect ( await getBlameDecorations ( {
194- uri : 'a' ,
195- settings : {
196- 'git.blame.lineDecorations' : true
197- } ,
198- now : NOW ,
199- selections : null ,
200- queryHunks : ( ) => Promise . resolve ( [ FIXTURE_HUNK_1 , FIXTURE_HUNK_2 , FIXTURE_HUNK_3 ] ) ,
201- sourcegraph : SOURCEGRAPH as any
202- } ) ) . toEqual ( [
211+ expect (
212+ await getBlameDecorations ( {
213+ uri : 'a' ,
214+ settings : {
215+ 'git.blame.lineDecorations' : true ,
216+ } ,
217+ now : NOW ,
218+ selections : null ,
219+ queryHunks : ( ) => Promise . resolve ( [ FIXTURE_HUNK_1 , FIXTURE_HUNK_2 , FIXTURE_HUNK_3 ] ) ,
220+ sourcegraph : SOURCEGRAPH as any ,
221+ } )
222+ ) . toEqual ( [
203223 getDecorationFromHunk ( FIXTURE_HUNK_1 , NOW , 0 , SOURCEGRAPH as any ) ,
204224 getDecorationFromHunk ( FIXTURE_HUNK_2 , NOW , 1 , SOURCEGRAPH as any ) ,
205225 getDecorationFromHunk ( FIXTURE_HUNK_3 , NOW , 2 , SOURCEGRAPH as any ) ,
206226 ] )
207227 } )
208228
209229 it ( 'gets decorations for the selections if selections are passed' , async ( ) => {
210- expect ( await getBlameDecorations ( {
211- uri : 'a' ,
212- settings : {
213- 'git.blame.lineDecorations' : true
214- } ,
215- now : NOW ,
216- selections : [
217- new SOURCEGRAPH . Selection (
218- new SOURCEGRAPH . Position ( 2 , 0 ) ,
219- new SOURCEGRAPH . Position ( 2 , 0 )
220- ) as any
221- ] ,
222- queryHunks : ( ) => Promise . resolve ( [ FIXTURE_HUNK_1 , FIXTURE_HUNK_2 , FIXTURE_HUNK_3 ] ) ,
223- sourcegraph : SOURCEGRAPH as any
224- } ) ) . toEqual ( [
225- getDecorationFromHunk ( FIXTURE_HUNK_3 , NOW , 2 , SOURCEGRAPH as any ) ,
226- ] )
230+ expect (
231+ await getBlameDecorations ( {
232+ uri : 'a' ,
233+ settings : {
234+ 'git.blame.lineDecorations' : true ,
235+ } ,
236+ now : NOW ,
237+ selections : [
238+ new SOURCEGRAPH . Selection ( new SOURCEGRAPH . Position ( 2 , 0 ) , new SOURCEGRAPH . Position ( 2 , 0 ) ) as any ,
239+ ] ,
240+ queryHunks : ( ) => Promise . resolve ( [ FIXTURE_HUNK_1 , FIXTURE_HUNK_2 , FIXTURE_HUNK_3 ] ) ,
241+ sourcegraph : SOURCEGRAPH as any ,
242+ } )
243+ ) . toEqual ( [ getDecorationFromHunk ( FIXTURE_HUNK_3 , NOW , 2 , SOURCEGRAPH as any ) ] )
227244 } )
228-
229245} )
0 commit comments