@@ -4,7 +4,6 @@ import {PuzzleJs} from "../src/puzzle";
4
4
import { Core } from "../src/core" ;
5
5
import { createPageLibConfiguration } from "./mock" ;
6
6
import sinon , { SinonStub } from "sinon" ;
7
- import { AssetHelper } from "../src/assetHelper" ;
8
7
import * as faker from "faker" ;
9
8
import { IPageLibAsset , IPageLibConfiguration , IPageLibDependency } from "../src/types" ;
10
9
import { RESOURCE_LOADING_TYPE , RESOURCE_TYPE } from "../src/enums" ;
@@ -203,6 +202,7 @@ describe('Module - Core', () => {
203
202
chunked : true ,
204
203
clientAsync : true ,
205
204
clientAsyncForce : undefined ,
205
+ onDemand : undefined ,
206
206
source : undefined ,
207
207
asyncDecentralized : false
208
208
} ] ,
@@ -256,6 +256,7 @@ describe('Module - Core', () => {
256
256
chunked : true ,
257
257
clientAsync : true ,
258
258
clientAsyncForce : true ,
259
+ onDemand : undefined ,
259
260
source : undefined ,
260
261
asyncDecentralized : false
261
262
} ] ,
@@ -278,4 +279,66 @@ describe('Module - Core', () => {
278
279
expect ( fetchStub . getCall ( 0 ) . lastArg . headers ) . to . haveOwnProperty ( "originalurl" ) ;
279
280
expect ( stubAsyncRenderResponse . calledOnce ) . to . eq ( true ) ;
280
281
} ) ;
282
+
283
+ it ( 'should return a promise object that is resolved if fragment does not exist' , ( ) => {
284
+ const assets = [ ] as IPageLibAsset [ ] ;
285
+ const dependencies = [ ] as IPageLibDependency [ ] ;
286
+ const config = {
287
+ dependencies,
288
+ assets,
289
+ fragments : [ ] ,
290
+ page : 'page' ,
291
+ peers : [ ]
292
+ } as IPageLibConfiguration ;
293
+
294
+ Core . config ( JSON . stringify ( config ) ) ;
295
+ const result = Core . renderAsyncFragment ( 'test' ) ;
296
+
297
+ expect ( result ) . to . be . a ( 'promise' ) ;
298
+ } ) ;
299
+
300
+ it ( 'should return a promise object that is resolved if fragment is asyncLoaded' , ( ) => {
301
+ const assets = [
302
+ {
303
+ name : 'bundle1' ,
304
+ dependent : [ 'vendor1' ] ,
305
+ preLoaded : false ,
306
+ link : 'bundle1.js' ,
307
+ fragment : 'test' ,
308
+ loadMethod : RESOURCE_LOADING_TYPE . ON_PAGE_RENDER ,
309
+ type : RESOURCE_TYPE . JS
310
+ }
311
+ ] as IPageLibAsset [ ] ;
312
+ const dependencies = [
313
+ {
314
+ name : 'vendor1' ,
315
+ link : 'vendor1.js' ,
316
+ preLoaded : false
317
+ }
318
+ ] as IPageLibDependency [ ] ;
319
+ const config = {
320
+ dependencies,
321
+ assets,
322
+ fragments : [ {
323
+ name : 'test' ,
324
+ attributes : {
325
+ if : "false"
326
+ } ,
327
+ chunked : true ,
328
+ clientAsync : true ,
329
+ clientAsyncForce : undefined ,
330
+ onDemand : undefined ,
331
+ source : undefined ,
332
+ asyncDecentralized : false ,
333
+ asyncLoaded : true
334
+ } ] ,
335
+ page : 'page' ,
336
+ peers : [ ]
337
+ } as IPageLibConfiguration ;
338
+
339
+ Core . config ( JSON . stringify ( config ) ) ;
340
+ const result = Core . renderAsyncFragment ( 'test' ) ;
341
+
342
+ expect ( result ) . to . be . a ( 'promise' ) ;
343
+ } ) ;
281
344
} ) ;
0 commit comments