1
- import { async , ComponentFixture , TestBed } from '@angular/core/testing' ;
2
- import { RouterTestingModule } from '@angular/router/testing' ;
3
- import { BsDropdownModule , BsModalRef , BsModalService , ModalModule , PopoverModule , TooltipModule } from 'ngx-bootstrap' ;
4
- import { AppsService } from '../apps.service' ;
5
- import { ToastyService } from 'ng2-toasty' ;
6
- import { MockToastyService } from '../../tests/mocks/toasty' ;
7
- import { MockAppsService } from '../../tests/mocks/apps' ;
8
- import { ReactiveFormsModule , FormsModule } from '@angular/forms' ;
9
- import { AppDetailsComponent } from './app-details.component' ;
10
- import { SharedAboutService } from '../../shared/services/shared-about.service' ;
11
- import { AppTypeComponent } from '../components/app-type/app-type.component' ;
12
- import { RolesDirective } from '../../auth/directives/roles.directive' ;
13
- import { MockActivatedRoute } from '../../tests/mocks/activated-route' ;
14
- import { MocksSharedAboutService } from '../../tests/mocks/shared-about' ;
15
- import { ActivatedRoute } from '@angular/router' ;
16
- import { MockAuthService } from '../../tests/mocks/auth' ;
17
- import { AuthService } from '../../auth/auth.service' ;
18
- import { By } from '@angular/platform-browser' ;
19
- import { DebugElement } from '@angular/core' ;
20
- import { APPS } from '../../tests/mocks/mock-data' ;
21
- import { MockConfirmService } from '../../tests/mocks/confirm' ;
22
- import { ConfirmService } from '../../shared/components/confirm/confirm.service' ;
23
- import { AppVersionLabelComponent } from '../components/app-versions-label/app-versions-label.component' ;
24
- import { SortComponent } from '../../shared/components/sort/sort.component' ;
25
- import { OrderByPipe } from '../../shared/pipes/orderby.pipe' ;
26
- import { MockModalService } from '../../tests/mocks/modal' ;
27
- import { AppVersionsComponent } from '../app-versions/app-versions.component' ;
28
- import { BusyService } from '../../shared/services/busy.service' ;
1
+ import { async , ComponentFixture , TestBed } from '@angular/core/testing' ;
2
+ import { RouterTestingModule } from '@angular/router/testing' ;
3
+ import { BsDropdownModule , BsModalRef , BsModalService , ModalModule , PopoverModule , TooltipModule } from 'ngx-bootstrap' ;
4
+ import { AppsService } from '../apps.service' ;
5
+ import { ToastyService } from 'ng2-toasty' ;
6
+ import { MockToastyService } from '../../tests/mocks/toasty' ;
7
+ import { MockAppsService } from '../../tests/mocks/apps' ;
8
+ import { ReactiveFormsModule , FormsModule } from '@angular/forms' ;
9
+ import { AppDetailsComponent } from './app-details.component' ;
10
+ import { SharedAboutService } from '../../shared/services/shared-about.service' ;
11
+ import { AppTypeComponent } from '../components/app-type/app-type.component' ;
12
+ import { RolesDirective } from '../../auth/directives/roles.directive' ;
13
+ import { MockActivatedRoute } from '../../tests/mocks/activated-route' ;
14
+ import { MocksSharedAboutService } from '../../tests/mocks/shared-about' ;
15
+ import { ActivatedRoute } from '@angular/router' ;
16
+ import { MockAuthService } from '../../tests/mocks/auth' ;
17
+ import { AuthService } from '../../auth/auth.service' ;
18
+ import { By } from '@angular/platform-browser' ;
19
+ import { DebugElement } from '@angular/core' ;
20
+ import { APPS } from '../../tests/mocks/mock-data' ;
21
+ import { MockConfirmService } from '../../tests/mocks/confirm' ;
22
+ import { ConfirmService } from '../../shared/components/confirm/confirm.service' ;
23
+ import { AppVersionLabelComponent } from '../components/app-versions-label/app-versions-label.component' ;
24
+ import { SortComponent } from '../../shared/components/sort/sort.component' ;
25
+ import { OrderByPipe } from '../../shared/pipes/orderby.pipe' ;
26
+ import { MockModalService } from '../../tests/mocks/modal' ;
27
+ import { AppVersionsComponent } from '../app-versions/app-versions.component' ;
28
+ import { BusyService } from '../../shared/services/busy.service' ;
29
+ import { RoutingStateService } from '../../shared/services/routing-state.service' ;
30
+ import { MockRoutingStateService } from '../../tests/mocks/routing-state' ;
29
31
30
32
/**
31
33
* Test {@link AppDetailsComponent}.
@@ -41,9 +43,10 @@ describe('AppDetailsComponent', () => {
41
43
const sharedAboutService = new MocksSharedAboutService ( ) ;
42
44
const modalService = new MockModalService ( ) ;
43
45
const confirmService = new MockConfirmService ( ) ;
46
+ const routingStateService = new MockRoutingStateService ( ) ;
44
47
let activeRoute : MockActivatedRoute ;
45
48
46
- const commonTestParams = { appName : 'foo' , appType : 'source' } ;
49
+ const commonTestParams = { appName : 'foo' , appType : 'source' } ;
47
50
48
51
const sourceMock = JSON . parse ( JSON . stringify ( APPS ) ) ;
49
52
const appMock = sourceMock . items [ 0 ] ;
@@ -69,14 +72,15 @@ describe('AppDetailsComponent', () => {
69
72
RouterTestingModule . withRoutes ( [ ] )
70
73
] ,
71
74
providers : [
72
- { provide : AppsService , useValue : appsService } ,
73
- { provide : AuthService , useValue : authService } ,
74
- { provide : ActivatedRoute , useValue : activeRoute } ,
75
- { provide : BsModalService , useValue : modalService } ,
76
- { provide : ConfirmService , useValue : confirmService } ,
77
- { provide : BusyService , useValue : new BusyService ( ) } ,
78
- { provide : SharedAboutService , useValue : sharedAboutService } ,
79
- { provide : ToastyService , useValue : toastyService }
75
+ { provide : AppsService , useValue : appsService } ,
76
+ { provide : AuthService , useValue : authService } ,
77
+ { provide : ActivatedRoute , useValue : activeRoute } ,
78
+ { provide : BsModalService , useValue : modalService } ,
79
+ { provide : ConfirmService , useValue : confirmService } ,
80
+ { provide : BusyService , useValue : new BusyService ( ) } ,
81
+ { provide : RoutingStateService , useValue : routingStateService } ,
82
+ { provide : SharedAboutService , useValue : sharedAboutService } ,
83
+ { provide : ToastyService , useValue : toastyService }
80
84
]
81
85
} )
82
86
. compileComponents ( ) ;
@@ -99,11 +103,11 @@ describe('AppDetailsComponent', () => {
99
103
100
104
it ( 'Should cancel (footer close)' , ( ) => {
101
105
fixture . detectChanges ( ) ;
102
- const navigate = spyOn ( ( < any > component ) . router , 'navigate ' ) ;
106
+ const navigate = spyOn ( routingStateService , 'back ' ) ;
103
107
const bt : HTMLElement = fixture . debugElement . query ( By . css ( '.footer-actions .btn-default' ) ) . nativeElement ;
104
108
bt . click ( ) ;
105
109
fixture . detectChanges ( ) ;
106
- expect ( navigate ) . toHaveBeenCalledWith ( [ 'apps' ] ) ;
110
+ expect ( navigate ) . toHaveBeenCalled ( ) ;
107
111
} ) ;
108
112
109
113
} ) ;
@@ -140,9 +144,9 @@ describe('AppDetailsComponent', () => {
140
144
it ( 'should apply a sort on name and uri' , ( ) => {
141
145
const sortProperty : HTMLElement = fixture . debugElement . query ( By . css ( '#sort-name a' ) ) . nativeElement ;
142
146
[
143
- { click : sortProperty , nameAsc : true , sort : 'name' , order : 'ASC' } ,
144
- { click : sortProperty , nameDesc : true , sort : 'name' , order : 'DESC' } ,
145
- { click : sortProperty , sort : '' , order : '' } ,
147
+ { click : sortProperty , nameAsc : true , sort : 'name' , order : 'ASC' } ,
148
+ { click : sortProperty , nameDesc : true , sort : 'name' , order : 'DESC' } ,
149
+ { click : sortProperty , sort : '' , order : '' } ,
146
150
] . forEach ( ( test ) => {
147
151
test . click . click ( ) ;
148
152
fixture . detectChanges ( ) ;
@@ -270,7 +274,7 @@ describe('AppDetailsComponent', () => {
270
274
const spy = spyOn ( modalService , 'show' ) ;
271
275
fixture . debugElement . query ( By . css ( '#no-default-version a' ) ) . nativeElement . click ( ) ;
272
276
fixture . detectChanges ( ) ;
273
- expect ( spy ) . toHaveBeenCalledWith ( AppVersionsComponent , { class : 'modal-xl' } ) ;
277
+ expect ( spy ) . toHaveBeenCalledWith ( AppVersionsComponent , { class : 'modal-xl' } ) ;
274
278
} ) ;
275
279
276
280
// Note: have to be review (related to the workaround #1871)
0 commit comments