@@ -10,6 +10,7 @@ import { CrisItemPageTabResolver } from './cris-item-page-tab.resolver';
1010import { TabDataService } from '../core/layout/tab-data.service' ;
1111import { createPaginatedList } from '../shared/testing/utils.test' ;
1212import { tabDetailsTest , tabPublicationsTest } from '../shared/testing/layout-tab.mocks' ;
13+ import { PLATFORM_ID } from '@angular/core' ;
1314
1415describe ( 'CrisItemPageTabResolver' , ( ) => {
1516 beforeEach ( ( ) => {
@@ -32,6 +33,7 @@ describe('CrisItemPageTabResolver', () => {
3233 let hardRedirectService : HardRedirectService ;
3334
3435 let router ;
36+ let platformId ;
3537
3638 const uuid = '1234-65487-12354-1235' ;
3739 const item = Object . assign ( new Item ( ) , {
@@ -54,6 +56,7 @@ describe('CrisItemPageTabResolver', () => {
5456
5557 beforeEach ( ( ) => {
5658 router = TestBed . inject ( Router ) ;
59+ platformId = TestBed . inject ( PLATFORM_ID ) ;
5760
5861 itemService . findById . and . returnValue ( createSuccessfulRemoteDataObject$ ( item ) ) ;
5962
@@ -63,65 +66,131 @@ describe('CrisItemPageTabResolver', () => {
6366 } ) ;
6467
6568 describe ( 'and there tabs' , ( ) => {
66- beforeEach ( ( ) => {
67-
68- ( tabService as any ) . findByItem . and . returnValue ( tabsRD$ ) ;
69-
70- spyOn ( router , 'navigateByUrl' ) ;
7169
72- resolver = new CrisItemPageTabResolver ( hardRedirectService , tabService , itemService , router ) ;
70+ describe ( 'when platform is browser' , ( ) => {
71+ beforeEach ( ( ) => {
72+
73+ ( tabService as any ) . findByItem . and . returnValue ( tabsRD$ ) ;
74+
75+ spyOn ( router , 'navigateByUrl' ) ;
76+
77+ resolver = new CrisItemPageTabResolver ( platformId , hardRedirectService , tabService , itemService , router ) ;
78+ } ) ;
79+
80+ it ( 'should redirect to root route if given tab is the first one' , ( done ) => {
81+ resolver . resolve ( { params : { id : uuid } } as any , { url : '/entities/publication/1234-65487-12354-1235/publications' } as any )
82+ . pipe ( take ( 1 ) )
83+ . subscribe (
84+ ( resolved ) => {
85+ expect ( router . navigateByUrl ) . toHaveBeenCalledWith ( '/entities/publication/1234-65487-12354-1235' ) ;
86+ expect ( hardRedirectService . redirect ) . not . toHaveBeenCalled ( ) ;
87+ expect ( resolved ) . toEqual ( tabsRD ) ;
88+ done ( ) ;
89+ }
90+ ) ;
91+ } ) ;
92+
93+ it ( 'should not redirect to root route if tab different than the main one is given' , ( done ) => {
94+ resolver . resolve ( { params : { id : uuid } } as any , { url : '/entities/publication/1234-65487-12354-1235/details' } as any )
95+ . pipe ( take ( 1 ) )
96+ . subscribe (
97+ ( resolved ) => {
98+ expect ( router . navigateByUrl ) . not . toHaveBeenCalled ( ) ;
99+ expect ( hardRedirectService . redirect ) . not . toHaveBeenCalled ( ) ;
100+ expect ( resolved ) . toEqual ( tabsRD ) ;
101+ done ( ) ;
102+ }
103+ ) ;
104+ } ) ;
105+
106+ it ( 'should not redirect to root route if no tab is given' , ( done ) => {
107+ resolver . resolve ( { params : { id : uuid } } as any , { url : '/entities/publication/1234-65487-12354-1235' } as any )
108+ . pipe ( take ( 1 ) )
109+ . subscribe (
110+ ( resolved ) => {
111+ expect ( router . navigateByUrl ) . not . toHaveBeenCalled ( ) ;
112+ expect ( hardRedirectService . redirect ) . not . toHaveBeenCalled ( ) ;
113+ expect ( resolved ) . toEqual ( tabsRD ) ;
114+ done ( ) ;
115+ }
116+ ) ;
117+ } ) ;
118+
119+ it ( 'should navigate to 404 if a wrong tab is given' , ( done ) => {
120+ resolver . resolve ( { params : { id : uuid } } as any , { url : '/entities/publication/1234-65487-12354-1235/test' } as any )
121+ . pipe ( take ( 1 ) )
122+ . subscribe (
123+ ( resolved ) => {
124+ expect ( router . navigateByUrl ) . toHaveBeenCalled ( ) ;
125+ expect ( hardRedirectService . redirect ) . not . toHaveBeenCalled ( ) ;
126+ expect ( resolved ) . toEqual ( tabsRD ) ;
127+ done ( ) ;
128+ }
129+ ) ;
130+ } ) ;
73131 } ) ;
74132
75- it ( 'should redirect to root route if given tab is the first one' , ( done ) => {
76- resolver . resolve ( { params : { id : uuid } } as any , { url : '/entities/publication/1234-65487-12354-1235/publications' } as any )
77- . pipe ( take ( 1 ) )
78- . subscribe (
79- ( resolved ) => {
80- expect ( router . navigateByUrl ) . not . toHaveBeenCalled ( ) ;
81- expect ( hardRedirectService . redirect ) . toHaveBeenCalledWith ( '/entities/publication/1234-65487-12354-1235' , 302 ) ;
82- expect ( resolved ) . toEqual ( tabsRD ) ;
83- done ( ) ;
84- }
85- ) ;
86- } ) ;
87-
88- it ( 'should not redirect to root route if tab different than the main one is given' , ( done ) => {
89- resolver . resolve ( { params : { id : uuid } } as any , { url : '/entities/publication/1234-65487-12354-1235/details' } as any )
90- . pipe ( take ( 1 ) )
91- . subscribe (
92- ( resolved ) => {
93- expect ( router . navigateByUrl ) . not . toHaveBeenCalled ( ) ;
94- expect ( hardRedirectService . redirect ) . not . toHaveBeenCalled ( ) ;
95- expect ( resolved ) . toEqual ( tabsRD ) ;
96- done ( ) ;
97- }
98- ) ;
99- } ) ;
100-
101- it ( 'should not redirect to root route if no tab is given' , ( done ) => {
102- resolver . resolve ( { params : { id : uuid } } as any , { url : '/entities/publication/1234-65487-12354-1235' } as any )
103- . pipe ( take ( 1 ) )
104- . subscribe (
105- ( resolved ) => {
106- expect ( router . navigateByUrl ) . not . toHaveBeenCalled ( ) ;
107- expect ( hardRedirectService . redirect ) . not . toHaveBeenCalled ( ) ;
108- expect ( resolved ) . toEqual ( tabsRD ) ;
109- done ( ) ;
110- }
111- ) ;
112- } ) ;
113-
114- it ( 'should navigate to 404 if a wrong tab is given' , ( done ) => {
115- resolver . resolve ( { params : { id : uuid } } as any , { url : '/entities/publication/1234-65487-12354-1235/test' } as any )
116- . pipe ( take ( 1 ) )
117- . subscribe (
118- ( resolved ) => {
119- expect ( router . navigateByUrl ) . toHaveBeenCalled ( ) ;
120- expect ( hardRedirectService . redirect ) . not . toHaveBeenCalled ( ) ;
121- expect ( resolved ) . toEqual ( tabsRD ) ;
122- done ( ) ;
123- }
124- ) ;
133+ describe ( 'when platform is server' , ( ) => {
134+ beforeEach ( ( ) => {
135+ platformId = 'server' ;
136+ ( tabService as any ) . findByItem . and . returnValue ( tabsRD$ ) ;
137+
138+ spyOn ( router , 'navigateByUrl' ) ;
139+
140+ resolver = new CrisItemPageTabResolver ( platformId , hardRedirectService , tabService , itemService , router ) ;
141+ } ) ;
142+
143+ it ( 'should redirect to root route if given tab is the first one' , ( done ) => {
144+ resolver . resolve ( { params : { id : uuid } } as any , { url : '/entities/publication/1234-65487-12354-1235/publications' } as any )
145+ . pipe ( take ( 1 ) )
146+ . subscribe (
147+ ( resolved ) => {
148+ expect ( router . navigateByUrl ) . not . toHaveBeenCalled ( ) ;
149+ expect ( hardRedirectService . redirect ) . toHaveBeenCalledWith ( '/entities/publication/1234-65487-12354-1235' , 302 ) ;
150+ expect ( resolved ) . toEqual ( tabsRD ) ;
151+ done ( ) ;
152+ }
153+ ) ;
154+ } ) ;
155+
156+ it ( 'should not redirect to root route if tab different than the main one is given' , ( done ) => {
157+ resolver . resolve ( { params : { id : uuid } } as any , { url : '/entities/publication/1234-65487-12354-1235/details' } as any )
158+ . pipe ( take ( 1 ) )
159+ . subscribe (
160+ ( resolved ) => {
161+ expect ( router . navigateByUrl ) . not . toHaveBeenCalled ( ) ;
162+ expect ( hardRedirectService . redirect ) . not . toHaveBeenCalled ( ) ;
163+ expect ( resolved ) . toEqual ( tabsRD ) ;
164+ done ( ) ;
165+ }
166+ ) ;
167+ } ) ;
168+
169+ it ( 'should not redirect to root route if no tab is given' , ( done ) => {
170+ resolver . resolve ( { params : { id : uuid } } as any , { url : '/entities/publication/1234-65487-12354-1235' } as any )
171+ . pipe ( take ( 1 ) )
172+ . subscribe (
173+ ( resolved ) => {
174+ expect ( router . navigateByUrl ) . not . toHaveBeenCalled ( ) ;
175+ expect ( hardRedirectService . redirect ) . not . toHaveBeenCalled ( ) ;
176+ expect ( resolved ) . toEqual ( tabsRD ) ;
177+ done ( ) ;
178+ }
179+ ) ;
180+ } ) ;
181+
182+ it ( 'should navigate to 404 if a wrong tab is given' , ( done ) => {
183+ resolver . resolve ( { params : { id : uuid } } as any , { url : '/entities/publication/1234-65487-12354-1235/test' } as any )
184+ . pipe ( take ( 1 ) )
185+ . subscribe (
186+ ( resolved ) => {
187+ expect ( router . navigateByUrl ) . toHaveBeenCalled ( ) ;
188+ expect ( hardRedirectService . redirect ) . not . toHaveBeenCalled ( ) ;
189+ expect ( resolved ) . toEqual ( tabsRD ) ;
190+ done ( ) ;
191+ }
192+ ) ;
193+ } ) ;
125194 } ) ;
126195 } ) ;
127196
@@ -132,7 +201,7 @@ describe('CrisItemPageTabResolver', () => {
132201
133202 spyOn ( router , 'navigateByUrl' ) ;
134203
135- resolver = new CrisItemPageTabResolver ( hardRedirectService , tabService , itemService , router ) ;
204+ resolver = new CrisItemPageTabResolver ( platformId , hardRedirectService , tabService , itemService , router ) ;
136205 } ) ;
137206
138207 it ( 'should not redirect nor navigate' , ( done ) => {
0 commit comments