5
5
import * as assert from 'assert'
6
6
import { createMockTextEditor , resetCodeWhispererGlobalVariables } from '../testUtil'
7
7
import { ReferenceLogViewProvider } from '../../../codewhisperer/service/referenceLogViewProvider'
8
+ import { LicenseUtil } from '../../../codewhisperer/util/licenseUtil'
8
9
9
10
describe ( 'referenceLogViewProvider' , function ( ) {
10
11
beforeEach ( function ( ) {
11
12
resetCodeWhispererGlobalVariables ( )
12
13
} )
13
14
describe ( 'getReferenceLog' , async function ( ) {
14
- it ( 'Should return expected reference log string' , function ( ) {
15
+ it ( 'Should return expected reference log string with link to license if there is no url ' , function ( ) {
15
16
const currentTime = new Date ( )
16
17
const currentTimeString = currentTime . toLocaleString ( )
17
18
currentTime . setSeconds ( currentTime . getSeconds ( ) + 1 )
@@ -34,6 +35,36 @@ describe('referenceLogViewProvider', function () {
34
35
assert . ok ( actualTime === currentTimeString || actualTime === nextTimeString )
35
36
assert . ok ( actual . includes ( 'MIT' ) )
36
37
assert . ok ( actual . includes ( 'def two_su' ) )
38
+ assert . ok ( actual . includes ( LicenseUtil . getLicenseHtml ( 'MIT' ) ) )
39
+ } )
40
+
41
+ it ( 'Should return expected reference log string with link to the repo url if present' , function ( ) {
42
+ const currentTime = new Date ( )
43
+ const currentTimeString = currentTime . toLocaleString ( )
44
+ currentTime . setSeconds ( currentTime . getSeconds ( ) + 1 )
45
+ const nextTimeString = currentTime . toLocaleString ( )
46
+ const mockEditor = createMockTextEditor ( )
47
+ const recommendation = `def two_sum(nums, target):`
48
+ const mockUrl = 'https://www.amazon.com'
49
+ const fakeReferences = [
50
+ {
51
+ message : '' ,
52
+ licenseName : 'MIT' ,
53
+ repository : 'TEST_REPO' ,
54
+ url : mockUrl ,
55
+ recommendationContentSpan : {
56
+ start : 0 ,
57
+ end : 10 ,
58
+ } ,
59
+ } ,
60
+ ]
61
+ const actual = ReferenceLogViewProvider . getReferenceLog ( recommendation , fakeReferences , mockEditor )
62
+ const actualTime = actual . substring ( 1 , actual . indexOf ( ']' ) )
63
+ assert . ok ( actualTime === currentTimeString || actualTime === nextTimeString )
64
+ assert . ok ( actual . includes ( 'MIT' ) )
65
+ assert . ok ( actual . includes ( 'def two_su' ) )
66
+ assert . ok ( actual . includes ( mockUrl ) )
67
+ assert . ok ( ! actual . includes ( LicenseUtil . getLicenseHtml ( 'MIT' ) ) )
37
68
} )
38
69
} )
39
70
} )
0 commit comments