@@ -4,7 +4,7 @@ import { MockProvider } from 'ng-mocks';
44
55import { BehaviorSubject } from 'rxjs' ;
66
7- import { signal , WritableSignal } from '@angular/core' ;
7+ import { PLATFORM_ID , signal , WritableSignal } from '@angular/core' ;
88import { ComponentFixture , TestBed } from '@angular/core/testing' ;
99
1010import { BannerModel } from '@core/components/osf-banners/models/banner.model' ;
@@ -24,43 +24,51 @@ describe('Component: Scheduled Banner', () => {
2424 const currentBannerSignal : WritableSignal < BannerModel | null > = signal < BannerModel | null > ( null ) ;
2525 let isMobile$ : BehaviorSubject < boolean > ;
2626
27- beforeEach ( ( ) => {
27+ function setup ( overrides : { isBrowser ?: boolean } = { } ) {
2828 isMobile$ = new BehaviorSubject < boolean > ( false ) ;
29+ currentBannerSignal . set ( null ) ;
2930
3031 TestBed . configureTestingModule ( {
3132 imports : [ ScheduledBannerComponent ] ,
3233 providers : [
3334 provideOSFCore ( ) ,
3435 MockProvider ( IS_XSMALL , isMobile$ ) ,
36+ MockProvider ( PLATFORM_ID , overrides . isBrowser === false ? 'server' : 'browser' ) ,
3537 provideMockStore ( {
3638 signals : [ { selector : BannersSelector . getCurrentBanner , value : currentBannerSignal } ] ,
3739 } ) ,
3840 ] ,
3941 } ) ;
4042
43+ store = TestBed . inject ( Store ) ;
4144 fixture = TestBed . createComponent ( ScheduledBannerComponent ) ;
4245 component = fixture . componentInstance ;
4346 fixture . detectChanges ( ) ;
44-
45- store = TestBed . inject ( Store ) ;
46- } ) ;
47+ }
4748
4849 it ( 'should create the component' , ( ) => {
50+ setup ( ) ;
4951 expect ( component ) . toBeInstanceOf ( ScheduledBannerComponent ) ;
5052 } ) ;
5153
52- it ( 'should dispatch FetchCurrentScheduledBanner on init' , ( ) => {
53- const dispatchSpy = vi . spyOn ( store , 'dispatch' ) ;
54- component . ngOnInit ( ) ;
55- expect ( dispatchSpy ) . toHaveBeenCalledWith ( new GetCurrentScheduledBanner ( ) ) ;
54+ it ( 'should dispatch GetCurrentScheduledBanner on init in browser' , ( ) => {
55+ setup ( ) ;
56+ expect ( store . dispatch ) . toHaveBeenCalledWith ( new GetCurrentScheduledBanner ( ) ) ;
57+ } ) ;
58+
59+ it ( 'should not dispatch GetCurrentScheduledBanner on server' , ( ) => {
60+ setup ( { isBrowser : false } ) ;
61+ expect ( store . dispatch ) . not . toHaveBeenCalled ( ) ;
5662 } ) ;
5763
5864 it ( 'should return false if no banner is set' , ( ) => {
65+ setup ( ) ;
5966 currentBannerSignal . set ( null ) ;
6067 expect ( component . shouldShowBanner ( ) ) . toBe ( false ) ;
6168 } ) ;
6269
6370 it ( 'should return true if current time is within banner window' , ( ) => {
71+ setup ( ) ;
6472 const showBanner = component . shouldShowBanner ;
6573 expect ( showBanner ( ) ) . toBeFalsy ( ) ;
6674
@@ -87,6 +95,7 @@ describe('Component: Scheduled Banner', () => {
8795 } ) ;
8896
8997 it ( 'should return false if current time is outside the banner window' , ( ) => {
98+ setup ( ) ;
9099 const now = new Date ( ) ;
91100 currentBannerSignal . set (
92101 Object ( {
@@ -104,6 +113,7 @@ describe('Component: Scheduled Banner', () => {
104113 } ) ;
105114
106115 it ( 'should reflect the isMobile signal' , ( ) => {
116+ setup ( ) ;
107117 const now = new Date ( ) ;
108118 currentBannerSignal . set (
109119 Object ( {
0 commit comments