-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from Jurfest/feature/utils
feature/utils
- Loading branch information
Showing
22 changed files
with
348 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
55 changes: 55 additions & 0 deletions
55
libs/shared/util-common/src/lib/directives/app-shell-no-render.directive.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { PLATFORM_ID, TemplateRef, ViewContainerRef } from '@angular/core'; | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { AppShellNoRenderDirective } from './app-shell-no-render.directive'; | ||
|
||
describe('AppShellNoRenderDirective', () => { | ||
let templateRef: TemplateRef<any>; | ||
let viewContainerRef: ViewContainerRef; | ||
let platformId: string; | ||
|
||
beforeEach(() => { | ||
templateRef = { | ||
createEmbeddedView: jest.fn(), | ||
} as unknown as TemplateRef<any>; | ||
|
||
viewContainerRef = { | ||
createEmbeddedView: jest.fn(), | ||
clear: jest.fn(), | ||
} as unknown as ViewContainerRef; | ||
|
||
platformId = 'server'; | ||
|
||
TestBed.configureTestingModule({ | ||
providers: [ | ||
{ provide: TemplateRef, useValue: templateRef }, | ||
{ provide: ViewContainerRef, useValue: viewContainerRef }, | ||
{ provide: PLATFORM_ID, useFactory: () => platformId }, | ||
AppShellNoRenderDirective, | ||
], | ||
}); | ||
}); | ||
|
||
it('should create an instance', () => { | ||
const directive = TestBed.inject(AppShellNoRenderDirective); | ||
expect(directive).toBeTruthy(); | ||
}); | ||
|
||
describe('ngOnInit', () => { | ||
it('should clear view container if platform is server', () => { | ||
platformId = 'server'; | ||
const directive = TestBed.inject(AppShellNoRenderDirective); | ||
directive.ngOnInit(); | ||
expect(viewContainerRef.clear).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should create embedded view if platform is not server', () => { | ||
platformId = 'browser'; | ||
const directive = TestBed.inject(AppShellNoRenderDirective); | ||
directive.ngOnInit(); | ||
expect(viewContainerRef.createEmbeddedView).toHaveBeenCalledWith( | ||
templateRef, | ||
); | ||
}); | ||
}); | ||
}); |
28 changes: 28 additions & 0 deletions
28
libs/shared/util-common/src/lib/directives/app-shell-no-render.directive.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { isPlatformServer } from '@angular/common'; | ||
import { | ||
Directive, | ||
inject, | ||
OnInit, | ||
PLATFORM_ID, | ||
TemplateRef, | ||
ViewContainerRef, | ||
} from '@angular/core'; | ||
|
||
/* Template directive to hide content when is on Server Platform */ | ||
@Directive({ | ||
selector: '[commonAppShellNoRender]', | ||
standalone: true, | ||
}) | ||
export class AppShellNoRenderDirective implements OnInit { | ||
private templateRef = inject(TemplateRef<any>); | ||
private viewContainer = inject(ViewContainerRef); | ||
private platformId = inject(PLATFORM_ID); | ||
|
||
ngOnInit(): void { | ||
if (isPlatformServer(this.platformId)) { | ||
this.viewContainer.clear(); | ||
} else { | ||
this.viewContainer.createEmbeddedView(this.templateRef); | ||
} | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
libs/shared/util-common/src/lib/directives/app-shell-render.directive.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { PLATFORM_ID, TemplateRef, ViewContainerRef } from '@angular/core'; | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { AppShellRenderDirective } from './app-shell-render.directive'; | ||
|
||
describe('AppShellRenderDirective', () => { | ||
let templateRef: TemplateRef<any>; | ||
let viewContainerRef: ViewContainerRef; | ||
let platformId: string; | ||
|
||
beforeEach(() => { | ||
templateRef = { | ||
createEmbeddedView: jest.fn(), | ||
} as unknown as TemplateRef<any>; | ||
|
||
viewContainerRef = { | ||
createEmbeddedView: jest.fn(), | ||
clear: jest.fn(), | ||
} as unknown as ViewContainerRef; | ||
|
||
platformId = 'server'; // Default to server for initial setup | ||
|
||
TestBed.configureTestingModule({ | ||
providers: [ | ||
{ provide: TemplateRef, useValue: templateRef }, | ||
{ provide: ViewContainerRef, useValue: viewContainerRef }, | ||
{ provide: PLATFORM_ID, useFactory: () => platformId }, | ||
AppShellRenderDirective, // Provide the directive | ||
], | ||
}); | ||
}); | ||
|
||
it('should create an instance', () => { | ||
const directive = TestBed.inject(AppShellRenderDirective); | ||
expect(directive).toBeTruthy(); | ||
}); | ||
|
||
describe('ngOnInit', () => { | ||
it('should create embedded view if platform is server', () => { | ||
platformId = 'server'; | ||
const directive = TestBed.inject(AppShellRenderDirective); | ||
directive.ngOnInit(); | ||
expect(viewContainerRef.createEmbeddedView).toHaveBeenCalledWith( | ||
templateRef, | ||
); | ||
}); | ||
|
||
it('should clear view container if platform is not server', () => { | ||
platformId = 'browser'; | ||
const directive = TestBed.inject(AppShellRenderDirective); | ||
directive.ngOnInit(); | ||
expect(viewContainerRef.clear).toHaveBeenCalled(); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.