@@ -58,6 +58,56 @@ test.each([
58
58
[ paragraph ( [ link ( 'ftp://user:pass@localhost:21/etc/hosts' ) ] ) ] ,
59
59
] ,
60
60
[ 'ssh://test@test.test' , [ paragraph ( [ link ( 'ssh://test@test.test' ) ] ) ] ] ,
61
+ [ 'custom://test@test.test' , [ paragraph ( [ link ( 'custom://test@test.test' ) ] ) ] ] ,
62
+ [ 'ftp://test.com' , [ paragraph ( [ link ( 'ftp://test.com' ) ] ) ] ] ,
61
63
] ) ( 'parses %p' , ( input , output ) => {
62
64
expect ( parser ( input ) ) . toMatchObject ( output ) ;
63
65
} ) ;
66
+
67
+ describe ( 'link helper function' , ( ) => {
68
+ it ( 'should preserve the original protocol if the protocol is http or https' , ( ) => {
69
+ expect ( link ( 'https://rocket.chat/test' ) ) . toMatchObject ( {
70
+ type : 'LINK' ,
71
+ value : {
72
+ src : plain ( 'https://rocket.chat/test' ) ,
73
+ label : plain ( 'https://rocket.chat/test' ) ,
74
+ } ,
75
+ } ) ;
76
+ expect ( link ( 'http://rocket.chat/test' ) ) . toMatchObject ( {
77
+ type : 'LINK' ,
78
+ value : {
79
+ src : plain ( 'http://rocket.chat/test' ) ,
80
+ label : plain ( 'http://rocket.chat/test' ) ,
81
+ } ,
82
+ } ) ;
83
+ } ) ;
84
+
85
+ it ( 'should preserve the original protocol even if for custom protocols' , ( ) => {
86
+ expect ( link ( 'custom://rocket.chat/test' ) ) . toMatchObject ( {
87
+ type : 'LINK' ,
88
+ value : {
89
+ src : plain ( 'custom://rocket.chat/test' ) ,
90
+ label : plain ( 'custom://rocket.chat/test' ) ,
91
+ } ,
92
+ } ) ;
93
+ } ) ;
94
+
95
+ it ( 'should return // as the protocol if // is the protocol specified' , ( ) => {
96
+ expect ( link ( '//rocket.chat/test' ) ) . toMatchObject ( {
97
+ type : 'LINK' ,
98
+ value : {
99
+ src : plain ( '//rocket.chat/test' ) ,
100
+ label : plain ( '//rocket.chat/test' ) ,
101
+ } ,
102
+ } ) ;
103
+ } ) ;
104
+ it ( "should return an url concatenated '//' if the url has no protocol" , ( ) => {
105
+ expect ( link ( 'rocket.chat/test' ) ) . toMatchObject ( {
106
+ type : 'LINK' ,
107
+ value : {
108
+ src : plain ( '//rocket.chat/test' ) ,
109
+ label : plain ( 'rocket.chat/test' ) ,
110
+ } ,
111
+ } ) ;
112
+ } ) ;
113
+ } ) ;
0 commit comments