@@ -60,6 +60,39 @@ describe("link-preview", () => {
60
60
expect ( oneboxDom [ 0 ] . textContent ) . toBe ( "https://example.com" ) ;
61
61
} ) ;
62
62
63
+ it ( "should attempt to retrieve a link preview but simply show the plain link when not available" , async ( ) => {
64
+ const markdown = "https://example.com/not-preview\n" ;
65
+
66
+ // store the promise so we can control when it resolves
67
+ let resolver : ( value : Element | PromiseLike < Element > ) => void ;
68
+ const promise = new Promise < Element > ( ( resolve ) => {
69
+ resolver = resolve ;
70
+ } ) ;
71
+
72
+ const richEditorView = richView ( markdown , {
73
+ domainTest : / ^ .+ $ / , // any url
74
+ renderer : ( ) => promise ,
75
+ } ) ;
76
+
77
+ // check that the loading indicator is shown
78
+ let loadingIndicator = richEditorView . dom . querySelectorAll (
79
+ ".js-link-preview-loading"
80
+ ) ;
81
+ expect ( loadingIndicator ) . toHaveLength ( 1 ) ;
82
+
83
+ resolver ( undefined ) ; // link preview not available
84
+ await sleepAsync ( 0 ) ; // await next tick
85
+
86
+ // check that the loading indicator is no longer showing
87
+ loadingIndicator = richEditorView . dom . querySelectorAll (
88
+ ".js-link-preview-loading"
89
+ ) ;
90
+ expect ( loadingIndicator ) . toHaveLength ( 0 ) ;
91
+
92
+ const link = richEditorView . dom . querySelector ( "a" ) ;
93
+ expect ( link . textContent ) . toBe ( "https://example.com/not-preview" ) ;
94
+ } ) ;
95
+
63
96
it ( "should not add rich previews to links with additional text on the same line" , ( ) => {
64
97
const markdown = "here is [some link](https://example.com)\n" ;
65
98
0 commit comments